public virtual IActionResult Edit(int id, MaterialGroupModel 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.Name);

                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;

            //If we got this far, something failed, redisplay form
            // prepare parent groups
            PrepareAvailableMaterialGroups(viewModel);

            return(View("~/Plugins/Xrms.MaterialAdmin/Areas/Admin/Views/MaterialGroup/Edit.cshtml", viewModel));
        }
        public virtual IActionResult Create(MaterialGroupModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(XrmsPermissionProvider.ManageMaterialGroups))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var group = model.ToEntity();
                group.CreatedOnUtc = DateTime.UtcNow;
                group.UpdatedOnUtc = DateTime.UtcNow;
                _materialGroupService.InsertMaterialGroup(group);

                //activity log
                _customerActivityService.InsertActivity("AddNewMaterialGroup", _localizationService.GetResource("Xrms.ActivityLog.AddNewMaterialGroup"), group.Name);

                SuccessNotification(_localizationService.GetResource("Xrms.Admin.Catalog.MaterialGroups.Notifications.Created"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = group.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.MaterialAdmin/Areas/Admin/Views/MaterialGroup/Create.cshtml", viewModel));
        }