public IActionResult Post([FromBody] CatagoryEditDto dto) { if (!ModelState.IsValid) { return(BadRequest()); } var catagory = Catagory.Create(dto.Name); if (dto.ParentID.HasValue && dto.ParentID.Value != Guid.Empty) { var parentCatagory = _context.Catagories.Find(dto.ParentID); parentCatagory.AddChildCatagory(catagory); } _context.Catagories.Add(catagory); _context.SaveChanges(); return(this.AlpsActionOk()); }
public IActionResult Put(Guid id, [FromBody] CatagoryEditDto dto) { if (!ModelState.IsValid || id != dto.ID) { return(BadRequest()); } var catagory = _context.Catagories.Find(id); catagory.Name = dto.Name; if (dto.ParentID.HasValue && dto.ParentID.Value != Guid.Empty && catagory.ParentID != dto.ParentID) { var parentCatagory = _context.Catagories.Find(dto.ParentID); parentCatagory.AddChildCatagory(catagory); } _context.SaveChanges(); return(this.AlpsActionOk()); }