Beispiel #1
0
        public static bool BranchExists(Branch branch)
        {
            try
            {
                var existingBranch = new Branch();
                using (var context = new PersoDBEntities())
                {
                    existingBranch = context.Branches
                                     .Include(b => b.Users)
                                     .Where(t => t.Name.Equals(branch.Name) || t.Code.Equals(branch.Code))
                                     .FirstOrDefault();
                }

                if (existingBranch == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public static bool CustomerExists(Customer customer)
        {
            try
            {
                var existingCustomer = new Customer();
                using (var context = new PersoDBEntities())
                {
                    existingCustomer = context.Customers
                                       .Where(t => t.Surname.Equals(customer.Surname) && t.Othernames.Equals(customer.Othernames))
                                       .FirstOrDefault();
                }

                if (existingCustomer == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public static bool RoleExists(Role role)
        {
            try
            {
                var existingRole = new Role();
                using (var context = new PersoDBEntities())
                {
                    existingRole = context.Roles
                                   .Where(t => t.Name.Equals(role.Name))
                                   .FirstOrDefault();
                }

                if (existingRole == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        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;
            }
        }
Beispiel #5
0
        public static bool FunctionExists(Function function)
        {
            try
            {
                var existingFunction = new Function();
                using (var context = new PersoDBEntities())
                {
                    existingFunction = context.Functions
                                       .Where(t => t.Name.Equals(function.Name))
                                       .FirstOrDefault();
                }

                if (existingFunction == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #6
0
        public static bool UserExists(User user)
        {
            try
            {
                var existingUser = new User();
                using (var context = new PersoDBEntities())
                {
                    existingUser = context.Users
                                   .Where(t => t.Username.Equals(user.Username))
                                   .FirstOrDefault();
                }

                if (existingUser == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #7
0
 public static bool Save(PersoDBEntities context, Card card, out long savedCardID)
 {
     try
     {
         context.Cards.Add(card);
         context.SaveChanges();
         savedCardID = card.ID;
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #8
0
 public static bool Save(Branch branch)
 {
     try
     {
         using (var context = new PersoDBEntities())
         {
             context.Branches.Add(branch);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #9
0
        public static List <Function> RetrieveFunctions()
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var functions = context.Functions.ToList();

                    return(functions);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #10
0
 public static bool Save(Function function)
 {
     try
     {
         using (var context = new PersoDBEntities())
         {
             context.Functions.Add(function);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #11
0
        public static List <CardProfile> RetrieveCardProfiles()
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var cardProfiles = context.CardProfiles.ToList();

                    return(cardProfiles);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #12
0
 public static bool Save(CardProfile cardProfile)
 {
     try
     {
         using (var context = new PersoDBEntities())
         {
             context.CardProfiles.Add(cardProfile);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #13
0
 public static bool Save(User user)
 {
     try
     {
         using (var context = new PersoDBEntities())
         {
             context.Users.Add(user);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #14
0
        public static Customer RetrieveCustomer(string accountnumber)
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var customers = context.Customers
                                    .Where(c => c.AccountNumber == accountnumber);

                    return(customers.Any() ? customers.FirstOrDefault() : null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #15
0
        public static Function RetrieveFunctionByID(long functionID)
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var function = context.Functions
                                   .Where(f => f.ID == functionID);

                    return(function.FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #16
0
        public static List <Customer> RetrieveCustomers()
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var customers = context.Customers
                                    .ToList();

                    return(customers);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #17
0
        public static CardProfile RetrieveCardProfileByID(long id)
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var cardProfiles = context.CardProfiles
                                       .Where(f => f.ID == id);

                    return(cardProfiles.Any() ? cardProfiles.FirstOrDefault() : null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #18
0
        public static List <Branch> RetrieveBranches()
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var branches = context.Branches
                                   .Include(b => b.Users)
                                   .ToList();

                    return(branches);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #19
0
        public static Branch RetrieveBranchByID(long?branchID)
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var branches = context.Branches
                                   .Include(b => b.Users)
                                   .Where(f => f.ID == branchID);

                    return(branches.FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #20
0
        public static List <Role> RetrieveRoles()
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var roles = context.Roles
                                .Include(r => r.RoleFunctions.Select(rf => rf.Function))
                                .ToList();

                    return(roles);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #21
0
        public static Role RetrieveRoleByID(long?roleID)
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var role = context.Roles
                               .Where(r => r.ID == roleID)
                               .Include(r => r.RoleFunctions.Select(rf => rf.Function))
                               .ToList().FirstOrDefault();

                    return(role);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #22
0
        public static User AuthenticateUser(string username, string hashedPassword)
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var users = context.Users
                                .Include("Branch")
                                .Include("Role.RoleFunctions.Function")
                                .Where(f => f.Username == username && f.HashedPassword == hashedPassword);

                    return(users.FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #23
0
        public static List <User> RetrieveUsers()
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var users = context.Users
                                .Include("Branch")
                                .Include("Role.RoleFunctions.Function")
                                .ToList();

                    return(users);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #24
0
        public static User RetrieveUser()
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var existingUser = context.Users
                                       .Include("Branch")
                                       .Include("Role.RoleFunctions.Function")
                                       .OrderByDescending(u => u.ID)
                                       .Take(1);

                    return(existingUser.Any() ? existingUser.FirstOrDefault() : null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #25
0
        public static User RetrieveUserByUsername(string username)
        {
            try
            {
                var existingUser = new User();
                using (var context = new PersoDBEntities())
                {
                    existingUser = context.Users
                                   .Where(t => t.Username.Equals(username))
                                   .Include(x => x.Branch)
                                   .FirstOrDefault();
                }

                return(existingUser);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #26
0
        public static List <Customer> RetrieveCustomersByID(long[] id)
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var customers = context.Customers
                                    .Where(c => id.Contains(c.ID))
                                    .Include("Card")
                                    .Include("Card.CardProfile")
                                    .ToList();

                    return(customers);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #27
0
        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;
            }
        }
Beispiel #28
0
        public static List <Customer> RetrieveCustomerPersoData()
        {
            try
            {
                using (var context = new PersoDBEntities())
                {
                    var customers = context.Customers
                                    .Where(c => c.CustomerCard != null)
                                    .Include("Card")
                                    .Include("Card.CardProfile")

                                    .ToList();

                    return(customers);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #29
0
        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;
            }
        }
Beispiel #30
0
        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;
            }
        }