public List <Dictionary <string, object> > GetPurchaseByUser(string user) { List <Dictionary <string, object> > jewelries = new List <Dictionary <string, object> >(); ColmanInternetiotContext context = new ColmanInternetiotContext(); // Get list of current account purchases List <Purchase> purchases = context.Purchase.Where(x => x.UserId == Account.GetCurrAccountId(User)).ToList(); foreach (Purchase purchase in purchases) { Dictionary <string, object> dictJewelry = new Dictionary <string, object>(); //Get the jewelry object of the jewelry that bought in this purchase Jewelry jewelry = context.Jewelry.First(x => x.Id == purchase.JewelryId); jewelry.Purchase = null; // Convert from Jewelry object to Dictionary dictJewelry = jewelry.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public) .ToDictionary(prop => prop.Name.ToLower(), prop => prop.GetValue(jewelry, null)); // Add a summary attribute dictJewelry.Add("summary", purchase.Amount + " X " + jewelry.Price); jewelries.Add(dictJewelry); } return(jewelries); }
/// <summary> /// Method used to update fields of object that will be edited on the ui /// </summary> /// <param name="item"></param> public void InitJewelryFields(ref Jewelry item) { Fields = null; Fields = new ObservableCollection <EditJewelryItem>(); var props = item.GetType().GetProperties(); foreach (var property in props) { //if this is list of materials, skip if (property.PropertyType.IsGenericList()) { continue; } if (property.GetMethod.ReturnType.IsEnum) { Fields.Add(new EditJewelryItem() { UiName = property.GetCustomAttribute <UiNameAttribute>(false).Name, Name = property.Name, ElementType = UiElementType.Enum, EnumTypes = property.GetMethod.ReturnType.GetEnumNames(), FieldType = property.GetMethod.ReturnType }); } else { Fields.Add(new EditJewelryItem() { Name = property.Name, UiName = property.GetCustomAttribute <UiNameAttribute>(false).Name, ElementType = UiElementType.Field, FieldType = property.GetMethod.ReturnType }); } } JewelryToEdit = item; EditableJewelryMaterials = JewelryToEdit.Materials; EditableJewelryMaterialsUI = new ObservableCollection <Material>(JewelryToEdit.Materials); IsEditingJewelryAllowed = true; IsEditingMaterialAllowed = true; }