public async Task <ActionResult <User> > PutUserPoll(int id, User user)
        {
            if (id != user.User_ID)
            {
                return(BadRequest());
            }

            var updateUser = await _context.User.FirstOrDefaultAsync(s => s.User_ID == user.User_ID);

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

            updateUser.Name = user.Name;
            updateUser.Poll = user.Poll;

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

            return(updateUser);
        }
        //[Route("UpdateName")]
        public async Task <IActionResult> PutName(int id, Poll poll)
        {
            if (id != poll.Poll_ID)
            {
                return(BadRequest());
            }

            var updatePoll = await _context.Poll.FirstOrDefaultAsync(s => s.Pool_Title == poll.Pool_Title);

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

            updatePoll.Pool_Title = poll.Pool_Title;

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

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> Reset(AccountEmailReset model)
        {
            var user = await AppDatabase.Users.FirstOrDefaultAsync(o => o.Email == model.Email);

            if (user == null)
            {
                return(BadRequest("User not found"));
            }

            if (string.IsNullOrEmpty(user.Email))
            {
                return(BadRequest("User lacks a valid email address. Did you use Facebook or Twilio ?"));
            }

            var token = Strings.RandomString(6).ToLower();

            user.ModifiedOn    = DateTime.UtcNow;
            user.EmailPassword = UserPassword.Create(token);

            AppDatabase.Entry(user).State = EntityState.Modified;

            await AppDatabase.SaveChangesAsync();

            await SendTokenEmail(new UserTokenViewModel
            {
                UserId    = user.Id,
                UserEmail = user.Email,
                Token     = token,
            });

            return(Ok(GetAccountDetails()));
        }
Esempio n. 4
0
        public async Task <ActionResult <PollOption> > AddVote(int id, PollOption pollOption)
        {
            if (id != pollOption.Option_ID)
            {
                return(BadRequest());
            }

            var updatePollOption = await _context.PollOption.FirstOrDefaultAsync(s => s.Option_ID == pollOption.Option_ID);

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

            updatePollOption.Vote = pollOption.Vote;

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

            return(updatePollOption);
        }
Esempio n. 5
0
        public async Task <IActionResult> PutQuestions(int id, Questions questions)
        {
            if (id != questions.questionID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 6
0
        async Task DeleteUser(UserAccount user)
        {
            // delete
            AppDatabase.Entry(user).State = EntityState.Deleted;
            AppDatabase.Users.Remove(user);
            AppDatabase.UserFacebookClaims.RemoveRange(AppDatabase.UserFacebookClaims.Where(o => o.UserId == user.Id));

            AppDatabase.Storage.RemoveRange(AppDatabase.Storage.Where(o => o.AclParam == user.Id));
            AppDatabase.Scores.RemoveRange(AppDatabase.Scores.Where(o => o.UserId == user.Id));

            await AppDatabase.SaveChangesAsync();

            Session.SignOut();
            Authorization.SignOut();
        }
Esempio n. 7
0
        public async Task <IHttpActionResult> Update(AccountEmailUpdate model)
        {
            var user = await AppDatabase.Users.FindAsync(Session.UserId);

            // no user? signUp. This happens from guest upgrades.
            if (user == null)
            {
                return(await Create(new AccountEmailSignIn
                {
                    UserId = Session.UserId,
                    Email = model.NewEmail,
                    Password = model.NewPassword
                }));
            }

            // make sure Email is not in use by someone else
            string oldEmail = null;

            if (!string.IsNullOrEmpty(model.NewEmail))
            {
                var users = await AppDatabase.Users
                            .Where(o => o.Id != Session.UserId)
                            .AnyAsync(o => o.Email == model.NewEmail);

                if (users)
                {
                    return(BadRequest("Email is in use."));
                }

                oldEmail   = user.Email;
                user.Email = model.NewEmail;
            }

            // update password
            if (!string.IsNullOrEmpty(model.NewPassword))
            {
                user.EmailPassword = UserPassword.Create(model.NewPassword);
            }

            // update password
            if (!string.IsNullOrEmpty(model.NewEmail))
            {
                user.Email = model.NewEmail;
            }

            // update
            user.ModifiedOn = DateTime.UtcNow;
            AppDatabase.Entry(user).State = EntityState.Modified;
            await AppDatabase.SaveChangesAsync();

            await SendUpdateEmail(new UserUpdateViewModel
            {
                UserId    = user.Id,
                UserEmail = user.Email,
                OldEmail  = oldEmail,
            });

            //update session
            Session.UpdateFrom(user);
            Authorization.UpdateFrom(user);

            return(Ok(GetAccountDetails()));
        }
 public void Update(ApplicationUserentity entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     _context.SaveChanges();
 }