示例#1
0
        public IActionResult EditProfil([FromBody] Profil updatedprofil)
        {
            var oldprofil = _maBd.Profil.FirstOrDefault(pr => pr.profilId == updatedprofil.profilId);

            if (oldprofil != null)
            {
                var utilisateur = _maBd.Utilisateur.FirstOrDefault(u => u.email == oldprofil.courriel);

                if (utilisateur != null)
                {
                    var trouve = _maBd.Utilisateur.FirstOrDefault(u => u.email == updatedprofil.courriel);

                    if (trouve == null || trouve.Id == utilisateur.Id)
                    {
                        utilisateur.email = updatedprofil.courriel;

                        _maBd.Utilisateur.Attach(utilisateur);

                        var entry = _maBd.Entry(utilisateur);
                        entry.Property(e => e.email).IsModified = true;
                        _maBd.SaveChanges();

                        _maBd.Profil.Attach(oldprofil);
                        _maBd.Entry(oldprofil).CurrentValues.SetValues(updatedprofil);
                        _maBd.SaveChanges();

                        return(new OkObjectResult(updatedprofil));
                    }
                }
            }

            return(new OkObjectResult(null));
        }
        public IActionResult ModifyMachin(Machin updatedMachin)
        {
            var machin = _maBd.Machin.FirstOrDefault(m => m.Id == updatedMachin.Id);

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

            _maBd.Entry(machin).CurrentValues.SetValues(updatedMachin);

            return(new OkResult());
        }
        public IActionResult AjoutTrajet([FromBody] Marqueur marqueur)
        {
            var oldmark = _maBd.Marqueur.FirstOrDefault(m => m.Id == marqueur.Id);

            if (oldmark != null)
            {
                _maBd.Entry(oldmark).CurrentValues.SetValues(marqueur);
                _maBd.SaveChanges();

                return(new OkObjectResult(marqueur));
            }

            return(new OkObjectResult(null));
        }
示例#4
0
        public IActionResult ModifyPostUser([FromBody] PostUserDto updatedPost, int id)
        {
            var post = _maBd.PostsUser.FirstOrDefault(m => m.postId == id);

            if (post == null)
            {
                return(new ObjectResult(null));
            }

            _maBd.Entry(post).CurrentValues.SetValues(updatedPost);
            _maBd.SaveChanges();

            return(new OkObjectResult(post));
        }
        public IActionResult Reset([FromBody] UtilisateurDto user)
        {
            var identity = _maBd.Utilisateur.SingleOrDefault(u => u.email == user.Email);

            if (identity != null)
            {
                identity.reset = true;
                identity.mdp   = RandomString(8);
                emailSender.setDestination(user.Email);
                emailSender.setSender("*****@*****.**", "Welcome");
                emailSender.SetHTMLMessage("Votre mot de passe temporaire est le <b> " + identity.mdp.ToString() + "</b><br><a href='https://rando.dinf.cll.qc.ca/login'>https://rando.dinf.cll.qc.ca/login</a>");
                emailSender.setSubject("Nouveau Mot de passe");

                try
                {
                    emailSender.sendMessage();
                }
                catch (Exception ex)
                {
                    Object[] obj = { ex.Message, user };
                    return(new OkObjectResult(false));
                }

                _maBd.Utilisateur.Attach(identity);

                var entry = _maBd.Entry(identity);
                entry.Property(e => e.mdp).IsModified   = true;
                entry.Property(e => e.reset).IsModified = true;
                _maBd.SaveChanges();
            }
            else
            {
                return(new ObjectResult(null));
            }
            return(new OkObjectResult(user));
        }