コード例 #1
0
        // GET: /ProductCategorySettingMaster/Create

        public ActionResult Create(int id)//ProductCategoryId
        {
            if (!UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }
            var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            var SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            var settings   = new ProductCategorySettingsService(_unitOfWork).GetProductCategorySettings(id);

            if (settings == null)
            {
                ProductCategorySettingsViewModel vm = new ProductCategorySettingsViewModel();
                vm.ProductCategoryId = id;
                PrepareViewBag(vm);
                return(View("Create", vm));
            }
            else
            {
                ProductCategorySettingsViewModel temp = AutoMapper.Mapper.Map <ProductCategorySettings, ProductCategorySettingsViewModel>(settings);
                PrepareViewBag(temp);
                return(View("Create", temp));
            }
        }
コード例 #2
0
        public ActionResult Post(ProductCategorySettingsViewModel vm)
        {
            ProductCategorySettings pt = AutoMapper.Mapper.Map <ProductCategorySettingsViewModel, ProductCategorySettings>(vm);


            if (ModelState.IsValid)
            {
                ProductCategory ProductCategory = new ProductCategoryService(_unitOfWork).Find(vm.ProductCategoryId);
                if (vm.ProductCategorySettingsId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductCategorySettingsService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag(vm);
                        return(View("Create", vm));
                    }

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocId        = pt.ProductCategorySettingsId,
                        DocTypeId    = DocTypeId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



                    return(RedirectToAction("Index", "ProductCategory", new { id = ProductCategory.ProductTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductCategorySettings temp = _ProductCategorySettingsService.Find(pt.ProductCategorySettingsId);

                    ProductCategorySettings ExRec = Mapper.Map <ProductCategorySettings>(temp);

                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _ProductCategorySettingsService.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);
                        PrepareViewBag(vm);
                        return(View("Create", pt));
                    }

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocId           = temp.ProductCategorySettingsId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        DocTypeId       = DocTypeId,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "ProductCategory", new { id = ProductCategory.ProductTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(vm);
            return(View("Create", vm));
        }
コード例 #3
0
 private void PrepareViewBag(ProductCategorySettingsViewModel s)
 {
     int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"];
 }