public Bookers Edit(Bookers updatedBook) { Bookers exists = _repo.Get(updatedBook.Id); if (exists == null) { throw new Exception("Invalid Id"); } return(_repo.Edit(updatedBook)); }
public Bookers Get(int id) { Bookers found = _repo.Get(id); if (found == null) { throw new Exception("Invalid Id"); } return(found); }
public ActionResult <Bookers> Create([FromBody] Bookers newBook) { try { return(Ok(_vs.Create(newBook))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Bookers> Edit(int id, [FromBody] Bookers updatedBook) { try { updatedBook.Id = id; return(Ok(_vs.Edit(updatedBook))); } catch (Exception e) { return(BadRequest(e.Message)); } }
//put public Bookers Edit(Bookers updatedBook) { string sql = @" UPDATE bookers SET title = @Title, pages = @Pages, isAvailable = @IsAvailable WHERE id = @Id; "; _db.Execute(sql, updatedBook); return(updatedBook); }
//post public Bookers Create(Bookers newBook) { string sql = @" INSERT INTO bookers (title, pages, IsAvailable, lbId) VALUES (@Title, @Pages, true, @lbId); SELECT LAST_INSERT_ID(); "; int id = _db.ExecuteScalar <int>(sql, newBook); newBook.Id = id; newBook.IsAvailable = true; return(newBook); }
public string Delete(int id) { Bookers exists = _repo.Get(id); if (exists == null) { throw new Exception("Invalid Id"); } //if you are the creator if (_repo.Delete(id)) { return("Success"); } throw new Exception("Something went wrong with deleting that item"); }
public Bookers Create(Bookers newVid) { return(_repo.Create(newVid)); }