public async Task<IHttpActionResult> Register(ApplicationUserModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser(model);

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

            return !result.Succeeded ? GetErrorResult(result) : Ok();
        }
Пример #2
0
        public ApplicationUser(ApplicationUserModel model)
        {
            if (model == null)
                throw new NullReferenceException($"The {nameof(model)} is null");

            if (Info == null)
                Info = new UserInfo();
            Info.Id = Id;
            Info.Address.Add(model.Address);
            Info.Name = model.Name;
            Info.Cpf = model.Cpf;
            Info.BirthDate = model.BirthDate;
            Info.Gender = model.Gender;
            Info.Email = UserName = Email = model.Email;

        }
        public async Task<IHttpActionResult> Register(ApplicationUserModel model)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);
            if (UserManager == null)
                return InternalServerError(new Exception("Fail in load Identity"));

            Contract.EndContractBlock();

            var user = new ApplicationUser(model);
            try
            {
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    return Ok(new
                    {
                        Id = user.Id,
                        Name = user.Info.Name
                    });

                }
                var msg = result.Errors.IsNullOrEmpty()
                    ? ""
                    : result.Errors.Aggregate((c, r) => $"{c} \n\r {r}");

                return BadRequest(msg);
            }
            catch (Exception ex)
            {
                var exBase = ex.GetBaseException();
                return InternalServerError(exBase);
            }
        }