public ActionResult StorageStaffApproveExportDone(int id) { var entity = Repository.GetAll().Where(p => p.TransferId == id).Include(p => p.TransferItems).FirstOrDefault(); using (UnitOfWork) { entity.ApproveFromStorageStaff = true; entity.ApproveFromStorageStaffAt = DateTime.Now; entity.ApproveFromStorageStaffId = WorkContext.CurrentUserId; Repository.Update(entity); //Update Product In Storage using (UnitOfWork) { foreach (var importDetail in entity.TransferItems) { var productInStorage = _productInStorageRepository.Search("") .FirstOrDefault( p => p.ProductId == importDetail.ProductId && p.StorageId == entity.FromStorageId); if (productInStorage == null) { var entityProductInStorage = new ProductInStorage { Amount = 0, ProductId = importDetail.ProductId, StorageId = entity.FromStorageId, IsDeleted = false }; _productInStorageRepository.Insert(entityProductInStorage); } else { productInStorage.Amount -= importDetail.Amount; _productInStorageRepository.Update(productInStorage); } } } } this.SetSuccessNotification("Đã xác nhận thành công!"); return(RedirectToAction("StorageStaffApproveExport", "Transfer", new { area = "Administrator" })); }
public ActionResult StoreNeedImportGridModel(string search) { var model = _productInStorageRepository.Search(search).Where(p => p.Amount < 1000).OrderBy(p => p.Amount); var gridModel = new GridModel <ProductInStorageModel> { Data = model.Select(x => new ProductInStorageModel { StorageId = x.StorageId, ProductId = x.ProductId, ProductName = x.Product.ProductName, StorageName = x.Storage.StorageName, Amount = x.Amount, ProductInStorageId = x.ProductInStorageId }) }; return(new JsonResult { Data = gridModel }); }
public virtual ActionResult SaveOrder(OrderModel model) { if (model.OrderId <= 0) //Create News { SaveOrderToSession(model); if (!OrderDetails.Any()) { SetErrorNotification(string.Format("Đơn hàng chưa có sản phẩm nào.")); return(RedirectToAction("CreateOrder", "Home", new { area = "", blank = false })); } if (model.CustomerId <= 0) { SetErrorNotification(string.Format("Đơn hàng chưa có khách hàng.")); return(RedirectToAction("CreateOrder", "Home", new { area = "", blank = false })); } if (model.PaymentType != (int)PaymentTypes.InOffice && string.IsNullOrEmpty(model.ShippingServiceName)) { SetErrorNotification(string.Format("Đơn hàng chưa chọn chành xe.")); return(RedirectToAction("CreateOrder", "Home", new { area = "", blank = false })); } //if (OrderDetails.Any(p => !p.PrintIncludeImage && !p.PrintWithoutImage)) //{ // SetErrorNotification(string.Format("Bạn phải chọn in hình hoặc in không hình cho sản phẩm.")); // return RedirectToAction("CreateOrder", "Home", new { area = "", blank = false }); //} var entity = new Order { IsDeleted = false, CreateDate = DateTime.Now, CreateUserId = WorkContext.CurrentUserId, Note = model.Note, MyOfficeId = model.MyOfficeId, TotalCost = model.TotalCost, ExtraFee = model.ExtraFee, Status = (int)OrderStatus.Imported, PaymentType = model.PaymentType, WaitForPrint = model.WaitForPrint, ShowOnTop = model.ShowOnTop, OrderDetails = new List <OrderDetail>() }; SetCustomerToOrder(model, entity); var myOffice = _myOfficeRepository.GetById(model.MyOfficeId); AddOrderDetailToOrder(entity, OrderDetails, myOffice.StorageId); //Update product in storage foreach (var orderDetailModel in OrderDetails) { var productInStorage = _productInStorageRepository.Search("").FirstOrDefault(p => p.ProductId == orderDetailModel.ProductId && p.StorageId == myOffice.StorageId); if (productInStorage != null && productInStorage.Amount > orderDetailModel.Amount) { productInStorage.Amount -= orderDetailModel.Amount; } else { var product = _productRepository.GetById(orderDetailModel.ProductId); SetErrorNotification(string.Format("Sản phẩm {0} đã hết trong kho.", product.ProductName)); return(RedirectToAction("CreateOrder", "Home", new { area = "", blank = false })); } } using (UnitOfWork) { _orderRepository.Insert(entity); } var customer = _customerRepository.GetById(entity.CustomerId); SendEmailConfirm(entity, new Customer { CustomerCode = customer.CustomerCode, PhoneNumber = customer.PhoneNumber, CustomerName = customer.CustomerName }, MakeOrderDetailHtml(entity)); OrderDetails = new List <OrderDetailModel>(); OrderSession = new OrderModel(); //this.SetSuccessNotification(string.Format("{0} đã được tạo thành công.", "Đơn hàng")); return(RedirectToAction("CreateOrder", "Home", new { area = "", blank = false, f = true })); } OrderDetails = new List <OrderDetailModel>(); OrderSession = new OrderModel(); //Save success this.SetSuccessNotification(string.Format("{0} đã được tạo thành công. Thông tin đặt hàng đã được gửi đến quý khách, vui lòng xem email để biết thêm chi tiết!", "Đơn hàng")); return(RedirectToAction("CreateOrder", "Home", new { area = "" })); }