public static UserAccountModel GetUserAccount(int userId) { using (var _context = new bbbsDbContext()) { return(TransformHelpers.UserAccountToModel(_context.UserAccounts.FirstOrDefault(x => x.Id == userId))); } }
public static UserAccountModel GetUserByLogin(LoginRequestModel requestModel) { using (var _context = new bbbsDbContext()) { return(TransformHelpers.UserAccountToModel(_context.UserAccounts.FirstOrDefault( x => x.UserName == requestModel.UserName && x.Password == requestModel.Password ))); } }
public static List <UserAccountModel> GetUserAccountsByType(int typeId) { using (var _context = new bbbsDbContext()) { List <UserAccountModel> userAccountModels = new List <UserAccountModel>(); foreach (var userAccount in _context.UserAccounts.Where(x => x.UserTypeId == typeId).ToList()) { userAccountModels.Add(TransformHelpers.UserAccountToModel(userAccount)); } return(userAccountModels); } }
public static UserAccountModel UpdateUserAccount(UserAccountModel userModel) { using (var _context = new bbbsDbContext()) { var existingUser = _context.UserAccounts.FirstOrDefault(x => x.Id == userModel.Id); if (existingUser != null) { existingUser.FirstName = userModel.FirstName; existingUser.LastName = userModel.LastName; existingUser.UserName = userModel.UserName; existingUser.UserTypeId = userModel.UserTypeId; existingUser.Age = userModel.Age; _context.SaveChanges(); return(TransformHelpers.UserAccountToModel(existingUser)); } } return(null); }