public static bool ChangePassword(string username, string newHashedPassword) { try { User existingUser = new User(); using (var context = new PersoDBEntities()) { existingUser = context.Users .Where(t => t.Username == username) .FirstOrDefault(); } if (existingUser != null) { existingUser.HashedPassword = newHashedPassword; existingUser.FirstTime = false; using (var context = new PersoDBEntities()) { context.Entry(existingUser).State = EntityState.Modified; context.SaveChanges(); } return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }
public static bool Update(User user) { try { User existingUser = new User(); using (var context = new PersoDBEntities()) { existingUser = context.Users .Where(t => t.ID == user.ID) .FirstOrDefault(); } if (existingUser != null) { existingUser.Email = user.Email; existingUser.Gender = user.Gender; existingUser.PhoneNumber = user.PhoneNumber; existingUser.Lastname = user.Lastname; existingUser.Othernames = user.Othernames; existingUser.UserRole = user.UserRole; existingUser.UserBranch = user.UserBranch; using (var context = new PersoDBEntities()) { context.Entry(existingUser).State = EntityState.Modified; context.SaveChanges(); } return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }
public static bool UpdateStatus(long[] customerIDs, bool status) { try { var existingCustomer = new List <Customer>(); using (var context = new PersoDBEntities()) { existingCustomer = context.Customers .Where(t => customerIDs.Contains(t.ID)) .ToList(); } if (existingCustomer.Any()) { existingCustomer.ForEach(customer => { customer.Downloaded = status; using (var context = new PersoDBEntities()) { context.Entry(customer).State = EntityState.Modified; context.SaveChanges(); } }); return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }
public static bool Update(Branch branch) { try { Branch existingBranch = new Branch(); using (var context = new PersoDBEntities()) { existingBranch = context.Branches .Include(b => b.Users) .Where(t => t.ID == branch.ID) .FirstOrDefault(); } if (existingBranch != null) { existingBranch.Name = branch.Name; existingBranch.Code = branch.Code; existingBranch.Address = branch.Address; using (var context = new PersoDBEntities()) { context.Entry(existingBranch).State = EntityState.Modified; context.SaveChanges(); } return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }
public static bool Update(CardProfile cardProfile) { try { var existingCardProfile = new CardProfile(); using (var context = new PersoDBEntities()) { existingCardProfile = context.CardProfiles .Where(t => t.ID == cardProfile.ID) .FirstOrDefault(); } if (existingCardProfile != null) { existingCardProfile.Name = cardProfile.Name; existingCardProfile.CardType = cardProfile.CardType; existingCardProfile.CardBin = cardProfile.CardBin; existingCardProfile.CEDuration = cardProfile.CEDuration; using (var context = new PersoDBEntities()) { context.Entry(existingCardProfile).State = EntityState.Modified; context.SaveChanges(); } return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }
public static bool Update(Customer customer) { try { var existingCustomer = new Customer(); using (var context = new PersoDBEntities()) { existingCustomer = context.Customers .Where(t => t.ID == customer.ID) .FirstOrDefault(); } if (existingCustomer != null) { existingCustomer.Surname = customer.Surname; existingCustomer.Othernames = customer.Othernames; using (var context = new PersoDBEntities()) { context.Entry(existingCustomer).State = EntityState.Modified; context.SaveChanges(); } return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }
public static bool Update(Function function) { try { Function existingfunction = new Function(); using (var context = new PersoDBEntities()) { existingfunction = context.Functions .Where(t => t.ID == function.ID) .FirstOrDefault(); } if (existingfunction != null) { existingfunction.Name = function.Name; existingfunction.PageLink = function.PageLink; using (var context = new PersoDBEntities()) { context.Entry(existingfunction).State = EntityState.Modified; context.SaveChanges(); } return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }
public static bool IssueCustomerCard(Customer customer, out string errMsg) { try { var existingCustomer = new Customer(); using (var context = new PersoDBEntities()) { existingCustomer = context.Customers .Where(t => t.AccountNumber == customer.AccountNumber) .FirstOrDefault(); if (existingCustomer != null && existingCustomer.ID != 0) { if (existingCustomer.Card == null) { using (var transaction = context.Database.BeginTransaction()) { try { long cardid = 0; if (CardDL.Save(context, customer.Card, out cardid)) { existingCustomer.CustomerBranch = customer.CustomerBranch; existingCustomer.Downloaded = customer.Downloaded; existingCustomer.CustomerCard = cardid; context.Entry(existingCustomer).State = EntityState.Modified; context.SaveChanges(); transaction.Commit(); errMsg = string.Empty; return(true); } else { errMsg = "Request Failed"; transaction.Rollback(); return(false); } } catch (Exception e) { transaction.Rollback(); throw e; } } } else { errMsg = string.Format("Customer with account number: {0} has a card already", customer.AccountNumber); return(true); } } else { errMsg = string.Format("No customer found with account number: {0}", customer.AccountNumber); return(false); } } } catch (Exception ex) { throw ex; } }
public static bool Update(Role role) { try { Role existingRole = new Role(); using (var context = new PersoDBEntities()) { existingRole = context.Roles .Where(t => t.ID == role.ID) .FirstOrDefault(); } if (existingRole != null) { existingRole.Name = role.Name; using (var context = new PersoDBEntities()) { //Transaction block using (var transaction = context.Database.BeginTransaction()) { try { //Modifying just the property details context.Entry(existingRole).State = EntityState.Modified; context.SaveChanges(); //Delete existing role function of the role IEnumerable <RoleFunction> existingRoleFunctions = context.RoleFunctions.Include("Role") .Where(t => existingRole.ID.Equals(t.RoleID)) .ToList(); if (existingRoleFunctions != null && existingRoleFunctions.ToList().Count != 0) { context.RoleFunctions.RemoveRange(existingRoleFunctions); context.SaveChanges(); } //Adding new Role Functions List <RoleFunction> newRoleFunctions = new List <RoleFunction>(); foreach (RoleFunction function in role.RoleFunctions) { RoleFunction roleFunction = new RoleFunction(); roleFunction.RoleID = existingRole.ID; roleFunction.FunctionID = function.FunctionID; newRoleFunctions.Add(roleFunction); } if (newRoleFunctions != null && newRoleFunctions.Count != 0) { context.RoleFunctions.AddRange(newRoleFunctions); context.SaveChanges(); } //commit changes transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }