private FullAndPartialViewModel GetModelByCategory(int intId) { FullAndPartialViewModel modelReturn = new FullAndPartialViewModel(); List <CategoryProductItem> Product1 = new List <CategoryProductItem>() { new CategoryProductItem() { ItemProduct = "Test11" } }; List <CategoryListItem> Kategori1 = new List <CategoryListItem>() { new CategoryListItem() { CategoryId = 1, CategoryName = "11Test" }, new CategoryListItem() { CategoryId = 2, CategoryName = "22Test" } }; List <CategoryProductItem> Product2 = new List <CategoryProductItem>() { new CategoryProductItem() { ItemProduct = "Test22" } }; List <CategoryListItem> Kategori2 = new List <CategoryListItem>() { new CategoryListItem() { CategoryId = 2, CategoryName = "22Test" } }; if (intId == 0) { modelReturn = new FullAndPartialViewModel() { CategoryId = 1, Products = Product1, CategoryList = Kategori1 }; } if (intId == 1) { modelReturn = new FullAndPartialViewModel() { CategoryId = 1, Products = Product1, CategoryList = Kategori1 }; } if (intId == 2) { modelReturn = new FullAndPartialViewModel() { CategoryId = 2, Products = Product2, CategoryList = Kategori2 }; } return(modelReturn); }
public ActionResult Index() { var items = _dataAccess.GetData <Item>(ItemsFileLocation); var viewModel = new FullAndPartialViewModel(); viewModel.Items = items; return(View(viewModel)); }
private FullAndPartialViewModel CreateInvoiceTablelContent(string itemIds) { var viewModel = new FullAndPartialViewModel(); var items = new List <Item>(); var ids = itemIds.Split(IdentifiersSeparator); decimal totalTax = 0; decimal total = 0; decimal discount = 0; var index = 1; foreach (var id in ids) { var innerId = 0; var quantity = 1; var tempVariable = string.Empty; if (id.Contains(IdentifiersQuantitySeparator)) { quantity = Int32.Parse(id.Split(IdentifiersQuantitySeparator)[1]); tempVariable = id.Replace(IdentifiersQuantitySeparator.ToString() + quantity, string.Empty); } else { tempVariable = id; } if (Int32.TryParse(tempVariable, out innerId)) { var item = _dataAccess.GetItem <Item>(ItemsFileLocation, innerId); if (quantity != item.Quantity) { item = new Item() { Id = item.Id, Description = item.Description, Quantity = quantity, UnitPrice = item.UnitPrice, Tax = item.Tax, IsPromotionItem = item.IsPromotionItem, PromotionDiscount = item.PromotionDiscount }; } item.Index = index; items.Add(item); totalTax += item.TotalTax; discount += item.Discount; total += item.Total; index += 1; } } viewModel.InvoiceRows = items; viewModel.TotalTax = totalTax; ProcessTotal(viewModel, total, discount); return(viewModel); }
private void ProcessTotal(FullAndPartialViewModel viewModel, decimal total, decimal discount) { var rangeList = _dataAccess.GetData <RangeAndDiscount>(RangeListFileLocation); var closest = rangeList.Aggregate((x, y) => Math.Abs(x.Range - total) < Math.Abs(y.Range - total) ? x : y); var rangeDiscount = (total * closest.Discount) / 100; total = total - rangeDiscount; viewModel.Total = total; viewModel.Discount = discount + rangeDiscount; }