internal bool Delete(CartShoes cs) { string sql = "DELETE FROM cartshoes WHERE cartId = @CartId AND shoeId = @ShoeId LIMIT 1"; int deleted = _db.Execute(sql, cs); return(deleted == 1); }
internal String Delete(CartShoes cs) { if (_repo.Delete(cs)) { return("Successfully Deleted"); } throw new Exception("Invalid Id"); }
// internal CartShoes Get(int id) // { // CartShoes found = _repo.Get(id); // if (found == null) // { // throw new Exception("Invalid Id"); // } // return found; // } internal CartShoes Create(CartShoes newCartShoes) { CartShoes created = _repo.Create(newCartShoes); if (created == null) { throw new Exception("Create Request Failed"); } return(created); }
[HttpPut] // api/cartshoes/:shoeCartId public ActionResult <CartShoes> Delete([FromBody] CartShoes toRemove) { try { return(Ok(_cs.Delete(toRemove))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <CartShoes> Create([FromBody] CartShoes newCartShoes) { try { return(Ok(_cs.Create(newCartShoes))); } catch (Exception e) { return(BadRequest(e.Message)); } }
// internal CartShoes Get(int Id) // { // string sql = "SELECT * FROM carts WHERE id = @Id"; // // NOTE essentialy FindOne() returns a single object or null // return _db.QueryFirstOrDefault<CartShoes>(sql, new { Id }); // } internal CartShoes Create(CartShoes newCartShoes) { string sql = @" INSERT INTO cartshoes (cartId, shoeId) VALUES (@CartId, @ShoeId); SELECT LAST_INSERT_ID(); "; newCartShoes.Id = _db.ExecuteScalar <int>(sql, newCartShoes); return(newCartShoes); }