public ActionResult InsertProduct(InsertProductViewModel insertProductViewModel) { Product product = _productRepository.DataContext.Product.FirstOrDefault(c => c.Code == insertProductViewModel.Product.Code); if (product != null) { insertProductViewModel.Product = product; var quantity = 0; if (insertProductViewModel.ByWeight == true) { if (WhatIsThisTypeOfSale(product) == "Weight") { quantity = insertProductViewModel.Quantity; var priceSaleByMill = product.SalePrice / 1000; var priceBuyByMill = product.PurchasePrice / 1000; insertProductViewModel.FullSale = priceSaleByMill * quantity; insertProductViewModel.FullIncome = priceSaleByMill * quantity - (priceBuyByMill * quantity); } else { return PartialView("Alert"); } } else { if (WhatIsThisTypeOfSale(product) == "Weight") { return PartialView("Alert"); } quantity = insertProductViewModel.Quantity; insertProductViewModel.FullSale = product.SalePrice * quantity; insertProductViewModel.FullIncome = product.SalePrice * quantity - (product.PurchasePrice * quantity); } list.Add(insertProductViewModel); return PartialView(list); } return PartialView("Alert"); }
//[ValidateAntiForgeryToken] public ActionResult GetControlItens(InsertProductViewModel insertProductViewModel) { Controls control = _controlRepository.DataContext.FirstOrDefault(c => c.Code == insertProductViewModel.ControlsCode); if (control != null) { var lists = list.FirstOrDefault(c => c.ControlsCode == control.Code); if (lists == null) { foreach (var item in _saleWithActiveControlsRrepository.DataContext.Where(c => c.Controls.Code == control.Code)) { InsertProductViewModel productViewModel = new InsertProductViewModel(); { productViewModel.ControlsCode = control.Code; productViewModel.Product = _productRepository.GetByIds(item.ProductID); productViewModel.FullSale = item.FullPrice; productViewModel.Quantity = item.Quantity; productViewModel.FullIncome = item.FullPrice - (productViewModel.Product.PurchasePrice * item.Quantity); } list.Add(productViewModel); listControl.Add(control); } return PartialView(viewName: nameof(this.InsertProduct), model: list); } else { listControl.Add(control); return PartialView(viewName: nameof(this.InsertProduct), model: list); } } return PartialView("Alert"); }