示例#1
0
 public async Task <IHttpActionResult> Register([FromBody] RegisterViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (_userRepo.IsUserExists(model.Email)) //user is alreasy exists
             {
                 return(BadRequest(model.Email + " " + "is already taken"));
             }
             else
             {
                 var user = new User();
                 user.FirstName = model.FirstName;
                 user.LastName  = model.LastName;
                 user.UserName  = model.UserName;
                 user.Email     = model.Email;
                 user.Password  = PasswordHashProvider.HashPassword(model.Password);
                 var    userId   = _userRepo.Create(user);
                 string location = Request.RequestUri + "/" + user.Id.ToString();
                 return(Created(location, new { Id = userId }));
             }
         }
         else
         {
             return(BadRequest(string.Join(" ", ModelState.Values.SelectMany(x => x.Errors).Select(e => e.ErrorMessage))));
         }
     }
     catch (Exception e)
     {
         return(await ErrorResult(e));
     }
 }
示例#2
0
        public int ChangePassword(ChangePasswordViewModel model, string email)
        {
            var user = _dbContext.Users.Where(x => x.Email == email).FirstOrDefault();

            user.Password = PasswordHashProvider.HashPassword(model.NewPassword);
            var result = _dbContext.SaveChanges();

            return(result);
        }