public ActionResult Buy(SaleFactor salefactor) { OrderRepository blOrder = new OrderRepository(); SaleFactorRepository blFactor = new SaleFactorRepository(); ProductRepository blProduct = new ProductRepository(); List <BasketViewModel> listBasket = new List <BasketViewModel>(); List <HttpCookie> lst = new List <HttpCookie>(); //list of cookie for (int i = Request.Cookies.Count - 1; i >= 0; i--) { if (lst.Where(p => p.Name == Request.Cookies[i].Name).Any() == false) //delete repetetive cooki { lst.Add(Request.Cookies[i]); // add cooki to list } } decimal price = 0; foreach (var item in listBasket) { price += (item.Product.Price * item.Count); } salefactor.BuyDate = DateTime.Now; salefactor.Price = price; //salefactor.Description = "خرید در تاریخ " + DateTime.Now.ToString() + "یه مبلغ" + salefactor.Price.ToString() + "انجام شد"; salefactor.Description = "ok"; salefactor.UserId = Convert.ToInt32(Session["LoginUserId"]); if (blFactor.Add(salefactor)) { int FactorId = blFactor.GetLastIdentity(); foreach (var item in listBasket) { blOrder.Add(new Order() { OrderId = FactorId, ProductId = item.Product.ProductId, Qty = Convert.ToByte(item.Count) }); } } else { ViewBag.Message = "اطلاعات شما ثبت نشد"; } return(View()); }
public SaleFactorAppService(SaleFactorRepository repository, UnitOfWork unitOfWork, GoodRepository goodRepository) { _repository = repository; _unitOfWork = unitOfWork; _goodRepository = goodRepository; }