public async Task <JsonResult> DisableDiscount(DisscountModel model) { var Messaging = new RenderMessaging(); try { if (User == null || User.UserId < 0) { Messaging.isError = true; Messaging.messaging = "Vui lòng đăng nhập lại!"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } Messaging.isError = !await _IDiscountBusiness.DisableDiscount(model, User.UserId); Messaging.messaging = !Messaging.isError ? "Tắt khuyễn mãi thành công!" : "Tắt khuyễn mãi không thành công!"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Tắt khuyễn mãi không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
private RenderMessaging Validate_Product(ProductSampleModel model) { var Messaging = new RenderMessaging(); if (model.masp.Length >= 9) { Messaging.isError = true; Messaging.messaging = "Code không được lớn 10 ký tự!"; return(Messaging); } if (string.IsNullOrEmpty(model.tensp)) { Messaging.isError = true; Messaging.messaging = "Tên sản phẩm không được trống."; return(Messaging); } if (model.id <= 0) { var productexits = _context.shop_sanpham.FirstOrDefault(o => o.masp.Equals(model.masp)); if (productexits != null) { Messaging.isError = true; Messaging.messaging = "Mã sản phẩm đã tồn tại."; return(Messaging); } } return(null); }
public async Task <JsonResult> CreateOrder_Inside(OrderModel model, bool isDone = true, int OrderSuppliersId = 0) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.Detail.Count <= 0) { Messaging.isError = true; Messaging.messaging = "Dữ liệu không hợp lệ, vui lòng kiểm tra lại"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var user = Mapper.Map <UserCurrent>(User); var isError = await _IOrderBus.AddOrder_Input(model, user, isDone, OrderSuppliersId); Messaging.isError = !isError; Messaging.messaging = "Đã Nhập hàng thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Nhập hàng không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> RemoveChannel(ChannelModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.Id <= 0) { Messaging.isError = true; Messaging.messaging = "Thông tin Kênh không hợp lệ"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } Messaging.isError = !await _IChannelBusiness.RemoveChannel(model.Id); Messaging.messaging = !Messaging.isError ? "Xóa kênh thành công!" : "Kênh không xóa được vui lòng kiểm tra lại."; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Kênh không xóa được vui lòng kiểm tra lại."; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> UpdateBranches(BranchesModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.BranchesName) || string.IsNullOrEmpty(model.Address) || string.IsNullOrEmpty(model.Phone)) { Messaging.isError = true; Messaging.messaging = "Thông tin Kho không hợp lệ"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } Messaging.isError = !await _IBrachesBusiness.UpdateBranches(model, User.UserId); Messaging.messaging = !Messaging.isError ? "Cập nhật kho thành công!" : "Cập nhật kho không thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Cập nhật kho không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> Update_Channel(ChannelModel model) { var Messaging = new RenderMessaging(); try { if (model.Id <= 0 || string.IsNullOrEmpty(model.Channel) || string.IsNullOrEmpty(model.Code)) { Messaging.isError = true; Messaging.messaging = "Thông tin Kênh không hợp lệ"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } Messaging.isError = !await _IChannelBusiness.UpdateChannel(model, User.UserId); Messaging.messaging = !Messaging.isError ? "Cập nhật kênh bán hàng thành công!" : "Cập nhật kênh bán hàng không thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Cập nhật kênh bán hàng không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult LoadEmployessInfo() { var Messaging = new RenderMessaging(); try { if (User == null || User.ChannelId <= 0) { Messaging.isError = true; Messaging.messaging = "Vui lòng đăng nhập lại!"; } var employ = _context.sys_Employee.Find(User.UserId); if (employ == null) { Messaging.isError = true; Messaging.messaging = "Vui lòng đăng nhập lại!"; } var result = Mapper.Map <EmployeeModel>(employ); Messaging.Data = result; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Hiển thị nhân viên không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult GetCatalogby(PagingInfo pageinfo) { var Messaging = new RenderMessaging <Channel_Paging <CatalogModel> >(); try { if (User == null || User.ChannelId <= 0) { Messaging.isError = true; Messaging.messaging = "Vui lòng đăng nhập lại!"; } Channel_Paging <CatalogModel> lstInfo = new Channel_Paging <CatalogModel>(); int count, min = 0; var rs = catalogBus.GetCatalog(pageinfo, out count, out min); lstInfo.startItem = min; lstInfo.totalItems = count; lstInfo.listTable = rs; Messaging.Data = lstInfo; } catch { Messaging.isError = true; Messaging.messaging = "Hiển thị Nhóm sản phẩm có lỗi!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> DeleteCatalog(int id) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (id <= 0) { Messaging.isError = true; Messaging.messaging = "Dữ liệu không hợp lệ vui lòng thử lại."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } Messaging.isError = !await catalogBus.DeleteCatalog(id); Messaging.messaging = !Messaging.isError ? "Xóa Nhóm hàng thành công!" : "Xóa nhóm hàng không thành công, vui lòng thử lại!"; } catch { Messaging.isError = true; Messaging.messaging = "Nhóm hàng này đang sử dụng không xóa được, vui lòng thử lại!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult GetDisscount(string code) { var Messaging = new RenderMessaging(); if (!string.IsNullOrEmpty(code)) { var dateNow = DateTime.Now; var discount = _unitOW.DisscountRepository.FindBy(o => o.Code.Equals(code) && o.Disable == false && dateNow >= o.Startdate && (o.IsNotExp == true || dateNow < o.Enddate)).FirstOrDefault(); if (discount == null) { Messaging.isError = true; Messaging.messaging = "Vui lòng kiểm tra mã khuyến mãi."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } else { Messaging.isError = false; Messaging.Data = new { value = discount.Value, type = discount.Type }; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } } return(null); }
public async Task <JsonResult> UpdateStatus_Order_Sale(OrderModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var user = Mapper.Map <UserCurrent>(User); var result = await _IOrderBus.UpdateOrder_Sale(model, user); if (!result.Item1) { Messaging.isError = true; Messaging.messaging = !string.IsNullOrEmpty(result.Item2) ? result.Item2 : "Cập nhât đơn hàng không thành công."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } Messaging.isError = false; Messaging.messaging = "Cập nhật đơn hàng thành công."; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Cập nhật đơn hàng không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> UpdateCustomer(CustomerModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Phone) || string.IsNullOrEmpty(model.Address) || string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.User)) { Messaging.isError = true; Messaging.messaging = "Dữ liệu không hợp lệ vui lòng thử lại."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } Messaging.isError = !await _customerBus.UpdateCustomer(model); Messaging.messaging = !Messaging.isError ? "Cập nhật khách hàng thành công!" : "Cập nhật khách hàng không thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Cập nhật khách hàng không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public ActionResult GetConfig() { var Messaging = new RenderMessaging <BarcodeModel>(); try { var config = _IBarCodeBusiness.GetConfig(User.BranchesId); if (config == null) { Messaging.Data = new BarcodeModel(); } else { Messaging.Data = config; } Messaging.isError = false; } catch { Messaging.isError = true; Messaging.messaging = "Không lấy được cấu hình, vui lòng thử lại."; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> RemoveBranchs(BranchesModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.BranchesId <= 0) { Messaging.isError = true; Messaging.messaging = "Thông tin Kho không hợp lệ"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } Messaging.isError = !await _IBrachesBusiness.RemoveBranchs(model.BranchesId); Messaging.messaging = Messaging.isError ? "Kho không xóa được vui lòng kiểm tra lại." : "Xóa Kho thành công!"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } catch { Messaging.isError = true; Messaging.messaging = "Kho không xóa được vui lòng kiểm tra lại."; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult GetEmployessby(PagingInfo pageinfo) { var Messaging = new RenderMessaging <Channel_Paging <EmployeeModel> > (); try { if (User == null || User.ChannelId <= 0) { Messaging.isError = true; Messaging.messaging = "Vui lòng đăng nhập lại!"; } Channel_Paging <EmployeeModel> lstInfo = new Channel_Paging <EmployeeModel>(); int count, min = 0; var rs = _IEmployessBusiness.GetEmployessby(pageinfo, out count, out min); lstInfo.startItem = min; lstInfo.totalItems = count; lstInfo.listTable = rs; Messaging.Data = lstInfo; Messaging.Data = lstInfo; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Hiển thị danh sách nhân viên không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult GetCustomerby(PagingInfo pageinfo) { var Messaging = new RenderMessaging(); try { if (User == null || User.ChannelId <= 0) { Messaging.isError = true; Messaging.messaging = "Vui lòng đăng nhập lại!"; } Channel_Paging <CustomerModel> lstInfo = new Channel_Paging <CustomerModel>(); int count, min = 0; var rs = _customerBus.GetCustomer(pageinfo, out count, out min); lstInfo.startItem = min; lstInfo.totalItems = count; lstInfo.listTable = rs; Messaging.Data = lstInfo; } catch { Messaging.isError = true; Messaging.messaging = "Hiển thị danh sách khách hàng không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteEmployess(int id) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var employee = _context.sys_Employee.Find(id); employee.IsDelete = true; _crud.Update <sys_Employee>(employee, o => o.IsDelete); _crud.SaveChanges(); Messaging.messaging = "Xóa User thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Xóa nhân viên không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateEmloyeeTitle(Employee_TitleModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var emp = Mapper.Map <soft_Employee_Title>(model); _crud.Add <soft_Employee_Title>(emp); _crud.SaveChanges(); Messaging.messaging = "Cập nhật Chức danh thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Cập nhật chức danh không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateEmployess(EmployeeModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.Id <= 0 && (string.IsNullOrEmpty(model.Pwd) || model.Pwd.Length <= 5)) { Messaging.isError = true; Messaging.messaging = "Mật khẩu không hợp lệ."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.Email)) { Messaging.isError = true; Messaging.messaging = "Email không được rỗng!"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var objEmployee = Mapper.Map <sys_Employee>(model); if (model.Id <= 0) { objEmployee.DateCreate = DateTime.Now; objEmployee.EmployeeCreate = User.UserId; objEmployee.DateUpdate = null; _crud.Add <sys_Employee>(objEmployee); } else { var employee = _context.sys_Employee.Find(model.Id); objEmployee.DateCreate = employee.DateCreate; objEmployee.DateUpdate = DateTime.Now; objEmployee.EmployeeUpdate = User.UserId; //objEmployee.IsDisable = model.IsDisable; objEmployee.Pwd = !string.IsNullOrEmpty(model.Pwd) ? model.Pwd : employee.Pwd; _crud.Update <sys_Employee>(objEmployee, o => o.Titles, o => o.IsDisable, o => o.Pwd, o => o.Address, o => o.Email, o => o.Name, o => o.Phone, o => o.Phone, o => o.DateUpdate, o => o.EmployeeUpdate, o => o.Roles, o => o.Titles); } _crud.SaveChanges(); Messaging.messaging = "Cập nhật nhân viên thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Cập nhật nhân viên không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult GetProductbyId(int productId) { var note = string.Empty; var Messaging = new RenderMessaging(); var product = _context.shop_sanpham.Find(productId); if (product == null) { Messaging.Data = new { result = "Sản phẩm không tồn tại." }; Messaging.isError = true; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var orderProduct = _context.soft_Order_Child.Where(o => o.ProductId == productId).ToList(); var orderedSup = orderProduct.FirstOrDefault(o => o.soft_Order.TypeOrder == (int)TypeOrder.OrderProduct && o.Status == (int)StatusOrder_Suppliers.Process); if (orderedSup != null) { var productcheck = _context.shop_sanpham.Find(orderedSup.ProductId); if (productcheck != null) { note += " Đơn hàng số " + orderedSup.OrderId + " đã đặt sản phẩm " + productcheck.tensp + " ngày " + orderedSup.soft_Order.DateCreate + "."; } } var price = Mapper.Map <Product_PriceModel>(_context.soft_Channel_Product_Price.FirstOrDefault(o => o.ProductId == product.id && o.ChannelId == User.ChannelId)); var stocks = Mapper.Map <List <Product_StockModel> >(_context.soft_Branches_Product_Stock.Where(o => o.ProductId == product.id).ToList()); var stock = stocks.FirstOrDefault(o => o.BranchesId == User.BranchesId); var productInfo = new Prodcut_Branches_PriceChannel { product_price = price ?? price, product_stock = stock ?? stock, product = Mapper.Map <ProductSampleModel>(product), product_stocks = stocks }; if (product.soft_Suppliers != null) { productInfo.product.SuppliersName = product.soft_Suppliers.Name; } if (product.soft_Branches_Product_Stock != null) { var stockbyBranches = product.soft_Branches_Product_Stock.FirstOrDefault(o => o.BranchesId == User.BranchesId); if (stockbyBranches != null) { productInfo.product.Stock_Total = stockbyBranches.Stock_Total; } } Messaging.Data = new { result = productInfo, note = note }; Messaging.isError = false; return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateMyInfo(EmployeeModel model) { var Messaging = new RenderMessaging(); try { var employee = _context.sys_Employee.Find(User.UserId); if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.isUpdatePwd && (!employee.Pwd.Equals(model.Pwd))) { Messaging.isError = true; Messaging.messaging = "Mật khẩu xác nhận không đúng."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.isUpdatePwd && (string.IsNullOrEmpty(model.Pwd) || string.IsNullOrEmpty(model.PwdNew) || model.PwdNew.Length <= 5)) { Messaging.isError = true; Messaging.messaging = "Mật khẩu không hợp lệ."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var objEmployee = Mapper.Map <sys_Employee>(model); objEmployee.Email = employee.Email; objEmployee.Pwd = model.isUpdatePwd ? model.PwdNew : employee.Pwd; objEmployee.DateCreate = employee.DateCreate; objEmployee.EmployeeCreate = employee.EmployeeCreate; objEmployee.DateUpdate = DateTime.Now; objEmployee.EmployeeUpdate = User.UserId; _crud.Update <sys_Employee>(objEmployee, o => o.Address, o => o.Name, o => o.Phone, o => o.DateUpdate, o => o.EmployeeUpdate, o => o.Pwd); _crud.SaveChanges(); Messaging.messaging = "Cập nhật thông tin thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Cập nhật thông tin cá nhân không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateDone_Order_Suppliers(int id) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var order = _context.soft_Order.Find(id); if (order == null) { Messaging.isError = true; Messaging.messaging = "Không tìm thấy đơn hàng này."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var objOrder = new soft_Order { Id = id, Status = (int)StatusOrder_Suppliers.Done, DateUpdate = DateTime.Now, EmployeeUpdate = User.UserId }; _crud.Update <soft_Order>(objOrder, o => o.Status, o => o.EmployeeUpdate, o => o.DateUpdate); foreach (var item in order.soft_Order_Child) { var objOrderChild = new soft_Order_Child { Id = item.Id, Status = (int)StatusOrder_Suppliers.Done, OrderId = item.OrderId, Price = item.Price, ProductId = item.ProductId, Total = item.Total }; _crud.Update <soft_Order_Child>(objOrderChild, o => o.Status); } _crud.SaveChanges(); } catch { Messaging.isError = true; Messaging.messaging = "Cập nhật phiếu đặt hàng nhà phân phối không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult CreateProduct(ProductSampleModel model) { var Messaging = new RenderMessaging(); try { if (User == null || User.UserId < 0) { Messaging.isError = true; Messaging.messaging = "Vui lòng đăng nhập lại!"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } model.masp = model.masp.Replace(" ", ""); var msError = Validate_Product(model); if (msError != null) { return(Json(msError, JsonRequestBehavior.AllowGet)); } var data = new shop_sanpham { tensp = model.tensp, masp = model.masp, Barcode = model.Barcode, PriceCompare = 0, PriceBase = 0, PriceBase_Old = 0, PriceInput = 0, hide = false, Status = model.Status, Note = model.Note, DateCreate = DateTime.Now, FromCreate = (int)TypeFromCreate.Soft }; _crud.Add <shop_sanpham>(data); _crud.SaveChanges(); Messaging.isError = false; Messaging.messaging = "Thêm sản phẩm thành công."; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Tạo sản phẩm không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> ChangePrice(Product_PriceModel model) { var Messaging = new RenderMessaging(); try { var pricechannel = _unitOW.ChanelPriceRepository.FindBy(o => o.ProductId == model.ProductId && o.ChannelId == User.ChannelId).FirstOrDefault(); if (pricechannel != null) { if (pricechannel.Price != model.Price) { pricechannel.Price = Convert.ToInt32(Helpers.Round_Double(model.Price, -3));; pricechannel.DateUpdate = DateTime.Now; pricechannel.EmployeeUpdate = User.UserId; _unitOW.ChanelPriceRepository.Update(pricechannel, o => o.Price, o => o.DateUpdate, o => o.EmployeeUpdate); await _unitOW.SaveChanges(); } } else { var data = new soft_Channel_Product_Price { Price = Convert.ToInt32(Helpers.Round_Double(model.Price, -3)), ChannelId = User.ChannelId, ProductId = model.ProductId, DateCreate = DateTime.Now, EmployeeCreate = User.UserId }; _unitOW.ChanelPriceRepository.Add(data); await _unitOW.SaveChanges(); } #region gia si var user = Mapper.Map <UserCurrent>(User); var product = _unitOW.ProductRepository.FindBy(o => o.id == model.ProductId).FirstOrDefault(); _IOrderBus.UpdatePriceWholesale(product, user, true); #endregion Messaging.messaging = "Đã thay đổi giá thành công!"; } catch { Messaging.isError = true; Messaging.messaging = "Thay đổi giá không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateDone_Order_Inside(int id) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var order = _context.soft_Order.Find(id); if (order == null) { Messaging.isError = true; Messaging.messaging = "Không tìm thấy đơn hàng này."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var objOrder = new soft_Order { Id = id, Status = (int)StatusOrder_Input.Done, DateUpdate = DateTime.Now, EmployeeUpdate = User.UserId }; var modelupdate = Mapper.Map <OrderModel>(order); if (order.Id_From > 0) { UpdateOrderSuppliers(modelupdate, order.Id_From.Value); } _crud.Update(objOrder, o => o.Status, o => o.EmployeeUpdate, o => o.DateUpdate); UpdateStockByBranches(modelupdate); _crud.SaveChanges(); } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Cập nhật đơn hàng nhập không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult GetConfigSys() { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Vui lòng đăng nhập lại!"; } var config = new ConfigModel(); config.User = Mapper.Map <Config_UserModel>(User); config.User.Branches = new List <BranchesModel>(); config.User.Channel = new List <ChannelModel>(); config.User.BranchesId = User.BranchesId; config.User.ChannelId = User.ChannelId; var lstBranches = Mapper.Map <List <BranchesModel> >(_unitOW.BrachesRepository.GetAll().ToList()); var lstchannel = Mapper.Map <List <ChannelModel> >(_unitOW.ChannelRepository.GetAll().ToList()); config.User.Channel = lstchannel; config.User.Branches = lstBranches; var emp = _unitOW.EmployeeRepository.GetAll().ToList(); config.Employee = new List <EmployeeModel>(); foreach (var item in emp) { config.Employee.Add(new EmployeeModel { Id = item.Id, Name = item.Name, Email = item.Email }); } var configMain = _unitOW.ConfigRepository.FindBy(o => o.Type == (int)TypeConfig.Main).FirstOrDefault(); if (configMain != null) { config.Config = Mapper.Map <Config>(configMain); } Messaging.Data = config; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Lấy Cấu hình không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> CreateOrder_Branches(OrderModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.Id_To <= 0) { Messaging.isError = true; Messaging.messaging = "Vui lòng chọn Kho bạn xuất đến."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.Id_To == User.BranchesId) { Messaging.isError = true; Messaging.messaging = "Kho đặt hàng không hơp lệ"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.Detail.Count <= 0) { Messaging.isError = true; Messaging.messaging = "Dữ liệu không hợp lệ, vui lòng kiểm tra lại"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var user = Mapper.Map <UserCurrent>(User); var isError = await _IOrderBus.AddOrder_Branches(model, user); Messaging.isError = !isError; Messaging.messaging = "Đã đặt hàng nội bộ thành công!"; } catch { Messaging.isError = true; Messaging.messaging = "Đặt hàng nội bộ không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult CreateOrder_Suppliers(OrderModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } foreach (var item in model.Detail) { var product = _context.shop_sanpham.Find(item.ProductId); if (product == null) { Messaging.isError = true; Messaging.messaging = "Sản phẩm không tồn tại, vui lòng thử lại."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } } var objOrder = Mapper.Map <soft_Order>(model); objOrder.Status = (int)StatusOrder_Suppliers.Process; objOrder.DateCreate = DateTime.Now; objOrder.EmployeeCreate = User.UserId; objOrder.TypeOrder = (int)TypeOrder.OrderProduct; objOrder.Id_From = User.BranchesId; objOrder.Id_To = null; foreach (var item in objOrder.soft_Order_Child) { item.Status = (int)StatusOrder_Suppliers.Process; } _crud.Add <soft_Order>(objOrder); _crud.SaveChanges(); Messaging.messaging = "Đã tạo phiếu đặt hàng."; } catch { Messaging.isError = true; Messaging.messaging = "Tạo phiếu đặt hàng nhà phân phối không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> CreatOrderSale(OrderModel model, bool isDone) { var Messaging = new RenderMessaging(); try { if (User == null || User.BranchesId <= 0 || User.ChannelId <= 0) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var lstItemCart = new List <Order_DetialModel>(); foreach (var item in model.Detail) { if (item.ProductId > 0) { lstItemCart.Add(item); } } model.Detail = lstItemCart; if (model.Detail == null || model.Detail.Count <= 0) { Messaging.isError = true; Messaging.messaging = "Không có sản phẩm nào trong đơn hàng."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } model.Id_From = User.ChannelId; var user = Mapper.Map <UserCurrent>(User); var order = await _IOrderBus.CreatOrder_Sale(model, isDone, user); Messaging.Data = new { Code = order.Item1.Code + "-" + order.Item1.Id, isPrint = order.Item2 }; Messaging.messaging = "Đã tạo đơn hàng thành công."; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Tạo đơn hàng không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }
public JsonResult CreateProductsSwitch(OrderModel model) { var Messaging = new RenderMessaging(); try { if (User == null) { Messaging.isError = true; Messaging.messaging = "Phiên đăng nhập đã hết hạn."; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } if (model.Detail.Count <= 0) { Messaging.isError = true; Messaging.messaging = "Dữ liệu không hợp lệ, vui lòng kiểm tra lại"; return(Json(Messaging, JsonRequestBehavior.AllowGet)); } var objOrder = Mapper.Map <soft_Order>(model); objOrder.Id_From = User.BranchesId; objOrder.Id_To = User.BranchesId; objOrder.DateCreate = DateTime.Now; objOrder.EmployeeCreate = User.UserId; objOrder.TypeOrder = (int)TypeOrder.Switch; objOrder.Status = (int)StatusOrder_Switch.Done; _crud.Add <soft_Order>(objOrder); UpdateStockByBranches(objOrder); _crud.SaveChanges(); Messaging.messaging = "Đã tạo phiếu điều chỉnh thành công!"; } catch (Exception ex) { Messaging.isError = true; Messaging.messaging = "Tạo phiếu điều chỉnh không thành công!"; } return(Json(Messaging, JsonRequestBehavior.AllowGet)); }