Beispiel #1
0
        public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] ProfessionnelsUpdateDTO professionnel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!ProfessionnelExists(id))
            {
                return(NotFound());
            }

            if (await _context.Professionnels.AnyAsync(x => x.Mail == professionnel.Mail && x.Id != id))
            {
                return(Conflict("Mail"));
            }

            if (await _context.Professionnels.AnyAsync(x => x.NomEntreprise == professionnel.NomEntreprise && x.Id != id))
            {
                return(Conflict("NomEntreprise"));
            }

            if (professionnel.LocaliteCode != null && !await _context.Localites.AnyAsync(x => x.CodePostal.Equals(professionnel.LocaliteCode)))
            {
                return(NotFound());
            }

            var user = await _context.Professionnels.SingleOrDefaultAsync(p => p.Id.Equals(id));

            user = Modification(user, professionnel);
            _context.Entry(user).State = EntityState.Modified;

            try {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateParticuliers([FromRoute] Guid id, [FromBody] ParticuliersUpdateDTO particulier)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_context.Particuliers.Any(p => p.Id.Equals(id)))
            {
                return(NotFound());
            }

            if (await _context.Particuliers.AnyAsync(x => x.Mail == particulier.Mail && x.Id != id))
            {
                return(Conflict("Mail"));
            }

            if (await _context.Particuliers.AnyAsync(x => x.Pseudo == particulier.Pseudo && x.Id != id))
            {
                return(Conflict("Pseudo"));
            }

            if (particulier.LocaliteCode != null && !await _context.Localites.AnyAsync(x => x.CodePostal.Equals(particulier.LocaliteCode)))
            {
                return(NotFound());
            }

            var user = await _context.Particuliers.SingleOrDefaultAsync(p => p.Id.Equals(id));

            user = Modification(user, particulier);
            _context.Entry(user).State = EntityState.Modified;

            try {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }
            return(NoContent());
        }