Exemplo n.º 1
0
        public ActionResult CategoryTemplateUpdate(CategoryTemplateModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            var template = _categoryTemplateService.GetCategoryTemplateById(model.Id);

            if (template == null)
            {
                throw new ArgumentException("No template found with the specified id");
            }
            template = model.ToEntity(template);
            _categoryTemplateService.UpdateCategoryTemplate(template);

            return(CategoryTemplates(command));
        }
Exemplo n.º 2
0
        public virtual ActionResult CategoryTemplateUpdate(CategoryTemplateModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var template = _categoryTemplateService.GetCategoryTemplateById(model.Id);

            if (template == null)
            {
                throw new ArgumentException("No template found with the specified id");
            }
            template = model.ToEntity(template);
            _categoryTemplateService.UpdateCategoryTemplate(template);

            return(new NullJsonResult());
        }
Exemplo n.º 3
0
        public virtual IActionResult CategoryTemplateAdd(CategoryTemplateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            CategoryTemplate template = new CategoryTemplate();

            template = model.ToEntity(template);
            _categoryTemplateService.InsertCategoryTemplate(template);

            return(new NullJsonResult());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CategoryTemplateAdd(CategoryTemplateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }
            if (ModelState.IsValid)
            {
                var template = new CategoryTemplate();
                template = model.ToEntity(template);
                await _categoryTemplateService.InsertCategoryTemplate(template);

                return(new NullJsonResult());
            }
            return(ErrorForKendoGridJson(ModelState));
        }
Exemplo n.º 5
0
        public virtual IActionResult CategoryTemplateUpdate(CategoryTemplateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            //try to get a category template with the specified id
            CategoryTemplate template = _categoryTemplateService.GetCategoryTemplateById(model.Id)
                                        ?? throw new ArgumentException("No template found with the specified id");

            template = model.ToEntity(template);
            _categoryTemplateService.UpdateCategoryTemplate(template);

            return(new NullJsonResult());
        }
Exemplo n.º 6
0
        public virtual IActionResult CategoryTemplateAdd(CategoryTemplateModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            var template = new CategoryTemplate();

            template = model.ToEntity(template);
            _categoryTemplateService.InsertCategoryTemplate(template);

            return(Json(new { Result = true }));
        }
Exemplo n.º 7
0
        public virtual ActionResult CategoryTemplateAdd([Bind(Exclude = "Id")] CategoryTemplateModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var template = new CategoryTemplate();

            template = model.ToEntity(template);
            _categoryTemplateService.InsertCategoryTemplate(template);

            return(new NullJsonResult());
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> CategoryTemplateUpdate(CategoryTemplateModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            //try to get a category template with the specified id
            var template = await _categoryTemplateService.GetCategoryTemplateByIdAsync(model.Id)
                           ?? throw new ArgumentException("No template found with the specified id");

            template = model.ToEntity(template);
            await _categoryTemplateService.UpdateCategoryTemplateAsync(template);

            return(new NullJsonResult());
        }
Exemplo n.º 9
0
        public ActionResult CategoryTemplateAdd([Bind(Exclude = "Id")] CategoryTemplateModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            var template = new CategoryTemplate();

            template = model.ToEntity(template);
            _categoryTemplateService.InsertCategoryTemplate(template);

            return(CategoryTemplates(command));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> CategoryTemplateUpdate(CategoryTemplateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var template = await _categoryTemplateService.GetCategoryTemplateById(model.Id);

            if (template == null)
            {
                throw new ArgumentException("No template found with the specified id");
            }
            if (ModelState.IsValid)
            {
                template = model.ToEntity(template);
                await _categoryTemplateService.UpdateCategoryTemplate(template);

                return(new NullJsonResult());
            }
            return(ErrorForKendoGridJson(ModelState));
        }
Exemplo n.º 11
0
 public static CategoryTemplate ToEntity(this CategoryTemplateModel model, CategoryTemplate destination)
 {
     return(model.MapTo(destination));
 }
Exemplo n.º 12
0
 public static CategoryTemplate ToEntity(this CategoryTemplateModel model)
 {
     return(model.MapTo <CategoryTemplateModel, CategoryTemplate>());
 }
Exemplo n.º 13
0
 public static CategoryTemplate ToEntity(this CategoryTemplateModel model)
 {
     return(Mapper.Map <CategoryTemplateModel, CategoryTemplate>(model));
 }