Ejemplo n.º 1
0
        public ActionResult Edit(FilterModel model)
        {
            var filter = _filterRepository.GetById(model.Id);

            if (ModelState.IsValid)
            {
                if (model.ControlType == FieldControlType.DropDownList ||
                    model.ControlType == FieldControlType.MultiSelectList)
                {
                    if (model.DataSource != FieldDataSource.CSV)
                    {
                        model.CsvTextList  = null;
                        model.CsvValueList = null;
                    }
                    if (model.DataSource != FieldDataSource.DB)
                    {
                        model.DbTable       = null;
                        model.DbTextColumn  = null;
                        model.DbValueColumn = null;
                    }
                    if (model.DataSource != FieldDataSource.SQL)
                    {
                        model.SqlQuery      = null;
                        model.SqlTextField  = null;
                        model.SqlValueField = null;
                    }
                    if (model.DataSource != FieldDataSource.MVC)
                    {
                        model.MvcController   = null;
                        model.MvcAction       = null;
                        model.AdditionalField = null;
                        model.AdditionalValue = null;
                    }
                }

                if (model.ControlType != FieldControlType.Lookup)
                {
                    model.LookupType       = null;
                    model.LookupTextField  = null;
                    model.LookupValueField = null;
                }

                filter = model.ToEntity(filter);
                //always set IsNew to false when saving
                filter.IsNew    = false;
                filter.AutoBind = true;
                _filterRepository.Update(filter);

                //commit all changes
                this._dbContext.SaveChanges();

                //notification
                SuccessNotification(_localizationService.GetResource("Record.Saved"));
                return(new NullJsonResult());
            }
            else
            {
                return(Json(new { Errors = ModelState.SerializeErrors() }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] FilterModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                throw new ApiException("Model error encountered", HttpStatusCode.BadRequest, ModelState);
            }

            var result = await service.Create(model.ToEntity(this.User.GetUserId()));

            return(Created(Url.Link(RouteConstants.FilterSelfRoute, new { id = result.Id }), result));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateResult([FromRoute] string id, [FromBody] FilterModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var filter = await service.Find(id);

            if (filter.User != this.User.GetUserId())
            {
                return(Unauthorized());
            }

            var result = await service.Update(model.ToEntity(id, this.User.GetUserId()));

            return(Ok(result));
        }