public ActionResult Create(string entityName, FormCollection collection) { var entity = _admin.GetEntity(entityName); if (entity == null) { return(RedirectToAction("NotFound", new { entityName })); } try { var savedId = _entityService.Create(entity, collection, Request.Files); if (savedId != null) { _notificator.Success(IlaroAdminResources.AddSuccess, entity.Verbose.Singular); return(SaveOrUpdateSucceed(entityName, savedId)); } } catch (Exception ex) { _log.Error(ex); _notificator.Error(ex.Message); } var model = new EntityCreateModel { Entity = entity, PropertiesGroups = _entityService.PrepareGroups(entity.CreateRecord(collection, Request.Files)) }; return(View(model)); }
public ActionResult Create(string entityName, FormCollection collection) { ViewBag.IsAjaxRequest = HttpContext.Request.IsAjaxRequest(); var entity = AdminInitialise.EntitiesTypes .FirstOrDefault(x => x.Name == entityName); if (entity == null) { throw new NoNullAllowedException("entity is null"); } entity.Fill(collection, Request.Files); if (_validator.Validate(entity)) { try { var savedId = _entityService.Create(entity); if (savedId != null) { _notificator.Success(IlaroAdminResources.AddSuccess, entity.Verbose.Singular); if (Request["ContinueEdit"] != null) { return(RedirectToAction( "Edit", new { entityName, key = entity.Key.Value.ToObject(savedId) })); } if (Request["AddNext"] != null) { return(RedirectToAction("Create", new { entityName })); } return(RedirectToAction("Index", "Entities", new { entityName })); } _notificator.Error(IlaroAdminResources.UncaughtError); } catch (Exception ex) { var message = ex.Message; if (ex.InnerException != null) { message += "<br />" + ex.InnerException.Message; } _notificator.Error(message); } } var model = new EntityCreateModel { Entity = entity, PropertiesGroups = _entityService.PrepareGroups(entity) }; return(View(model)); }