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 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; }
private void ConvertUserTypeToUserTypeBDO(UserType u, UserTypeBDO userTypeBDO) { userTypeBDO.UserTypeCode = u.UserTypeCode; userTypeBDO.UsersType = u.UserType1; }
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; }