public Boolean CreateUser(ref UserBDO userBDO, ref string message) { message = "User Added Successfully"; bool ret = true; UserType ut = new UserType() { UserType1 = userBDO.UserType.UsersType, UserTypeCode = userBDO.UserType.UserTypeCode }; User u = new User() { UserName = userBDO.UserName, Password = userBDO.Password, LastName = userBDO.LastName, FirstName = userBDO.FirstName, MiddleName = userBDO.MiddleName, UserTypeCode = userBDO.UserType.UserTypeCode, UserType = ut }; using (var DCEnt = new DCFIEntities()) { DCEnt.Users.Attach(u); DCEnt.Entry(u).State = System.Data.Entity.EntityState.Added; int num = DCEnt.SaveChanges(); userBDO.UserId = u.UserId; if (num != 1) { ret = false; message = "Adding of User failed"; } } return ret; }
public UserBDO GetUserBDO(int userId) { UserBDO userBDO = null; UserTypeBDO utype = null; using (var DCEnt = new DCFIEntities()) { User user = (from u in DCEnt.Users where u.UserId == userId select u).FirstOrDefault(); if (user != null) { utype = new UserTypeBDO() { UserTypeCode = user.UserTypeCode }; userBDO = new UserBDO() { UserId = user.UserId, UserName = user.UserName, Password = user.Password, LastName = user.LastName, FirstName = user.UserName, MiddleName = user.MiddleName, UserType = utype }; } } return userBDO; }
public Boolean CreateUser(ref User user, ref string message) { message = String.Empty; UserBDO userBDO = new UserBDO(); TranslateUserDTOToUserBDO(user, userBDO); return userLogic.CreateUser(ref userBDO, ref message); }
public User GetUser(string username) { UserBDO ubdo = new UserBDO(); ubdo = userLogic.GetUser(username); User u = new User(); TranslateUserBDOToUserDTO(ubdo, u); return u; }
public Boolean CreateUser(ref UserBDO userBDO, ref string message) { Boolean ret = false; UserBDO uBDO = GetUser(userBDO.UserName); if (uBDO == null) ret = userDAO.CreateUser(ref userBDO, ref message); else message = "Username already exists. Please select another username"; return ret; }
public Boolean AuthenticateUser(string username, string password, ref string message) { Boolean ret = false; UserBDO userBDO = new UserBDO(); message = "Username and Password do not match "; userBDO = GetUser(username); if (ComparePasswords(userBDO.Password, password)) { message = "WELCOME " + username; ret = true; } return ret; }
public Boolean CreateUser(ref UserBDO userBDO, ref string message) { message = "User Added Successfully"; bool ret = true; UserType ut = new UserType() { UserType1 = userBDO.UserType.UsersType, UserTypeCode = userBDO.UserType.UserTypeCode }; User u = new User() { UserName = userBDO.UserName, Password = userBDO.Password, LastName = userBDO.LastName, FirstName = userBDO.FirstName, MiddleName = userBDO.MiddleName, UserTypeCode = userBDO.UserType.UserTypeCode, UserType = ut }; try { using (var DCEnt = new DCFIEntities()) { DCEnt.Users.Attach(u); DCEnt.Entry(u).State = System.Data.Entity.EntityState.Added; int num = DCEnt.SaveChanges(); userBDO.UserId = u.UserId; if (num != 1) { ret = false; message = "Adding of User failed"; } } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return ret; }
public Boolean AuthenticateUser(string username, string password, ref string message) { Boolean ret = false; UserBDO userBDO = new UserBDO(); message = "Incorrect Username/Password"; userBDO = GetUser(username); if (userBDO != null) { if (ComparePasswords(userBDO.Password, password)) { message = "WELCOME " + username; ret = true; } } return ret; }
public UserBDO GetUserBDO(int userId) { UserBDO userBDO = null; UserTypeBDO utype = null; try { using (var DCEnt = new DCFIEntities()) { User user = (from u in DCEnt.Users where u.UserId == userId select u).FirstOrDefault(); if (user != null) { utype = new UserTypeBDO() { UserTypeCode = user.UserTypeCode }; userBDO = new UserBDO() { UserId = user.UserId, UserName = user.UserName, Password = user.Password, LastName = user.LastName, FirstName = user.UserName, MiddleName = user.MiddleName, UserType = utype }; } } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return userBDO; }
public List<UserBDO> GetAllUsers() { List<User> userList = new List<User>(); using (var DCEnt = new DCFIEntities()) { var allUsers = (DCEnt.Users); userList = allUsers.ToList<User>(); } List<UserBDO> userBDOList = new List<UserBDO>(); foreach (User u in userList) { UserBDO userBDO = new UserBDO(); ConvertUserToUserBDO(u,userBDO); userBDOList.Add(userBDO); } return userBDOList; }
public Boolean UpdateUser(ref UserBDO userBDO, ref string message) { message = "User updated successfully."; Boolean ret = true; using (var DCEnt = new DCFIEntities()) { var userID = userBDO.UserId; User userInDB = (from u in DCEnt.Users where u.UserId == userID select u).FirstOrDefault(); if (userInDB == null) { throw new Exception("No user with ID " + userBDO.UserId); } DCEnt.Users.Remove(userInDB); UserType ut = new UserType(); ut.UserTypeCode = userBDO.UserType.UserTypeCode; ut.UserType1 = userBDO.UserType.UsersType; userInDB.LastName = userBDO.LastName; userInDB.FirstName = userBDO.FirstName; userInDB.MiddleName = userBDO.MiddleName; userInDB.UserName = userBDO.UserName; userInDB.Password = userBDO.Password; userInDB.Deactivated = userBDO.Deactivated; userInDB.UserTypeCode = ut.UserTypeCode; DCEnt.Users.Attach(userInDB); DCEnt.Entry(userInDB).State = System.Data.Entity.EntityState.Modified; int num = DCEnt.SaveChanges(); if (num != 1) { ret = false; message = "No user is updated."; } } return ret; }
private void ConvertUserToUserBDO(User user, UserBDO userBDO) { UserTypeBDO ut = new UserTypeBDO(); ut.UserTypeCode = user.UserTypeCode; userBDO.UserId = user.UserId; userBDO.FirstName = user.FirstName; userBDO.LastName = user.LastName; userBDO.MiddleName = user.MiddleName; userBDO.UserName = user.UserName; userBDO.Password = user.Password; userBDO.Deactivated = user.Deactivated; userBDO.UserType = ut; }
public void TranslateUserBDOToUserDTO(UserBDO userBDO, User user) { user.UserId = userBDO.UserId; user.FirstName = userBDO.FirstName; user.LastName = userBDO.LastName; user.MiddleName = userBDO.MiddleName; user.UserName = userBDO.UserName; user.Password = userBDO.Password; user.UserTypeCode = userBDO.UserType.UserTypeCode; }
public void TranslateUserDTOToUserBDO(User user, UserBDO userBDO) { UserTypeBDO ut = new UserTypeBDO(); ut.UserTypeCode = user.UserTypeCode; userBDO.UserId = user.UserId; userBDO.FirstName = user.FirstName; userBDO.LastName = user.LastName; userBDO.MiddleName = user.MiddleName; userBDO.UserName = user.UserName; userBDO.Password = user.Password; userBDO.UserType = ut; }
public Boolean UpdateUser(ref UserBDO userBDO, ref string message) { if (UserExists(userBDO.UserId)) return userDAO.UpdateUser(ref userBDO, ref message); else { message = "Cannot get user for this ID"; return false; } }
public List<UserBDO> GetAllUsers() { List<User> userList = new List<User>(); List<UserBDO> userBDOList = new List<UserBDO>(); try { using (var DCEnt = new DCFIEntities()) { var allUsers = (DCEnt.Users); userList = allUsers.ToList<User>(); } foreach (User u in userList) { UserBDO userBDO = new UserBDO(); ConvertUserToUserBDO(u,userBDO); userBDOList.Add(userBDO); } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return userBDOList; }