public static MemberEditViewModel UserToMemberEditViewModel(MembershipUser user) { var viewModel = new MemberEditViewModel { IsApproved = user.IsApproved, Id = user.Id, IsLockedOut = user.IsLockedOut, IsBanned = user.IsBanned, Roles = user.Roles.Select(x => x.RoleName).ToArray(), UserName = user.UserName, Age = user.Age, Comment = user.Comment, Email = user.Email, Facebook = user.Facebook, Location = user.Location, PasswordAnswer = user.PasswordAnswer, PasswordQuestion = user.PasswordQuestion, Signature = user.Signature, Twitter = user.Twitter, Website = user.Website, DisableEmailNotifications = (user.DisableEmailNotifications == true), DisablePosting = (user.DisablePosting == true), DisablePrivateMessages = (user.DisablePrivateMessages == true), DisableFileUploads = (user.DisableFileUploads == true), Avatar = user.Avatar }; return viewModel; }
public ActionResult Edit(MemberEditViewModel userModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var user = MembershipService.GetUser(userModel.Id); // Map everything in model except properties hidden on page user.Age = userModel.Age; user.Comment = userModel.Comment; user.Email = userModel.Email; user.Facebook = userModel.Facebook; user.IsApproved = userModel.IsApproved; user.IsLockedOut = userModel.IsLockedOut; user.Location = userModel.Location; user.PasswordAnswer = userModel.PasswordAnswer; user.PasswordQuestion = userModel.PasswordQuestion; user.Signature = userModel.Signature; user.Twitter = userModel.Twitter; user.UserName = userModel.UserName; user.Website = userModel.Website; user.DisableEmailNotifications = userModel.DisableEmailNotifications; user.DisablePosting = userModel.DisablePosting; user.DisablePrivateMessages = userModel.DisablePrivateMessages; // If there is a location try and save the longitude and latitude if (!string.IsNullOrEmpty(user.Location)) { try { var longLat = LocalisationUtils.GeocodeGoogle(user.Location); if (longLat != null && longLat[0] != "0") { // Got the long lat and save them to the user user.Latitude = longLat[0]; user.Longitude = longLat[1]; } } catch { LoggingService.Error("Error getting longitude and latitude from location"); } } try { unitOfWork.Commit(); ViewBag.Message = new GenericMessageViewModel { Message = "User saved", MessageType = GenericMessages.success }; } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Errors.GenericMessage")); } return ListUsers(null, null); } }
public ActionResult Edit(MemberEditViewModel userModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var user = MembershipService.GetUser(userModel.Id); // Map everything in model except properties hidden on page user.Age = userModel.Age; user.Comment = userModel.Comment; user.Email = userModel.Email; user.Facebook = userModel.Facebook; user.IsApproved = userModel.IsApproved; user.IsLockedOut = userModel.IsLockedOut; user.IsBanned = userModel.IsBanned; user.Location = userModel.Location; user.PasswordAnswer = userModel.PasswordAnswer; user.PasswordQuestion = userModel.PasswordQuestion; user.Signature = userModel.Signature; user.Twitter = userModel.Twitter; user.UserName = userModel.UserName; user.Website = userModel.Website; user.DisableEmailNotifications = userModel.DisableEmailNotifications; user.DisablePosting = userModel.DisablePosting; user.DisablePrivateMessages = userModel.DisablePrivateMessages; try { unitOfWork.Commit(); ViewBag.Message = new GenericMessageViewModel { Message = "User saved", MessageType = GenericMessages.success }; } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Errors.GenericMessage")); } return ListUsers(null, null); } }