Exemple #1
0
        public async Task <IActionResult> delete([FromRoute] Guid id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                //first or default retourne le premiere enregistrement where e.id=id sinon return null
                ConducteurSite conducteurSite = _context.ConducteurSite.FirstOrDefault(e => e.id == id);
                if (conducteurSite == null)
                {
                    return(NotFound());
                }

                _context.ConducteurSite.Remove(conducteurSite);
                SaveChanges(_context);

                return(Ok(conducteurSite));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        public async Task <IActionResult> put([FromRoute] Guid id, [FromBody] ConducteurSite conducteurSite)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != conducteurSite.id)
            {
                return(BadRequest());
            }

            _context.Entry(conducteurSite).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!conducteurSiteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #3
0
        public async Task <ConducteurSite> post([FromBody] ConducteurSite conducteurSite)
        {
            try
            {
                _context.ConducteurSite.Add(conducteurSite);
                await _context.SaveChangesAsync();
            }

            catch (Exception ex) {
                throw ex;
            }

            return(conducteurSite);
        }