예제 #1
0
 public TrasactionService(ParrotWingsContext db, string currentUserName)
 {
     _db = db;
     _currentUserName = currentUserName;
     _currentUser     = db.Users
                        .FirstOrDefault(el => el.Name == _currentUserName);
 }
예제 #2
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var user = new ApplicationUser()
                {
                    UserName = model.Name,
                    Email    = model.Email
                };

                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (!result.Succeeded)
                {
                    return(GetErrorResult(result));
                }

                var _db = new ParrotWingsContext();

                var newUser = new User()
                {
                    Name    = model.Name,
                    Balance = 500
                };

                _db.Users.Add(newUser);

                _db.SaveChanges();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }