internal Boquet GetById(int id) { Boquet Boquet = _repo.GetById(id); if (Boquet == null) { throw new Exception("invalid Id"); } return(Boquet); }
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)); } }
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)); } }
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); }
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); }
internal Boquet Create(Boquet newBoquet) { return(_repo.Create(newBoquet)); }