public void CreateEntries(VATRegModel model) { foreach (PropertyInfo p in typeof(VATRegModel).GetProperties()) { if (p.PropertyType == typeof(Double)) { DescriptionAttribute descriptionAttribute = (DescriptionAttribute)p.GetCustomAttribute(typeof(DescriptionAttribute), false); string Description = descriptionAttribute.Description; double Amount = 0.0; if (p.GetValue(model) != null) { Amount = (double)p.GetValue(model); } string Name = p.Name; VATEntries.Add(new VATEntryViewModel(Description, Amount, Name)); } } }
public void ListSums(VATRegModel model, VATDraftModel draftModel) { PropertyInfo[] propertyInfos = null; propertyInfos = draftModel.GetType().GetProperties(); foreach (var item in propertyInfos) { var prop = item.GetValue(draftModel); if (item.Name.Substring(0, 1).Equals("R")) { if (prop is IEnumerable) { double i = 0; foreach (var listitem in prop as IEnumerable) { double k = (double)listitem; i = i + k; } foreach (PropertyInfo p in typeof(VATRegModel).GetProperties()) { if (item.Name.Length == 2 && p.Name.Length == 2) { if (p.Name.Substring(0, 2).Equals(item.Name.Substring(0, 2))) { p.SetValue(model, i); } } if (item.Name.Length == 3 && p.Name.Length == 3) { if (p.Name.Substring(0, 3).Equals(item.Name.Substring(0, 3))) { p.SetValue(model, i); } } } } } } }