Ejemplo n.º 1
0
        public async Task<IHttpActionResult> UpdateUser(ApplicationUserDTO model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = await UserManager.FindByIdAsync(model.Id);
            user.PhoneNumber = model.PhoneNumber;
            user.UserProfileInfo.Company = model.UserProfileInfo.Company;
            user.UserProfileInfo.FirstName = model.UserProfileInfo.FirstName;
            user.UserProfileInfo.LastName = model.UserProfileInfo.LastName;
            user.UserProfileInfo.Type = model.UserProfileInfo.Type;
            user.UserProfileInfo.Gender = model.UserProfileInfo.Gender;
            user.UserProfileInfo.AltMobileNumber = model.UserProfileInfo.AltMobileNumber;
            user.UserProfileInfo.City = model.UserProfileInfo.City;
            user.UserProfileInfo.State = model.UserProfileInfo.State;
            user.UserProfileInfo.Country = model.UserProfileInfo.Country;
            user.UserProfileInfo.Address = model.UserProfileInfo.Address;

            IdentityResult result = await UserManager.UpdateAsync(user);

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

            return Ok(_mapper.Map<ApplicationUserDTO>(user));
        }
Ejemplo n.º 2
0
        public async Task<IHttpActionResult> Register(ApplicationUserDTO model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            ApplicationUser user = _mapper.Map<ApplicationUser>(model);

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

            if (result.Succeeded)
            {
                string code = await this.UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code }));
                try
                {
                    await this.UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                }
                catch (Exception ex)
                {
                    throw;
                }

                Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id }));

                result = await UserManager.AddToRoleAsync(user.Id, model.Role);
            }
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok(_mapper.Map<ApplicationUserDTO>(user));
        }