//register user public void RegisterNewUser(UsersViewModel userVM) { DBCarRent.User user = UserMapViewModelToModel(userVM); using (UsersRepository userRepository = new UsersRepository()) { userRepository.RegisterUser(user); } }
//update user public void UpdateUser(UsersViewModel userVM) { DBCarRent.User user = UserMapViewModelToModel(userVM); using (UsersRepository userRepository = new UsersRepository()) { var email = user.Email; userRepository.UpdateUser(email, user); } }
//get Users by id public UsersViewModel GetUserById(int id) { DBCarRent.User user = null; using (UsersRepository usersRepository = new UsersRepository()) { user = usersRepository.GetUserById(id); } return(UserMapModelToViewModel(user)); }
private AuthViewModel AuthMapModelToViewModel(DBCarRent.User user) { AuthViewModel userVM = new AuthViewModel(); userVM.Email = user.Email; userVM.IsAdmin = user.IsAdmin; return(userVM); }
//Model To ViewModel private UsersViewModel UserMapModelToViewModel(DBCarRent.User user) { UsersViewModel userVM = new UsersViewModel(); userVM.UserName = user.UserName; userVM.Password = user.Password; userVM.FullName = user.FullName; userVM.Email = user.Email; userVM.Sex = user.Sex; userVM.Passport = user.Passport; userVM.IsAdmin = user.IsAdmin; return(userVM); }
//ViewModel To Model private DBCarRent.User UserMapViewModelToModel(UsersViewModel userVM) { DBCarRent.User user = new DBCarRent.User(); user.UserName = userVM.UserName; user.Password = userVM.Password; user.FullName = userVM.FullName; user.Email = userVM.Email; user.Sex = userVM.Sex; user.Passport = userVM.Passport; user.IsAdmin = userVM.IsAdmin; return(user); }