public ActionResult Put(int id, [FromBody] CategoryPostDto dto) { try { _editCategory.Execute(dto); return(NoContent()); } catch (Exception) { return(StatusCode(500, "An error has occured.")); } }
public void Execute(CategoryPostDto request) { if (Context.CategoryPosts.Any(c => c.NameCat == request.Name)) { throw new EntityAlreadyExists(); } Context.CategoryPosts.Add(new Domen.CategoryPost { NameCat = request.Name }); Context.SaveChanges(); }
public ActionResult Post([FromBody] CategoryPostDto dto) { try { _addCategory.Execute(dto); return(StatusCode(201)); } catch (EntityAlreadyExists) { return(NotFound()); } catch (Exception) { return(StatusCode(500, "An error has occured.")); } }
public ActionResult Create(CategoryPostDto dto) { try { _addCategory.Execute(dto); return(RedirectToAction(nameof(Index))); } catch (EntityNoFound n) { return(NotFound()); } catch (Exception e) { TempData["greska"] = "Doslo je do greske."; } return(View()); }
public void Execute(CategoryPostDto request) { var category = Context.CategoryPosts.Find(request.Id); if (category == null) { throw new EntityNoFound(); } if (category.NameCat != request.Name) { if (Context.CategoryPosts.Any(c => c.NameCat == request.Name)) { throw new EntityAlreadyExists(); } category.NameCat = request.Name; Context.SaveChanges(); } }
public ActionResult Edit(int id, CategoryPostDto dto) { if (!ModelState.IsValid) { return(View(dto)); } try { _editCategory.Execute(dto); return(RedirectToAction(nameof(Index))); } catch (EntityNoFound) { return(RedirectToAction(nameof(Index))); } catch (EntityAlreadyExists) { TempData["error"] = "Kategorija sa istim imenom vec postoji."; return(View(dto)); } }
public async Task <IHttpActionResult> PostCategory(CategoryPostDto category) { var newCategory = await CategoryService.AddAsync(category); return(CreatedAtRoute("CategoryRoute", new { id = newCategory.Id }, newCategory)); }