public static User MapUserViewModelToUser(User user, UserViewModel userViewModel) { user.Email = userViewModel.Email; user.FirstName = userViewModel.FirstName; user.LastName = userViewModel.LastName; user.Address = userViewModel.Address; user.PhoneNumber = userViewModel.PhoneNumber; user.Id = userViewModel.Id; return user; }
public ActionResult UserProfile(string username = "******") { var userInfo = new User(); var userVM = new UserViewModel(); using (var context = new EventsDbContext()) { userInfo = context.Users.Where(u => u.UserName == username).FirstOrDefault(); userVM = ViewModelMapper.MapUserToUserViewModel(userInfo, userVM); } return View("Profile", userVM); }
public ActionResult UpdateProfile(UserViewModel userViewModel) { var userUpdated = new User(); using (var context = new EventsDbContext()) { var currentUser = context.Users.Find(userViewModel.Id); userUpdated = ViewModelMapper.MapUserViewModelToUser(currentUser, userViewModel); context.Entry(userUpdated).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return Redirect("http://localhost:15716/Users/MyProfile"); }
public ActionResult MyProfile() { User userInfo = new User(); var userVM = new UserViewModel(); using (var context = new EventsDbContext()) { //userInfo = data.Users.GetUserInfo(User.Identity.Name); userInfo = context.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); userVM = ViewModelMapper.MapUserToUserViewModel(userInfo, userVM); } return View("MyProfile", userVM); }
public async Task<ActionResult> UpdateProfileAsync(UserViewModel userViewModel) { await Task.Run(() => UpdateProfile(userViewModel)); return Redirect("http://localhost:15716/Users/MyProfile"); }