Ejemplo n.º 1
0
        public virtual ActionResult Create(string entityName)
        {
            var entity = _admin.GetEntity(entityName);
            if (entity == null)
            {
                return RedirectToAction("NotFound", new { entityName });
            }

            var entityRecord = EntityRecord.CreateEmpty(entity);
            var model = new EntityCreateModel
            {
                Entity = entity,
                PropertiesGroups = _entityService.PrepareGroups(entityRecord)
            };

            return View(model);
        }
Ejemplo n.º 2
0
        public virtual ActionResult Create(string entityName)
        {
            ViewBag.IsAjaxRequest = HttpContext.Request.IsAjaxRequest();

            var entity = AdminInitialise.EntitiesTypes
                .FirstOrDefault(x => x.Name == entityName);
            if (entity == null)
            {
                throw new NoNullAllowedException("entity is null");
            }

            entity.ClearPropertiesValues();

            var model = new EntityCreateModel
            {
                Entity = entity,
                PropertiesGroups = _entityService.PrepareGroups(entity)
            };

            return View(model);
        }
Ejemplo n.º 3
0
        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 entityRecord = new EntityRecord(entity);
            entityRecord.Fill(collection, Request.Files);

            var model = new EntityCreateModel
            {
                Entity = entity,
                PropertiesGroups = _entityService.PrepareGroups(entityRecord)
            };

            return View(model);
        }
Ejemplo n.º 4
0
        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);
        }