Example #1
0
        private async Task <UserModel> UpdateUserAsync(string userId, UserModel model)
        {
            var appUser = await _userManager.FindByIdAsync(userId);

            if (appUser == null)
            {
                throw new Voyage.Core.Exceptions.NotFoundException($"Could not locate entity with Id {userId}");
            }

            if (!IsValidPhoneNumbers(model))
            {
                throw new BadRequestException(HttpStatusCode.BadRequest.ToString(), "Invalid phone number.");
            }

            _mapper.Map <UserModel, ApplicationUser>(model, appUser);

            CollectionHelpers.MergeCollection(
                _mapper,
                source: model.Phones,
                destination: appUser.Phones,
                predicate: (s, d) => s.Id == d.Id,
                deleteAction: entity => _phoneRepository.Delete(entity.Id));

            await _userManager.UpdateAsync(appUser);

            return(_mapper.Map <UserModel>(appUser));
        }
        public ActionResult Delete(int phoneId)
        {
            UserPhone deletedPhone = repository.Delete(phoneId);

            if (deletedPhone != null)
            {
                TempData["message"] = string.Format("{0} was deleted",
                                                    deletedPhone.Name);
            }
            return(RedirectToAction("Index"));
        }