コード例 #1
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 model = new EntityCreateModel
            {
                Entity           = entity,
                PropertiesGroups = _entityService.PrepareGroups(entity.CreateRecord(collection, Request.Files))
            };

            return(View(model));
        }
コード例 #2
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));
        }
コード例 #3
0
        public virtual ActionResult Create(string entityName)
        {
            var entity = _admin.GetEntity(entityName);

            if (entity == null)
            {
                return(RedirectToAction("NotFound", new { entityName }));
            }

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

            return(View(model));
        }
コード例 #4
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));
        }
コード例 #5
0
        public virtual IActionResult CreateEntity([FromBody] EntityCreateModel body, [FromHeader][Required()] string acceptLanguage)
        {
            //TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(201, default(EntityViewModel));

            //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(400, default(ErrorViewModel));

            //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(404, default(ErrorViewModel));

            //TODO: Uncomment the next line to return response 409 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(409, default(ErrorViewModel));
            string exampleJson = null;

            exampleJson = "{\r\n  \"relationIdField\" : 1,\r\n  \"doubleField\" : 10,\r\n  \"exampleType\" : \"type1\",\r\n  \"dictionaryField\" : \"\",\r\n  \"integerField\" : 1,\r\n  \"exampleStatus\" : true,\r\n  \"dateField\" : \"2000-01-23T04:56:07.000+00:00\",\r\n  \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\r\n  \"stringField\" : \"somestring\"\r\n}";

            var example = exampleJson != null
                        ? JsonConvert.DeserializeObject <EntityViewModel>(exampleJson)
                        : default(EntityViewModel);            //TODO: Change the data returned

            return(new ObjectResult(example));
        }