public ActionResult SuaSale(StoreSale storeSale, string StoreID) { var ss = db.StoreSales.Where(n => n.StoreSaleID == storeSale.StoreSaleID).SingleOrDefault(); if (ss == null) { //Trả về trang báo lỗi Response.StatusCode = 404; return(null); } ss.Sale = storeSale.Sale; ss.StartSale = storeSale.StartSale; ss.StopSale = storeSale.StopSale; ss.KeySale = storeSale.KeySale; if (ModelState.IsValid) { //Thực hiện cập nhận trong model db.Entry(ss).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Session["Message"] = "Sửa thành công"; return(RedirectToAction("QuanLySale", new { StoreID = StoreID, page = 1, method = "Sua" })); } ViewBag.StoreID = StoreID; return(View(storeSale)); }
public async Task SaveStoreSaleAsync(StoreSale sale) { var businessDate = DateTime.Now; var storeId = this.session.StoreID.Value; await this.salesService.SaveStoreSalesAsync(storeId, businessDate, sale); }
public async Task <IActionResult> Edit(int id, [Bind("StoreID,SaleId")] StoreSale storeSale) { if (id != storeSale.SaleId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(storeSale); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StoreSaleExists(storeSale.SaleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["StoreID"] = new SelectList(_context.Set <Sale>(), "Id", "Name", storeSale.StoreID); ViewData["SaleId"] = new SelectList(_context.Stores, "Id", "Name", storeSale.SaleId); return(View(storeSale)); }
public async Task <IActionResult> Create([Bind("StoreID,SaleId")] StoreSale storeSale) { if (ModelState.IsValid) { _context.Add(storeSale); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["StoreID"] = new SelectList(_context.Set <Sale>(), "Id", "Name", storeSale.StoreID); ViewData["SaleId"] = new SelectList(_context.Stores, "Id", "Name", storeSale.SaleId); return(View(storeSale)); }
public ActionResult ThemSale(StoreSale storeSale, string StoreID) { storeSale.StoreID = Guid.Parse(StoreID); if (ModelState.IsValid) { //Thực hiện cập nhận trong model db.Entry(storeSale).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); Session["Message"] = "Thêm thành công"; return(RedirectToAction("QuanLySale", new { StoreID = StoreID, page = 1, method = "ThemMoi" })); } ViewBag.StoreID = StoreID; return(View(storeSale)); }
public Sales MapSale(StoreSale sale) { return(new Sales { CashDeposite = sale.CashDeposite, DamageQuantity = sale.DamageQuantity, MissingCrate = sale.MissingCrate, MissingQuantity = sale.MissingQuantity, OnlineOrder = sale.OnlineOrder, OpenOrder = sale.OpenOrder, PendingConsignment = sale.PendingConsignment, PendingSapphireComplain = sale.PendingSapphireComplain, PureMarquee = sale.PureMarquee, TotalMarquee = sale.TotalMarquee, TotalOnline = sale.TotalOnline, }); }
/// <inheritdoc /> public async Task SaveStoreSalesAsync(int storeId, DateTime date, StoreSale sale) { var existingSale = await this.mammothDBContext.Sales .Where(x => x.BusinessDate == date && x.StoreId == storeId) .FirstOrDefaultAsync(); if (existingSale != null) { existingSale.Id = existingSale.Id; existingSale.CashDeposite = sale.CashDeposite; existingSale.DamageQuantity = sale.DamageQuantity; existingSale.MissingCrate = sale.MissingCrate; existingSale.MissingQuantity = sale.MissingQuantity; existingSale.OnlineOrder = sale.OnlineOrder; existingSale.OpenOrder = sale.OpenOrder; existingSale.PendingConsignment = sale.PendingConsignment; existingSale.PendingSapphireComplain = sale.PendingSapphireComplain; existingSale.PureMarquee = sale.PureMarquee; existingSale.TotalMarquee = sale.TotalMarquee; existingSale.TotalOnline = sale.TotalOnline; existingSale.LastModifiedBy = this.session.LoginID.Value; existingSale.LastModifiedOn = DateTime.Now; this.mammothDBContext.Entry(existingSale).State = EntityState.Modified; } else { var saleData = this.mappers.MapSale(sale); saleData.StoreId = storeId; saleData.BusinessDate = date; saleData.LastModifiedBy = this.session.LoginID.Value; saleData.LastModifiedOn = DateTime.Now; this.mammothDBContext.Sales.Add(saleData); } await this.mammothDBContext.SaveChangesAsync(); }
public JsonResult DatHang(DatHangDto datHangDto) { if (Session["TaiKhoan"] != null) { try { Customer cus = (Customer)Session["TaiKhoan"]; var stID = Guid.Parse(datHangDto.StoreID); Store store = db.Stores.Where(n => n.StoreID == stID).SingleOrDefault(); GioHangStore gioHangStore = getGioHangStore(stID + ""); List <GioHang> lstGioHang = new List <GioHang>(); if (store != null && gioHangStore.Orders != null) { lstGioHang = gioHangStore.Orders; var tongCong = 0; lstGioHang.ForEach(n => tongCong += (int)n.ThanhTien); var totalPrice = tongCong; var serviceChange = 0; if (tongCong < store.ConditionShip) { totalPrice += (int)store.ServiceCharge; serviceChange = (int)store.ServiceCharge; } var sale = 0; if (datHangDto.StoreSaleID != 0) { StoreSale stSale = db.StoreSales.Where(n => n.StoreSaleID == datHangDto.StoreSaleID && n.StoreID == store.StoreID).SingleOrDefault(); if (stSale != null) { sale = totalPrice * (int)stSale.Sale / 100; totalPrice = totalPrice - sale; } } var shippingFee = 0; if (datHangDto.Distance > 0) { shippingFee = (int)(datHangDto.Distance * store.ShippingFee); } lstGioHang = gioHangStore.Orders; Invoice iv = new Invoice() { InvoiceID = Guid.NewGuid(), OrderDate = DateTime.Now, DeliveryDate = DateTime.Parse(datHangDto.DateDelivery + " " + datHangDto.TimeDelivery), AddressDelivery = datHangDto.CustomerAddress, CustomerID = cus.CustomerID, CustomerName = datHangDto.CustomerName, CustomerPhone = datHangDto.CustomerPhone, StoreID = stID, ServiceChange = serviceChange, Sale = sale, ShippingFee = shippingFee, TotalPrice = totalPrice, Status = 0 }; if (ModelState.IsValid) { //Thực hiện cập nhận trong model db.Entry(iv).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } foreach (var gh in lstGioHang) { var foodID = Guid.Parse(gh.FoodID); InvoiceDetail ivDT = new InvoiceDetail() { InvoiceID = iv.InvoiceID, FoodID = foodID, Size = gh.FoodSize, PriceSize = (decimal)gh.PriceSize, Type = gh.FoodType, PriceType = (Decimal)gh.PriceType, NumberFood = gh.SoLuong, }; if (ModelState.IsValid) { //Thực hiện cập nhận trong model db.Entry(ivDT).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } } return(Json(true)); } } catch { return(Json(false)); } } return(Json(false)); }