Example #1
0
        public virtual IActionResult Edit(int id, UpdateMaterialGroupModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(XrmsPermissionProvider.ManageMaterialGroups))
            {
                return(AccessDeniedView());
            }

            var materialGroup = _materialGroupService.GetMaterialGroupById(id);

            if (materialGroup == null || materialGroup.Deleted)
            {
                //No group found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var prevPictureId = materialGroup.PictureId;
                materialGroup = model.ToEntity(materialGroup);
                materialGroup.UpdatedOnUtc = DateTime.UtcNow;
                _materialGroupService.UpdateMaterialGroup(materialGroup);

                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != materialGroup.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }

                //activity log
                _customerActivityService.InsertActivity("EditMaterialGroup", _localizationService.GetResource("Xrms.ActivityLog.EditMaterialGroup"), materialGroup);

                SuccessNotification(_localizationService.GetResource("Xrms.Admin.Catalog.MaterialGroups.Notifications.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = materialGroup.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            var viewModel = new MaterialGroupDetailsPageViewModel();

            model.ToDetailsViewModel(viewModel);
            //viewModel.MaterialGroupInfo = model;

            // prepare parent groups
            PrepareAvailableMaterialGroups(viewModel);

            return(View("~/Plugins/Xrms/Areas/Admin/Views/MaterialGroup/Edit.cshtml", viewModel));
        }
Example #2
0
 public static MaterialGroup ToEntity(this UpdateMaterialGroupModel model, MaterialGroup entity)
 {
     return(model.MapTo(entity));
 }
Example #3
0
 public static MaterialGroupDetailsPageViewModel ToDetailsViewModel(this UpdateMaterialGroupModel model, MaterialGroupDetailsPageViewModel viewModel)
 {
     return(model.MapTo(viewModel));
 }
Example #4
0
 public static MaterialGroup ToEntity(this UpdateMaterialGroupModel model)
 {
     return(model.MapTo <UpdateMaterialGroupModel, MaterialGroup>());
 }