Esempio n. 1
0
        public CodeChantier Update(CodeChantier cc, string code, string description, string client, string produit)
        {
            if (cc.Code != code)
            {
                Delete(cc);
                cc = Add(code, description, client, produit, false);
            }

            cc.Description = description;
            cc.Client      = client;
            cc.Produit     = produit;
            _db.SaveChanges();
            return(cc);
        }
        public ActionResult <CodeChantier> Post([FromBody] CodeChantier newCc)
        {
            var cc = _codeChantierLogic.GetByCode(newCc.Code);

            if (cc != null)
            {
                return(this.BadRequest(new
                {
                    error = string.Format("The code `{0}` is already used", newCc.Code)
                }));
            }

            cc = _codeChantierLogic.Add(newCc.Code, newCc.Description, newCc.Client, newCc.Produit);
            return(CreatedAtAction("Get", new { code = newCc.Code }, cc));
        }
Esempio n. 3
0
        public CodeChantier Add(string code, string description, string client, string produit, bool commit = true)
        {
            var cc = new CodeChantier();

            cc.Code         = code;
            cc.Description  = description;
            cc.Client       = client;
            cc.Produit      = produit;
            cc.CreationDate = DateTime.UtcNow;
            _db.CodesChantier.Add(cc);

            if (commit)
            {
                _db.SaveChanges();
            }
            return(cc);
        }
Esempio n. 4
0
 public void Delete(CodeChantier cc)
 {
     _db.CodesChantier.Remove(cc);
     _db.SaveChanges();
 }