示例#1
0
        public async System.Threading.Tasks.Task <ActionResult> AddEditSale(AddEditSaleViewModel model, FormCollection fc)
        {
            try {
                foreach (var key in fc.AllKeys.Where(x => x.StartsWith("product-")).ToList())
                {
                    var num          = key.Split('-');
                    var keyProduct   = "product-" + num[1];
                    var keyQuantity  = "quantity-" + num[1];
                    var keyUnitPrice = "unitprice-" + num[1];

                    model.LstSaleDetail.Add(new SaleDetailEntity()
                    {
                        ProductBrandId = Convert.ToInt32(fc[keyProduct]),
                        Amount         = Convert.ToDecimal(fc[keyQuantity]),
                        Price          = Convert.ToDecimal(fc[keyUnitPrice]),
                        Total          = Convert.ToDecimal(fc[keyUnitPrice]) * Convert.ToDecimal(fc[keyQuantity]),
                    });
                }

                var postResult = ConstantHelpers.PostUrlAsync(Baseurl, "SAV/sales", model).Result;
                if (postResult.Message.Equals("Success"))
                {
                    return(RedirectToAction("ListSale", "Sale"));
                }
                await model.FillAdd(CargarDatosContext());

                return(View(model));
            } catch (Exception ex) {
                TryUpdateModel(model);
                await model.FillAdd(CargarDatosContext());

                return(View(model));
            }
        }
示例#2
0
        public async System.Threading.Tasks.Task <ActionResult> AddEditSale()
        {
            var vm = new AddEditSaleViewModel();
            await vm.FillAdd(CargarDatosContext());

            return(View(vm));
        }