Пример #1
0
        public async Task <Message <string> > Register(RegisterBindingModel model)
        {
            using (costmanagerdbEntities db = new costmanagerdbEntities())
            {
                var userExists = db.Users.Any(x => x.Login == model.Login);
                if (userExists)
                {
                    return new Message <string> {
                               StatusCode = (int)HttpStatusCode.Conflict, ReturnMessage = "Change username", IsSuccess = false
                    }
                }
                ;
                else
                {
                    db.Users.Add(new Models.Db.User {
                        Login = model.Login, Password = model.Password
                    });

                    await db.SaveChangesAsync();

                    var user = new ApplicationUser()
                    {
                        UserName = model.Login, Email = model.Login
                    };
                    IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                    return(new Message <string> {
                        StatusCode = (int)HttpStatusCode.OK, ReturnMessage = "Registered", IsSuccess = true
                    });
                }
            }
        }