示例#1
0
        private Professionnel Modification(Professionnel initialPro, ProfessionnelsUpdateDTO targetPro)
        {
            ScryptEncoder encoder = new ScryptEncoder();
            var           retour  = initialPro;

            if (targetPro.NomEntreprise != null)
            {
                retour.NomEntreprise = targetPro.NomEntreprise;
            }
            if (targetPro.Adresse != null)
            {
                retour.Adresse = targetPro.Adresse;
            }
            if (targetPro.MotDePasse != null)
            {
                retour.MotDePasse = encoder.Encode(targetPro.MotDePasse);
            }
            if (targetPro.NumeroTel != null)
            {
                retour.NumeroTel = targetPro.NumeroTel;
            }
            if (targetPro.Mail != null)
            {
                retour.Mail = targetPro.Mail;
            }
            if (targetPro.NumeroTVA != null)
            {
                retour.NumeroTVA = targetPro.NumeroTVA;
            }
            if (targetPro.LocaliteCode != null)
            {
                retour.LocaliteCode = targetPro.LocaliteCode;
            }
            return(retour);
        }
示例#2
0
        public async Task <IActionResult> UpdateMyAccount([FromBody] ProfessionnelsUpdateDTO professionnel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var email = User.Claims.SingleOrDefault(x => x.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;

            var user = await _context.Professionnels.SingleOrDefaultAsync(p => p.Mail.Equals(email));

            if (user == null)
            {
                return(NotFound());
            }

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

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

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

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

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

            return(NoContent());
        }
示例#3
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());
        }