Rebel.Cms.Web.Editors.DataTypeEditorController.ProcessSubmit C# (CSharp) Method

ProcessSubmit() protected method

Processes the submit for insert/update
protected ProcessSubmit ( DataTypeEditorModel model, AttributeType entity ) : System.Web.Mvc.ActionResult
model Rebel.Cms.Web.Model.BackOffice.Editors.DataTypeEditorModel
entity AttributeType
return System.Web.Mvc.ActionResult
        protected ActionResult ProcessSubmit(DataTypeEditorModel model, AttributeType entity)
        {
            Mandate.ParameterNotNull(model, "model");

            model.BindModel(this);

            model.Id = entity != null ? entity.Id : HiveId.Empty;

            if (!ModelState.IsValid)
            {
                AddValidationErrorsNotification();
                EnsurePropEditorListViewBagData();
                return View(model);
            }

            //persist the data
            using (var uow = BackOfficeRequestContext.Application.Hive.OpenWriter<IContentStore>())
            {
                if (entity == null)
                {
                    //map to new entity
                    entity = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map<DataTypeEditorModel, AttributeType>(model);
                }
                else
                {
                    //map back to existing entity from updated model
                    BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map(model, entity);    
                }

                uow.Repositories.Schemas.AddOrUpdate(entity);
                uow.Complete();

                Notifications.Add(new NotificationMessage(
                        "DataType.Save.Message".Localize(this),
                        "DataType.Save.Title".Localize(this),
                        NotificationType.Success));
                
                //add path for entity for SupportsPathGeneration (tree syncing) to work,
                //we need to manually contruct the path because of the static root node id.
                GeneratePathsForCurrentEntity(new EntityPathCollection(entity.Id, new[]{ new EntityPath(new[]
                    {
                        new HiveId(FixedSchemaTypes.SystemRoot, null, new HiveIdValue(new Guid(CorePluginConstants.DataTypeTreeRootNodeId))), 
                        entity.Id
                    })
                }));
                
                return RedirectToAction("Edit", new { id = entity.Id });
            }
            
        }