コード例 #1
0
        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);
        }
コード例 #2
0
 internal String Delete(CartShoes cs)
 {
     if (_repo.Delete(cs))
     {
         return("Successfully Deleted");
     }
     throw new Exception("Invalid Id");
 }
コード例 #3
0
        // 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);
        }
コード例 #4
0
 [HttpPut]  // api/cartshoes/:shoeCartId
 public ActionResult <CartShoes> Delete([FromBody] CartShoes toRemove)
 {
     try
     {
         return(Ok(_cs.Delete(toRemove)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #5
0
 public ActionResult <CartShoes> Create([FromBody] CartShoes newCartShoes)
 {
     try
     {
         return(Ok(_cs.Create(newCartShoes)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #6
0
        // 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);
        }