populate list with for loop viewmodel - c#-4.0

Just wondering if anyone can help with this problem. I have a viewmodel which populates a dropdownlist. I was just wondering if it's possible to change my code below so that I can use a for loop to populate the list.
ViewModel
public IEnumerable<SelectListItem> numberOfAdults { get; set; }
Controller
numberOfAdults = new[]
{
new SelectListItem {Value = "1", Text = "1"},
new SelectListItem {Value = "2", Text = "2"},
new SelectListItem {Value = "3", Text = "3"},
new SelectListItem {Value = "4", Text = "4"},
new SelectListItem {Value = "5", Text = "5"},
new SelectListItem {Value = "6", Text = "6"},
new SelectListItem {Value = "7", Text = "7"},
new SelectListItem {Value = "8", Text = "8"},
new SelectListItem {Value = "9", Text = "9"},
new SelectListItem {Value = "10", Text = "10"}
}
View
#Html.DropDownListFor(x => x.selectedAdultValue, new SelectList(Model.numberOfAdults, "Value", "Text"), null, new {#id="NumerOfAdults" })
Something like the following is what I would like, but not sure where to put it in model or controller.
for(int i = 0; i < 10; i++)
{
i;
}

It could be as simple as:
numberOfAdults = Enumerable.Range(1, 10).Select(x => new SelectListItem
{
Value = x.ToString(),
Text = x.ToString()
});
or if you really want to use a for loop (I don't see why would you want that but anyway):
var result = new List<SelectListItem>();
for(int i = 1; i <= 10; i++)
{
result.Add(new SelectListItem {
Value = x.ToString(),
Text = x.ToString()
});
}
numberOfAdults = result.ToArray();

Related

Drop down List from Viewbag not following selected property

I have a dropdownList that will be populated by a viewbag carrying a List values containing "Text" and "Value" property that is set by a loop.
List<SelectListItem> year = new List<SelectListItem>();
for (var i = 1990; i <= DateTime.Now.Year; i++)
{
year.Add(new SelectListItem
{
Text = i.ToString(),
Value = i.ToString()
});
}
ViewBag.Year = year;
And in my view:
#Html.DropDownListFor(model => model.Year, new SelectList(ViewBag.Year, "Value", "Text", Model.Birthday.Year), htmlAttributes: new { #class = "form-control", style = "width: 80px" })
Nothing happens.
Try
#Html.DropDownListFor(model => model.Year, new SelectList(#ViewBag.Year, "Value", "Text", Model.Birthday.Year), new { #class = "form-control", style = "width: 80px" })
It will work as expected.
I used script instead
$('#Year option')
.removeAttr('selected')
.filter('[value=#Model.Birthday.Year]')
.attr('selected', true)

QueryExpression Phonecall to Contact

I've been stuck on this for a bit. Here's the scope of what I'm trying to do:
Retrieve phonecall records while bringing in contact information within the "to" field.
After much research, I have boiled down the code to below. I'm not too sure if I'm doing linked entities right - but can't determine how to do a nested join like I need to as I need to somehow get to the activitypointer -> activityparty -> contact...I just don't know where I"m going wrong. Any help would be greatly appreciated.
using Microsoft.Crm.Sdk.Messages.Samples;
using Microsoft.Xrm.Sdk.Query.Samples;
QueryExpression qExpression = new QueryExpression("phonecall")
{
ColumnSet = cs,
LinkEntities =
{
new LinkEntity()
{
EntityAlias = "ap",
LinkFromEntityName= "phonecall",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activitypointer",
LinkToAttributeName = "activityid",
JoinOperator = JoinOperator.Inner
},
new LinkEntity()
{
EntityAlias = "app",
LinkFromEntityName= "activitypointer",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
JoinOperator = JoinOperator.Inner,
LinkCriteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("ParticipationTypeMask", ConditionOperator.Equal, 2),
}
}
},
new LinkEntity()
{
EntityAlias = "con",
Columns = new ColumnSet("fullname","contactid"),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "activityparty",
LinkFromAttributeName = "partyid",
LinkToEntityName = "contact",
LinkToAttributeName = "contactid"
}
}
};
Looks like I answered my own question, giving some inspiration. I had to nest the link within a link.
This is what works now
QueryExpression qExpression = new QueryExpression("phonecall")
{
ColumnSet = cs,
LinkEntities =
{
new LinkEntity()
{
EntityAlias = "app",
LinkFromEntityName= "phonecall",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
JoinOperator = JoinOperator.Inner,
LinkCriteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("participationtypemask", ConditionOperator.Equal, 2),
}
},
LinkEntities =
{
new LinkEntity()
{
EntityAlias = "con",
Columns = new ColumnSet("fullname","contactid"),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "activityparty",
LinkFromAttributeName = "partyid",
LinkToEntityName = "contact",
LinkToAttributeName = "contactid"
}
}
},
}
};
Using DLaB.Xrm, you could re-write this like this:
var qe = QueryExpressionFactory.Create(cs, "phonecall");
var activityParty = qe.AddLink("activityparty", "activityid");
activityParty.WhereEqual("participationtypemask", 2);
activityParty.AddLink("contact", "partyid", "contactid")
.AddColumns("fullname","contactid");
Having a lot less code to look at tends to make it easier to Grok IMHO.
This is how I would read teach line of my 5 lines listed:
I'm doing a Query against the Phone Call Entity
Joining to the Activity Party on the activity Id (same key for both, no need to duplicate)
Where the activityParty's ParticipationTypeMask == 2
And joining from that to the Contact on ActivityParty.PartyId == Contact.ContactId
Including the name and Id of the contact.

how to load statically under here JqGrid asp.net mvc action dynamically

public ActionResult All(string sidx, string sord, int page, int rows)
{
var jsonData = new
{
total = 1, // we'll implement later
page = page,
records = 100, // implement later
rows = new[]{
new {id = 1, cell = new[] {"1", "hard asdf", "issue adfds", "more issue", "someuser", "otheruser", "2", "Submitted"}},
}
};
return Json(jsonData , JsonRequestBehavior.AllowGet);
}

How To Retrieve An Attribute Field In StockItems In Acumatica API?

I am wondering if a specific attribute can be retrieved in the Web Service API?
I have tried IN202500.AttributesAttributes.Value when exporting but that listed all attributes of the inventory. I also noticed the attributes are saved in the table as [AttributeName]_Attributes in the Inventory table, is there any way of retrieving this?
This is the code I am using (expecting it would retrieve the Attributes)
IN202500Content IN202500 = context.IN202500GetSchema();
context.IN202500Clear();
Command[] oCmd = new Command[] {
IN202500.StockItemSummary.ServiceCommands.EveryInventoryID,
IN202500.StockItemSummary.InventoryID,
IN202500.StockItemSummary.Description,
IN202500.StockItemSummary.ItemStatus,
IN202500.GeneralSettingsItemDefaults.ItemClass,
IN202500.GeneralSettingsItemDefaults.LotSerialClass,
new Field {
ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName,
FieldName = "BARCODE_Attributes"},
new Field {
ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName,
FieldName = "DfltReceiptLocationID"},
new Field {
ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName,
FieldName = "LastModifiedDateTime"}
};
Filter[] oFilter = new Filter[] {
new Filter
{
Field = new Field {
ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName,
FieldName = "LastModifiedDateTime"},
Condition = FilterCondition.Greater,
Value = SyncDate
}
};
String[][] sReturn = context.IN202500Export(oCmd, oFilter, 0, true, false);
But the Attribute field returned is an empty string.
Thanks,
G
You can leverage the dynamic fields that are added to the primary view of the screen to retrieve specific attribute values. These fields don't show up in the WSDL schema, so you have to create a Field object and pass it to the Export function.
I looked up the field name and object name from an Export scenario by displaying the Native Object / Native Field name columns. Resulting Export call looks like this:
var result = screen.Export(new IN202500.Command[] {
new IN202500.Value() { LinkedCommand = schema.StockItemSummary.InventoryID, Value = "Z730P00073"},
schema.StockItemSummary.InventoryID,
schema.StockItemSummary.Description,
new IN202500.Field { FieldName = "COLOR_Attributes", ObjectName = "Item"},
new IN202500.Field { FieldName = "HWMAN_Attributes", ObjectName = "Item"},
}, null, 0, true, true);
This code will retrieve the two attributes value (COLOR and HWMAN Attributes) for a specific inventory item (Z730P00073). The result variable contains a two-dimensional array, let me know if you need help getting results from the array.
This example shows how to add an item and set attributes and image:
byte[] filedata;
using (System.IO.FileStream file = System.IO.File.Open(#"C:\1.jpg", System.IO.FileMode.Open))
{
filedata = new byte[file.Length];
file.Read(filedata, 0, filedata.Length);
}
Random rnd = new Random();
string inventoryID = "CPU0000" + rnd.Next(100).ToString();
context.IN202500Clear();
IN202500result = context.IN202500Submit(
new Command[]
{
IN202500.Actions.Insert,
new Value { Value = inventoryID, LinkedCommand = IN202500.StockItemSummary.InventoryID },
new Value { Value = inventoryID, LinkedCommand = IN202500.StockItemSummary.Description },
new Value { Value = "CPU", LinkedCommand = IN202500.GeneralSettingsItemDefaults.ItemClass, Commit = true },
new Value { Value = "TAXABLE", LinkedCommand = IN202500.GeneralSettingsItemDefaults.TaxCategory, Commit = true },
//attributes - pairs
new Value { Value = "FREQUENCY", LinkedCommand = IN202500.AttributesAttributes.Attribute },
new Value { Value = "1400", LinkedCommand = IN202500.AttributesAttributes.Value, Commit = true },
new Value { Value = "CORE", LinkedCommand = IN202500.AttributesAttributes.Attribute },
new Value { Value = "2 CORES", LinkedCommand = IN202500.AttributesAttributes.Value, Commit = true },
new Value { Value = "INTGRAPH", LinkedCommand = IN202500.AttributesAttributes.Attribute },
new Value { Value = "True", LinkedCommand = IN202500.AttributesAttributes.Value, Commit = true },
//image
new Value { Value = Convert.ToBase64String(filedata), FieldName = "1.jpg", LinkedCommand = IN202500.StockItemSummary.ServiceCommands.Attachment }, //uploads
new Value { Value = "1.jpg", LinkedCommand = IN202500.Attributes.ImageUrl }, //sets as an item picture
IN202500.Actions.Save,
//return the result
IN202500.StockItemSummary.InventoryID
});

Acumatica - Creating customer payment method with api

What is the correct way to create a customer payment method using the API? This will also answer how to work with a grid that has a key value pair vs just storing values into a particular field.
This code has been in use and functioning correctly for almost a year now and then starting earlier this week it no longer works.
// Connect to Acumatica
context = new acumatica.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.AllowAutoRedirect = true;
context.EnableDecompression = true;
context.Timeout = 1000000;
context.Url = Properties.Settings.Default.WebServiceURL;
LoginResult result = api.context.Login(Properties.Settings.Default.AcumaticaUserName, Properties.Settings.Default.AcumaticaPassword);
context.AR303010Clear();
AR303010Content AR303010 = context.AR303010GetSchema();
try
{
Debug.WriteLine("--- Payment Method Start ---");
// Create Invoice
AR303010.Actions.Save.Commit = true;
AR303010Content[] AR303010Content = context.AR303010Submit
(
new Command[]
{
new Value { Value = "ABARTENDE", LinkedCommand = AR303010.PaymentMethodSelection.Customer, Commit = true },
AR303010.Actions.Insert,
new Value { Value = "VISA", LinkedCommand = AR303010.PaymentMethodSelection.PaymentMethod, Commit = true },
new Key
{
ObjectName = AR303010.PaymentMethodDetails.Description.ObjectName,
FieldName = AR303010.PaymentMethodDetails.Description.FieldName,
Value = "=[" + AR303010.PaymentMethodDetails.Description.ObjectName + "." + AR303010.PaymentMethodDetails.Description.FieldName + "]"
},
new Value {Value = "Card Number", LinkedCommand = AR303010.PaymentMethodDetails.Description},
new Value {Value = "4000000000003636", LinkedCommand = AR303010.PaymentMethodDetails.Value, Commit = true},
new Key
{
ObjectName = AR303010.PaymentMethodDetails.Description.ObjectName,
FieldName = AR303010.PaymentMethodDetails.Description.FieldName,
Value = "=[" + AR303010.PaymentMethodDetails.Description.ObjectName + "." + AR303010.PaymentMethodDetails.Description.FieldName + "]"
},
new Value {Value = "Card Verification Code", LinkedCommand = AR303010.PaymentMethodDetails.Description},
new Value {Value = "321", LinkedCommand = AR303010.PaymentMethodDetails.Value, Commit = true},
new Key
{
ObjectName = AR303010.PaymentMethodDetails.Description.ObjectName,
FieldName = AR303010.PaymentMethodDetails.Description.FieldName,
Value = "=[" + AR303010.PaymentMethodDetails.Description.ObjectName + "." + AR303010.PaymentMethodDetails.Description.FieldName + "]"
},
new Value {Value = "Expiration Date", LinkedCommand = AR303010.PaymentMethodDetails.Description},
new Value {Value = "012015", LinkedCommand = AR303010.PaymentMethodDetails.Value, Commit = true},
AR303010.Actions.Save
}
);
Debug.WriteLine("--- Payment Method Created ---");
}
catch (Exception ex)
{
Debug.WriteLine(" --- Failed to create Payment Method ---");
Debug.WriteLine(ex.Message);
}
The code was originally pulled from the Acumatica forums at:
http://forum.acumatica.com/forum/acumatica-reseller-and-isv-community/development-and-customization/5873-setting-credit-card-fields-though-web-services
http://forum.acumatica.com/forum/acumatica-reseller-and-isv-community/development-and-customization/885-help-on-add-new-payment-method-to-a-given-customer-by-webservice-ar303010
• We have tried using the code on a previous version that we know 100% that it used to work on.
• We have tried unpublishing our customizations.
• We have tried sending the data over to the acumatica demo located at tryacumatica.com
Every single site/version/computer we have tested it on returns the same error.
Error #12: Inserting 'Customer Payment Method Detail' record raised one or more errors. Please review. Error: 'Value' may not be empty. ---> PX.Data.PXOuterException: Error #12: Inserting 'Customer Payment Method Detail' record raised one or more errors. Please review.
Can somebody please point me in the right direction?
Ok, so here is working code provided from Acumatica. I still have no idea why the old code broke when it has been working this entire year, but here's working code and it's a little cleaner since you do not have to deal with key/value.
var context = new acumatica.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.AllowAutoRedirect = true;
context.EnableDecompression = true;
context.Timeout = 1000000;
LoginResult result = context.Login("admin", "admin");
context.AR303010Clear();
AR303010Content AR303010 = context.AR303010GetSchema();
try
{
var commands = new Command[]
{
new Value { Value = "ABARTENDE",
LinkedCommand = AR303010.PaymentMethodSelection.Customer},
AR303010.Actions.Insert,
new Value { Value = "VISA",
LinkedCommand = AR303010.PaymentMethodSelection.PaymentMethod},
new Value
{
Value = "='CCDNUM'",
LinkedCommand = AR303010.PaymentMethodDetails.Description
},
new Value { Value = "41111111111111118",
LinkedCommand = AR303010.PaymentMethodDetails.Value,
Commit = true
},
new Value
{
Value = "='CVV'",
LinkedCommand = AR303010.PaymentMethodDetails.Description
},
new Value { Value = "121",
LinkedCommand = AR303010.PaymentMethodDetails.Value,
Commit = true
},
new Value
{
Value = "='EXPDATE'",
LinkedCommand = AR303010.PaymentMethodDetails.Description
},
new Value {Value = "01/2019",
LinkedCommand = AR303010.PaymentMethodDetails.Value,
Commit = true
},
new Value
{
Value = "='NAMEONCC'",
LinkedCommand = AR303010.PaymentMethodDetails.Description
},
new Value {Value = "Mr Jon Doe 8",
LinkedCommand = AR303010.PaymentMethodDetails.Value,
Commit = true
},
AR303010.Actions.Save};
AR303010Content[] AR303010Content = context.AR303010Submit(commands.ToArray());
}
catch (Exception ex)
{
}
here is the example which i used
public void CreateARPayment()
{
string paymentType = GetParamValue("lblARPaymentType");
string paymentNbr = GetParamValue("lblARPaymentNbr");
string customerID = GetParamValue("txbCustomerID");
string cardAccountNo = GetParamValue("lblCardAccountNo");
string arInvoiceNbr = GetParamValue("txbARInvoiceNbr");
string soInvoiceNbr = GetParamValue("txbSOInvoiceNbr");
Screen context = new Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.Url = Url;
context.Login(Login, Password);
AR302000Content paymentSchema = context.AR302000GetSchema();
paymentSchema.PaymentSummary.CardAccountNo.FieldName += "!Descr";
var commands = new Command[]
{
new Value
{
Value = customerID,
LinkedCommand = paymentSchema.PaymentSummary.Customer
},
new Value
{
Value = "TOKENCC",
LinkedCommand = paymentSchema.PaymentSummary.PaymentMethod
},
new Value
{
Value = cardAccountNo,
LinkedCommand = paymentSchema.PaymentSummary.CardAccountNo
},
new Value
{
Value = "101000",
LinkedCommand = paymentSchema.PaymentSummary.CashAccount
},
new Value
{
Value = "09/2014/AR-00001",
LinkedCommand = paymentSchema.PaymentSummary.PaymentRef
},
paymentSchema.DocumentsToApply.ServiceCommands.NewRow,
new Value
{
Value = arInvoiceNbr,
LinkedCommand = paymentSchema.DocumentsToApply.ReferenceNbr,
Commit = true
},
paymentSchema.DocumentsToApply.ServiceCommands.NewRow,
new Value
{
Value = soInvoiceNbr,
LinkedCommand = paymentSchema.DocumentsToApply.ReferenceNbr,
Commit = true
},
paymentSchema.PaymentSummary.AppliedToDocuments,
};
var payment = context.AR302000Submit(commands)[0];
commands = new Command[]
{
new Value
{
Value = payment.PaymentSummary.AppliedToDocuments.Value,
LinkedCommand = paymentSchema.PaymentSummary.PaymentAmount
},
paymentSchema.Actions.Save,
paymentSchema.PaymentSummary.ReferenceNbr,
paymentSchema.PaymentSummary.Status,
paymentSchema.PaymentSummary.PaymentAmount
};
payment = context.AR302000Submit(commands)[0];
UpdateSetting("lblARPaymentNbr", payment.PaymentSummary.ReferenceNbr.Value);
UpdateSetting("lblARPaymentStatus", payment.PaymentSummary.Status.Value);
UpdateSetting("lblARPaymentAmount", payment.PaymentSummary.PaymentAmount.Value);
}

Resources