public ActionResult Edit(SupplierViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { var Supplier = SupplierRepository.GetSupplierById(model.Id); AutoMapper.Mapper.Map(model, Supplier); Supplier.ModifiedUserId = WebSecurity.CurrentUserId; Supplier.ModifiedDate = DateTime.Now; Supplier.ProductIdOfSupplier = Request["ProductIdOfSupplier"]; //tạo đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Supplier.Id, model.AttributeValueList); SupplierRepository.UpdateSupplier(Supplier); if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = "True" })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Index")); } return(View(model)); } return(View(model)); }
public ActionResult Create(WarehouseViewModel model) { if (ModelState.IsValid) { var Warehouse = new Domain.Sale.Entities.Warehouse(); AutoMapper.Mapper.Map(model, Warehouse); Warehouse.IsDeleted = false; Warehouse.CreatedUserId = WebSecurity.CurrentUserId; Warehouse.ModifiedUserId = WebSecurity.CurrentUserId; Warehouse.CreatedDate = DateTime.Now; Warehouse.ModifiedDate = DateTime.Now; Warehouse.KeeperId = Request["KeeperId"]; Warehouse.Categories = Request["Categories"]; Warehouse.IsSale = model.IsSale; Warehouse.BranchId = Helpers.Common.CurrentUser.BranchId; //tạo đặc tính động cho kho hàng nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Warehouse.Id, model.AttributeValueList); WarehouseRepository.InsertWarehouse(Warehouse); //if(string.IsNullOrEmpty(Request["IsPopup"]) == false) //{ // ViewBag.closePopup = "close and append to page parent"; // model.Id = Warehouse.Id; // return View(model); //} TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create(SupplierViewModel model) { if (ModelState.IsValid) { var Supplier = new Domain.Sale.Entities.Supplier(); AutoMapper.Mapper.Map(model, Supplier); Supplier.IsDeleted = false; Supplier.CreatedUserId = WebSecurity.CurrentUserId; Supplier.ModifiedUserId = WebSecurity.CurrentUserId; Supplier.CreatedDate = DateTime.Now; Supplier.ModifiedDate = DateTime.Now; Supplier.ProductIdOfSupplier = string.IsNullOrEmpty(Request["ProductIdOfSupplier"]) == true ? "" : Request["ProductIdOfSupplier"]; SupplierRepository.InsertSupplier(Supplier); Supplier.Code = Erp.BackOffice.Helpers.Common.GetOrderNo("Supplier"); SupplierRepository.UpdateSupplier(Supplier); Erp.BackOffice.Helpers.Common.SetOrderNo("Supplier"); //tạo đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Supplier.Id, model.AttributeValueList); if (Request["IsPopup"] == "true") { ViewBag.closePopup = "close and append to page parent"; model.Id = Supplier.Id; model.Name = Supplier.Name; return(View(model)); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Edit(WarehouseViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { using (var scope = new TransactionScope(TransactionScopeOption.Required)) { try { var ListUserId = Request["ListUserId"]; var Warehouse = WarehouseRepository.GetWarehouseById(model.Id); AutoMapper.Mapper.Map(model, Warehouse); Warehouse.KeeperId = ListUserId; Warehouse.Categories = Request["Categories"]; Warehouse.ModifiedUserId = WebSecurity.CurrentUserId; Warehouse.ModifiedDate = DateTime.Now; Warehouse.IsSale = model.IsSale; //tạo đặc tính động cho kho hàng nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Warehouse.Id, model.AttributeValueList); WarehouseRepository.UpdateWarehouse(Warehouse); scope.Complete(); if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Index")); } catch (DbUpdateException) { return(Content("Fail")); } } } return(View(model)); } return(View(model)); //if (Request.UrlReferrer != null) // return Redirect(Request.UrlReferrer.AbsoluteUri); //return RedirectToAction("Index"); }
public ActionResult Edit(ProductViewModel model) { //foreach (var modelKey in ModelState.Keys) //{ // if (modelKey == "PriceInbound" || modelKey == "PriceOutbound") // { // var index = ModelState.Keys.ToList().IndexOf(modelKey); // ModelState.Values.ElementAt(index).Errors.Clear(); // } //} if (ModelState.IsValid) { var Product = productRepository.GetProductById(model.Id); AutoMapper.Mapper.Map(model, Product); Product.ModifiedUserId = WebSecurity.CurrentUserId; Product.ModifiedDate = DateTime.Now; if (model.PriceInbound == null) { Product.PriceInbound = 0; } var path = Helpers.Common.GetSetting("product-image-folder"); var filepath = System.Web.HttpContext.Current.Server.MapPath("~" + path); if (Request.Files["file-image"] != null) { var file = Request.Files["file-image"]; if (file.ContentLength > 0) { FileInfo fi = new FileInfo(Server.MapPath("~" + path) + Product.Image_Name); if (fi.Exists) { fi.Delete(); } string image_name = "product_" + Helpers.Common.ChuyenThanhKhongDau(Regex.Replace(Product.Code, @"\s+", "_")) + "." + file.FileName.Split('.').Last(); bool isExists = System.IO.Directory.Exists(filepath); if (!isExists) { System.IO.Directory.CreateDirectory(filepath); } file.SaveAs(filepath + image_name); Product.Image_Name = image_name; } } //tạo hoặc cập nhật đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Product.Id, model.AttributeValueList); productRepository.UpdateProduct(Product); if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Index")); } string errors = string.Empty; foreach (var modalState in ModelState.Values) { errors += modalState.Value + ": "; foreach (var error in modalState.Errors) { errors += error.ErrorMessage; } } ViewBag.errors = errors; return(View(model)); //if (Request.UrlReferrer != null) // return Redirect(Request.UrlReferrer.AbsoluteUri); //return RedirectToAction("Index"); }
//[ValidateAntiForgeryToken] public ActionResult Create(ProductViewModel model) { if (ModelState.IsValid) { var Product = new Domain.Sale.Entities.Product(); AutoMapper.Mapper.Map(model, Product); Product.IsDeleted = false; Product.CreatedUserId = WebSecurity.CurrentUserId; Product.ModifiedUserId = WebSecurity.CurrentUserId; Product.CreatedDate = DateTime.Now; Product.ModifiedDate = DateTime.Now; if (model.PriceInbound == null) { Product.PriceInbound = 0; } Product.Code = Product.Code.Trim(); var path = System.Web.HttpContext.Current.Server.MapPath("~" + Helpers.Common.GetSetting("product-image-folder")); if (Request.Files["file-image"] != null) { var file = Request.Files["file-image"]; if (file.ContentLength > 0) { string image_name = "product_" + Helpers.Common.ChuyenThanhKhongDau(Regex.Replace(Product.Code, @"\s+", "_")) + "." + file.FileName.Split('.').Last(); bool isExists = System.IO.Directory.Exists(path); if (!isExists) { System.IO.Directory.CreateDirectory(path); } file.SaveAs(path + image_name); Product.Image_Name = image_name; } } productRepository.InsertProduct(Product); //tạo đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Product.Id, model.AttributeValueList); if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; return(RedirectToAction("Index")); } string errors = string.Empty; foreach (var modalState in ModelState.Values) { errors += modalState.Value + ": "; foreach (var error in modalState.Errors) { errors += error.ErrorMessage; } } ViewBag.errors = errors; return(View(model)); }
public ActionResult Edit(ServiceViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { var Service = ServiceRepository.GetProductById(model.Id); AutoMapper.Mapper.Map(model, Service); Service.ModifiedUserId = WebSecurity.CurrentUserId; Service.ModifiedDate = DateTime.Now; Service.Type = "service"; var path = Helpers.Common.GetSetting("service-image-folder"); var filepath = System.Web.HttpContext.Current.Server.MapPath("~" + path); if (Request.Files["file-image"] != null) { var file = Request.Files["file-image"]; if (file.ContentLength > 0) { FileInfo fi = new FileInfo(Server.MapPath("~" + path) + Service.Image_Name); if (fi.Exists) { fi.Delete(); } string image_name = "service_" + Helpers.Common.ChuyenThanhKhongDau(Regex.Replace(Service.Name, @"\s+", "_")) + "." + file.FileName.Split('.').Last(); bool isExists = System.IO.Directory.Exists(filepath); if (!isExists) { System.IO.Directory.CreateDirectory(filepath); } file.SaveAs(filepath + image_name); Service.Image_Name = image_name; } } if (model.IsCombo == true) { var q = serviceComboRepository.GetAllServiceCombo().Where(x => x.ComboId == Service.Id).ToList(); ServiceRepository.DeleteServiceCombo(q); if (model.DetailList != null) { foreach (var item in model.DetailList) { var serviceCombo = new ServiceCombo(); serviceCombo.IsDeleted = false; serviceCombo.CreatedUserId = WebSecurity.CurrentUserId; serviceCombo.ModifiedUserId = WebSecurity.CurrentUserId; serviceCombo.AssignedUserId = WebSecurity.CurrentUserId; serviceCombo.CreatedDate = DateTime.Now; serviceCombo.ModifiedDate = DateTime.Now; serviceCombo.ComboId = Service.Id; serviceCombo.Quantity = item.Quantity; serviceCombo.ServiceId = item.ServiceId; serviceComboRepository.InsertServiceCombo(serviceCombo); } } } else { var q = serviceReminderGroupRepository.GetAllServiceReminderGroup().Where(x => x.ServiceId == Service.Id).ToList(); serviceReminderGroupRepository.DeleteServiceReminderGroupList(q); if (model.ReminderList != null) { foreach (var item in model.ReminderList) { var reminder = new ServiceReminderGroup(); reminder.IsDeleted = false; reminder.CreatedUserId = WebSecurity.CurrentUserId; reminder.ModifiedUserId = WebSecurity.CurrentUserId; reminder.AssignedUserId = WebSecurity.CurrentUserId; reminder.CreatedDate = DateTime.Now; reminder.ModifiedDate = DateTime.Now; reminder.ServiceId = Service.Id; reminder.ServiceReminderId = item.ServiceReminderId; serviceReminderGroupRepository.InsertServiceReminderGroup(reminder); } } } //tạo hoặc cập nhật đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Service.Id, model.AttributeValueList); ServiceRepository.UpdateService(Service); if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Index")); } return(View(model)); } return(View(model)); //if (Request.UrlReferrer != null) // return Redirect(Request.UrlReferrer.AbsoluteUri); //return RedirectToAction("Index"); }
public ActionResult Create(ServiceViewModel model) { if (ModelState.IsValid) { var Service = new Product(); Service.IsDeleted = false; Service.CreatedUserId = WebSecurity.CurrentUserId; Service.ModifiedUserId = WebSecurity.CurrentUserId; Service.CreatedDate = DateTime.Now; Service.ModifiedDate = DateTime.Now; Service.Barcode = model.Barcode; Service.CategoryCode = model.CategoryCode; Service.Description = model.Description; Service.IsCombo = model.IsCombo; Service.Name = model.Name; Service.PriceOutbound = model.PriceOutbound; Service.Type = "service"; Service.Unit = model.Unit; Service.Code = model.Code.Trim(); var path = System.Web.HttpContext.Current.Server.MapPath("~" + Helpers.Common.GetSetting("service-image-folder")); if (Request.Files["file-image"] != null) { var file = Request.Files["file-image"]; if (file.ContentLength > 0) { string image_name = "service_" + Helpers.Common.ChuyenThanhKhongDau(Regex.Replace(Service.Name, @"\s+", "_")) + "." + file.FileName.Split('.').Last(); bool isExists = System.IO.Directory.Exists(path); if (!isExists) { System.IO.Directory.CreateDirectory(path); } file.SaveAs(path + image_name); Service.Image_Name = image_name; } } ServiceRepository.InsertService(Service); //tạo đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Service.Id, model.AttributeValueList); if (model.IsCombo == true) { foreach (var item in model.DetailList) { var serviceCombo = new ServiceCombo(); serviceCombo.IsDeleted = false; serviceCombo.CreatedUserId = WebSecurity.CurrentUserId; serviceCombo.ModifiedUserId = WebSecurity.CurrentUserId; serviceCombo.AssignedUserId = WebSecurity.CurrentUserId; serviceCombo.CreatedDate = DateTime.Now; serviceCombo.ModifiedDate = DateTime.Now; serviceCombo.ComboId = Service.Id; serviceCombo.Quantity = item.Quantity; serviceCombo.ServiceId = item.ServiceId; serviceComboRepository.InsertServiceCombo(serviceCombo); } } else { foreach (var item in model.ReminderList) { var reminder = new ServiceReminderGroup(); reminder.IsDeleted = false; reminder.CreatedUserId = WebSecurity.CurrentUserId; reminder.ModifiedUserId = WebSecurity.CurrentUserId; reminder.AssignedUserId = WebSecurity.CurrentUserId; reminder.CreatedDate = DateTime.Now; reminder.ModifiedDate = DateTime.Now; reminder.ServiceId = Service.Id; reminder.ServiceReminderId = item.ServiceReminderId; serviceReminderGroupRepository.InsertServiceReminderGroup(reminder); } } if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Edit(ProductViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { var Product = ProductRepository.GetProductById(model.Id); var check_Code = ProductRepository.GetAllProductByType("product").Where(x => x.Code != Product.Code).Any(x => x.Code == model.Code); if (check_Code) { ViewBag.FailedMessage = "Mã " + model.Code + " bị trùng!"; return(View(model)); } // Ghi PriceLog nếu thay đổi giá nhập và giá xuất if (Product.PriceInbound != model.PriceInbound && Product.PriceOutbound != model.PriceOutbound) { CreateProdeLog(Product); } AutoMapper.Mapper.Map(model, Product); Product.ModifiedUserId = WebSecurity.CurrentUserId; Product.ModifiedDate = DateTime.Now; Product.Point = 1; if (model.PriceInbound == null) { Product.PriceInbound = 0; } if (Request.Files["file-image"] != null) { var file = Request.Files["file-image"]; if (file.ContentLength > 0) { FileInfo fi = new FileInfo(Server.MapPath("~/files/product/") + Product.Image_Name); if (fi.Exists) { fi.Delete(); } string image_name = "product_" + Helpers.Common.ChuyenThanhKhongDau(Regex.Replace(Product.Code, @"\s+", "_")) + "." + file.FileName.Split('.').Last(); file.SaveAs(Server.MapPath("~/files/product/") + image_name); Product.Image_Name = image_name; } } //tạo hoặc cập nhật đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Product.Id, model.AttributeValueList); ProductRepository.UpdateProduct(Product); if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Index")); } return(View(model)); } string errors = string.Empty; foreach (var modalState in ModelState.Values) { errors += modalState.Value + ": "; foreach (var error in modalState.Errors) { errors += error.ErrorMessage; } } ViewBag.errors = errors; return(View(model)); //if (Request.UrlReferrer != null) // return Redirect(Request.UrlReferrer.AbsoluteUri); //return RedirectToAction("Index"); }
public ActionResult Edit(ProductViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { var Product = ProductRepository.GetProductById(model.Id); AutoMapper.Mapper.Map(model, Product); Product.ModifiedUserId = WebSecurity.CurrentUserId; Product.ModifiedDate = DateTime.Now; if (model.PriceInbound == null) { Product.PriceInbound = 0; } if (model.IsServicePackage == true && model.ServicesInPackage != null && model.ServicesInPackage.Where(x => x.ProductId > 0).Count() > 0) { XElement xmlElements = new XElement("Services", model.ServicesInPackage.Select(s => new XElement("Service", new XAttribute("ProductId", s.ProductId), new XAttribute("Quantity", s.Quantity)) ) ); string xml = xmlElements.ToString(); Product.ServicesChild = xml; } else { Product.ServicesChild = ""; } if (Request.Files["file-image"] != null) { var file = Request.Files["file-image"]; if (file.ContentLength > 0) { FileInfo fi = new FileInfo(Server.MapPath("~/files/product/") + Product.Image_Name); if (fi.Exists) { fi.Delete(); } string image_name = "service_" + Helpers.Common.ChuyenThanhKhongDau(Regex.Replace(Product.Name, @"\s+", "_")) + "." + file.FileName.Split('.').Last(); file.SaveAs(Server.MapPath("~/files/product/") + image_name); Product.Image_Name = image_name; } } //tạo hoặc cập nhật đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Product.Id, model.AttributeValueList); ProductRepository.UpdateProduct(Product); if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Index")); } return(View(model)); } string errors = string.Empty; foreach (var modalState in ModelState.Values) { errors += modalState.Value + ": "; foreach (var error in modalState.Errors) { errors += error.ErrorMessage; } } ViewBag.errors = errors; return(View(model)); //if (Request.UrlReferrer != null) // return Redirect(Request.UrlReferrer.AbsoluteUri); //return RedirectToAction("Index"); }
//[ValidateAntiForgeryToken] public ActionResult Create(ProductViewModel model) { if (ModelState.IsValid) { var Product = new Domain.Sale.Entities.Product(); AutoMapper.Mapper.Map(model, Product); Product.IsDeleted = false; Product.CreatedUserId = WebSecurity.CurrentUserId; Product.ModifiedUserId = WebSecurity.CurrentUserId; Product.CreatedDate = DateTime.Now; Product.ModifiedDate = DateTime.Now; if (model.PriceInbound == null) { Product.PriceInbound = 0; } if (model.IsServicePackage == true && model.ServicesInPackage != null && model.ServicesInPackage.Where(x => x.ProductId > 0).Count() > 0) { XElement xmlElements = new XElement("Services", model.ServicesInPackage.Select(s => new XElement("Service", new XAttribute("ProductId", s.ProductId), new XAttribute("Quantity", s.Quantity)) ) ); string xml = xmlElements.ToString(); Product.ServicesChild = xml; } if (Request.Files["file-image"] != null) { var file = Request.Files["file-image"]; if (file.ContentLength > 0) { string image_name = "service_" + Helpers.Common.ChuyenThanhKhongDau(Regex.Replace(Product.Name, @"\s+", "_")) + "." + file.FileName.Split('.').Last(); file.SaveAs(Server.MapPath("~/files/product/") + image_name); Product.Image_Name = image_name; } } ProductRepository.InsertProduct(Product); //tạo đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị ObjectAttributeController.CreateOrUpdateForObject(Product.Id, model.AttributeValueList); if (string.IsNullOrEmpty(Request["IsPopup"]) == false) { return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] })); } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; return(RedirectToAction("Index")); } string errors = string.Empty; foreach (var modalState in ModelState.Values) { errors += modalState.Value + ": "; foreach (var error in modalState.Errors) { errors += error.ErrorMessage; } } ViewBag.errors = errors; ViewBag.service = ProductRepository.GetAllProduct().Where(x => x.IsServicePackage != true && x.Type == "service").AsEnumerable().Select(item => new SelectListItem { Text = item.Name, Value = item.Id.ToString() }); return(View(model)); }