Esempio n. 1
0
        internal Boquet GetById(int id)
        {
            Boquet Boquet = _repo.GetById(id);

            if (Boquet == null)
            {
                throw new Exception("invalid Id");
            }
            return(Boquet);
        }
Esempio n. 2
0
        internal IEnumerable <Flower> GetFlowersByBoquetId(int flowerId)
        {
            Boquet exists = _brepo.GetById(flowerId);

            if (exists == null)
            {
                throw new Exception("Invalid Id");
            }
            return(_repo.GetFlowersByBoquetId(flowerId));
        }
 [HttpPost] // POST
 public ActionResult <Boquet> Create([FromBody] Boquet newBoquet)
 {
     try
     {
         return(Ok(_service.Create(newBoquet)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Esempio n. 4
0
        internal Boquet Edit(Boquet updated)
        {
            var original = GetById(updated.Id);

            updated.name        = updated.name != null ? updated.name : original.name;
            updated.description = updated.description != null ? updated.description : original.description;
            updated.price       = updated.price > 0 ? updated.price : original.price;
            updated.amount      = updated.amount > 0 ? updated.amount : original.amount;
            updated.wrap        = updated.wrap != false ? updated.wrap : original.wrap;

            return(_repo.Edit(updated));
        }
 [HttpPut("{id}")] // PUT
 public ActionResult <Boquet> Edit([FromBody] Boquet editBoquet, int id)
 {
     try
     {
         editBoquet.Id = id;
         return(Ok(_service.Edit(editBoquet)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Esempio n. 6
0
        internal Boquet Create(Boquet newBoquet)
        {
            string sql = @"
                INSERT INTO Boquets
                    (name, description, color, price, wrap, amount)
                VALUES
                    (@name, @description, @color, @price @wrap, @amount);
                SELECT LAST_INSERT_ID();
                ";
            int    id  = _bb.ExecuteScalar <int>(sql, newBoquet);

            newBoquet.Id = id;
            return(newBoquet);
        }
Esempio n. 7
0
        internal Boquet Edit(Boquet update)
        {
            string sql = @"
                UPDATE FROM Boquets
                SET
                    name = @name,
                    color = @color,
                    description = @description,
                    price = @price,
                    wrap = @wrap,
                    amount = @amount
                WHERE id = @Id";

            _bb.Execute(sql, update);
            return(update);
        }
Esempio n. 8
0
 internal Boquet Create(Boquet newBoquet)
 {
     return(_repo.Create(newBoquet));
 }