public ResultViewModel UpdateCategory([FromBody] EditorCategoryViewModel model) { model.Validate(); if (model.Invalid) { return new ResultViewModel { Success = false, Message = "Não foi possivel editar a categoria!", Data = model.Notifications } } ; var category = _categoryRepository.Get(model.Id); category.Title = model.Title; category.Description = model.Description; //Update _categoryRepository.Update(category); return(new ResultViewModel { Success = true, Message = "Categoria editada com sucesso!", Data = category });; }
public ResultViewModel Put([FromBody] EditorCategoryViewModel model) { model.Validate(); if (model.Invalid) { return new ResultViewModel { Success = false, Message = "Não foi possível cadastrar Categoria", Data = model.Notifications } } ; var category = _repository.Get(model.Id); category.Title = model.Title; _repository.Update(category); return(new ResultViewModel { Success = true, Message = "Categoria alterada com sucesso", Data = category }); }
public ResultViewModel Post([FromBody] EditorCategoryViewModel model) { model.Validate(); if (model.Invalid) { return(new ResultViewModel() { Success = false, Message = "Não foi possível criar categoria", Data = model }); } var category = new Category() { Title = model.Title }; category = _categoryRepository.Create(category); return(new ResultViewModel() { Success = true, Message = "Categoria criada com sucesso", Data = category }); }
public ResultViewModel CreateCategory([FromBody] EditorCategoryViewModel model) { model.Validate(); if (model.Invalid) { return new ResultViewModel { Success = false, Message = "Não foi possivel criar a categoria!", Data = model.Notifications } } ; var category = new Category(); category.Title = model.Title; category.Description = model.Description; //Salvar _categoryRepository.Save(category); return(new ResultViewModel { Success = true, Message = "Categoria criada com sucesso!", Data = category }); }
public ResultViewModel Post([FromBody] EditorCategoryViewModel model) { model.Validate(); if (model.Invalid) { return new ResultViewModel { Success = model.Valid, Message = "Não foi possível adicionar nova categoria", Data = model.Notifications } } ; var category = new Category(); category.Id = model.Id; category.Title = model.Title; _repository.Save(category); return(new ResultViewModel { Success = model.Valid, Message = "Produto criado com sucesso!", Data = category }); }
public ActionResult Update(int id) { var category = _categoryRepository.Get(id); EditorCategoryViewModel model = new EditorCategoryViewModel { Nome = category.Nome }; return(View(model)); }
public ActionResult Create(EditorCategoryViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("ErrorMessage", "Modelo inválido"); return(View(model)); } Category category = new Category { Nome = model.Nome }; return(View(category)); }
public ResultViewModel Delete([FromBody] EditorCategoryViewModel model) { var category = _categoryRepository.Get(model.Id); if (category is null) { return(new ResultViewModel() { Success = false, Message = "Não foi possível deletar este item", Data = model }); } _categoryRepository.Delete(category); return(new ResultViewModel() { Success = true, Message = "Produto deletado com sucesso.", Data = category }); }
public ResultViewModel Put([FromBody] EditorCategoryViewModel model) { model.Validate(); if (model.Invalid) { return(new ResultViewModel() { Success = false, Message = "Não foi possível alterar categoria", Data = model }); } var category = _categoryRepository.Get(model.Id); if (category is null) { return(new ResultViewModel() { Success = false, Message = "Categoria não encontrada", Data = model }); } category.Title = model.Title; _categoryRepository.Update(category); return(new ResultViewModel() { Success = true, Message = "Categoria alterada com sucesso", Data = category }); }