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

        public ActionResult Create(int id)//ProductType Id
        {
            Dimension1ViewModel vm = new Dimension1ViewModel();

            vm.IsActive      = true;
            vm.ProductTypeId = id;
            ViewBag.id       = id;
            ViewBag.Name     = new ProductTypeService(_unitOfWork).Find(id).ProductTypeName;


            var settings = new ProductTypeSettingsService(_unitOfWork).GetProductTypeSettingsForDocument(id);

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("Create", "ProductTypeSettings", new { id = id }).Warning("Please create Product Type Settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }
            vm.ProductTypeSettings = Mapper.Map <ProductTypeSettings, ProductTypeSettingsViewModel>(settings);


            return(View("Create", vm));
        }
コード例 #2
0
        // GET: /ProductMaster/Edit/5

        public ActionResult Edit(int id)
        {
            Dimension1          D1 = _Dimension1Service.Find(id);
            Dimension1ViewModel pt = Mapper.Map <Dimension1, Dimension1ViewModel>(D1);

            if (pt == null)
            {
                return(HttpNotFound());
            }
            ViewBag.id   = pt.ProductTypeId;
            ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;


            if (pt.ProductTypeId != null)
            {
                var settings = new ProductTypeSettingsService(_unitOfWork).GetProductTypeSettingsForDocument((int)pt.ProductTypeId);

                if (settings == null && UserRoles.Contains("SysAdmin"))
                {
                    return(RedirectToAction("Create", "ProductTypeSettings", new { id = id }).Warning("Please create Product Type Settings"));
                }
                else if (settings == null && !UserRoles.Contains("SysAdmin"))
                {
                    return(View("~/Views/Shared/InValidSettings.cshtml"));
                }
                pt.ProductTypeSettings = Mapper.Map <ProductTypeSettings, ProductTypeSettingsViewModel>(settings);
            }

            return(View("Create", pt));
        }
コード例 #3
0
        public ActionResult Post(Dimension1ViewModel vm)
        {
            Dimension1 pt = Mapper.Map <Dimension1ViewModel, Dimension1>(vm);

            if (ModelState.IsValid)
            {
                if (vm.Dimension1Id <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _Dimension1Service.Create(pt);


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = vm.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId ?? 0).ProductTypeName;
                        return(View("Create", vm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Dimension1).DocumentTypeId,
                        DocId        = pt.Dimension1Id,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

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

                    Dimension1 temp  = _Dimension1Service.Find(pt.Dimension1Id);
                    Dimension1 ExRec = Mapper.Map <Dimension1>(temp);

                    temp.Dimension1Name = pt.Dimension1Name;
                    temp.IsActive       = pt.IsActive;
                    temp.Description    = pt.Description;
                    temp.ModifiedDate   = DateTime.Now;
                    temp.ModifiedBy     = User.Identity.Name;
                    temp.ObjectState    = Model.ObjectState.Modified;
                    _Dimension1Service.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);
                        ViewBag.id   = pt.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Dimension1).DocumentTypeId,
                        DocId           = temp.Dimension1Id,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    ViewBag.id   = pt.ProductTypeId;
                    ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;
                    return(RedirectToAction("Index", new { id = pt.ProductTypeId }).Success("Data saved successfully"));
                }
            }
            ViewBag.id   = vm.ProductTypeId;
            ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId ?? 0).ProductTypeName;
            return(View("Create", vm));
        }