Пример #1
0
        public async Task<ActionResult> Create(CreateModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userService.GetUser(model.UserName);
                if (user != null)
                {
                    FlashHelper.Add(string.Format("User with the username {0} aready exists.", model.UserName), FlashType.Error);
                    return new RedirectToRouteResult(new RouteValueDictionary(){
                        { "controller", "Account" },
                        { "action", "Index" }
                    });
                }
                
                var userObject = new User()
                {
                    Id = Guid.NewGuid(),
                    UserName = model.UserName
                };
                await userService.CreateUser(userObject, model.Password);

                FlashHelper.Add(string.Format("User with the username {0} have been created.", model.UserName), FlashType.Success);
                return new RedirectToRouteResult(new RouteValueDictionary(){
                        { "controller", "Account" },
                        { "action", "Index" }
                    });
            }
            return View(model);
        }
Пример #2
0
 public async Task CreateUser(User user, string password)
 {
     using (var audioViewEntities = new AudioViewEntities())
     {
         var userObject = user.ToDatabase();
         userObject.passwordSalt = getRandomSalt();
         userObject.password = generateHash(password, userObject.passwordSalt);
         audioViewEntities.Users.Add(userObject);
         await audioViewEntities.SaveChangesAsync().ConfigureAwait(false);
     }
 }
Пример #3
0
 public async Task CreateUser(User user, string password)
 {
     using (var audioViewEntities = new AudioViewEntities())
     {
         var userObject = user.ToDatabase();
         userObject.passwordSalt = getRandomSalt();
         userObject.password     = generateHash(password, userObject.passwordSalt);
         audioViewEntities.Users.Add(userObject);
         await audioViewEntities.SaveChangesAsync().ConfigureAwait(false);
     }
 }