// GET: /ProductBuyerMaster/Create public ActionResult Create(int ProductId) { int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; ProductBuyerSettings Settings = new ProductBuyerSettingsService(_unitOfWork).GetProductBuyerSettings(DivisionId, SiteId); List <string> UserRoles = new List <string>(); UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"]; if (Settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "ProductBuyerSettings").Warning("Please create Product Buyer settings")); } else if (Settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } ProductBuyerViewModel vm = new ProductBuyerViewModel(); Product temp = new ProductService(_unitOfWork).Find(ProductId); ViewBag.Name = temp.ProductName; ViewBag.Id = ProductId; vm.ProductId = ProductId; vm.ProductBuyerSettings = Mapper.Map <ProductBuyerSettings, ProductBuyerSettingsViewModel>(Settings);; return(View("Create", vm)); }
// GET: /ProductBuyerMaster/Create public ActionResult Create(int ProductId) { ProductBuyerViewModel vm = new ProductBuyerViewModel(); Product temp = new ProductService(_unitOfWork).Find(ProductId); ViewBag.Name = temp.ProductName; ViewBag.Id = ProductId; vm.ProductId = ProductId; return(View("Create", vm)); }
// GET: /ProductMaster/Edit/5 public ActionResult Edit(int id)//ProductBuyerId { ProductBuyer pt = _ProductBuyerService.Find(id); ProductBuyerViewModel vm = AutoMapper.Mapper.Map <ProductBuyer, ProductBuyerViewModel>(pt); if (pt == null) { return(HttpNotFound()); } Product temp = new ProductService(_unitOfWork).Find(pt.ProductId); ViewBag.Name = temp.ProductName; ViewBag.Id = pt.ProductId; return(View("Create", vm)); }
public ActionResult DeleteProductBuyerConfirmed(ProductBuyerViewModel vm) { if (ModelState.IsValid) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); var temp = new ProductBuyerService(_unitOfWork).Find(vm.ProductBuyerId); LogList.Add(new LogTypeViewModel { ExObj = temp, }); new ProductBuyerService(_unitOfWork).Delete(vm.ProductBuyerId); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(PartialView("_Create", vm)); } //Logging Activity LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId, DocId = vm.ProductBuyerId, ActivityType = (int)ActivityTypeContants.Deleted, xEModifications = Modifications, })); return(Json(new { success = true })); } return(PartialView("_Create", vm)); }
public ActionResult Post(ProductBuyerViewModel vm) { ProductBuyer pt = AutoMapper.Mapper.Map <ProductBuyerViewModel, ProductBuyer>(vm); if (ModelState.IsValid) { if (vm.ProductBuyerId <= 0) { pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; _ProductBuyerService.Create(pt); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId, DocId = pt.ProductBuyerId, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("Create", new { ProductId = pt.ProductId }).Success("Data saved successfully")); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); ProductBuyer temp = _ProductBuyerService.Find(pt.ProductBuyerId); ProductBuyer ExRec = new ProductBuyer(); ExRec = Mapper.Map <ProductBuyer>(temp); temp.BuyerId = pt.BuyerId; temp.BuyerSku = pt.BuyerSku; temp.BuyerProductCode = pt.BuyerProductCode; temp.BuyerSpecification = pt.BuyerSpecification; temp.BuyerSpecification1 = pt.BuyerSpecification1; temp.BuyerSpecification2 = pt.BuyerSpecification2; temp.BuyerSpecification3 = pt.BuyerSpecification3; temp.BuyerSpecification4 = pt.BuyerSpecification4; temp.BuyerSpecification5 = pt.BuyerSpecification5; temp.BuyerSpecification6 = pt.BuyerSpecification6; temp.BuyerUpcCode = pt.BuyerUpcCode; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; _ProductBuyerService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", pt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId, DocId = temp.ProductBuyerId, ActivityType = (int)ActivityTypeContants.Modified, xEModifications = Modifications, })); return(RedirectToAction("Index", new { id = vm.ProductId }).Success("Data saved successfully")); } } return(View("Create", vm)); }