Example #1
0
 public async Task <bool> CreateUser(UserModel model)
 {
     try
     {
         return(await rep.CreateUser(model));
     }
     catch (Exception e)
     {
         throw new ApplicationException($"Ha ocurrido un error {e.Message}");
     }
 }
Example #2
0
        public async Task <IHttpActionResult> Register(Register model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            IdentityResult result = await repository.CreateUser(model.Email, model.Password);

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

            result = await repository.AssignRole(model.Email, model.Password, model.RoleType.ToString());

            IdentityUser user = await repository.FindUser(model.Email, model.Password);

            return(GetErrorResult(result) ?? Ok(new { userId = user.Id }));
        }