public IActionResult Put(string id, Authour model) { try { var Authour = _repo.UpdatePutAuthour(id, model); return(new OkObjectResult(new{ message = "Authour updated succesfully", id })); } catch (Exception e) { return(BadRequest(new { message = e.Message })); } }
public IActionResult Post(Authour model) { try { var Authour = _repo.AddAuthour(model); return(new CreatedResult("/Authour/", new { Id = Authour.Id, message = "Authour created succesfully" })); } catch (Exception e) { return(BadRequest(new { message = e.Message })); } }
public Authour UpdatePutAuthour(string id, Authour model) { var Authour = GetOneAuthour(id); if (Authour is null) { throw new ArgumentOutOfRangeException(message: "No Authour with this Id found", null); } Authour.FullName = model.FullName; _context.Authour.Update(Authour); _context.SaveChanges(); return(Authour); }
public Authour AddAuthour(Authour model) { if (model is null) { throw new ArgumentNullException(message: "Authour cannot be null", null); } var Authour = new Authour { Id = Guid.NewGuid().ToString(), FullName = model.FullName }; _context.Authour.Add(Authour); _context.SaveChanges(); return(Authour); }