Exemplo n.º 1
0
        public static bool ChangePassword(string username, string newPassword)
        {
            try
            {
                string newHashedPassword = PasswordHash.MD5Hash(newPassword);

                User existingUser = new User();
                using (var context = new KioskWebDBEntities())
                {
                    existingUser = context.Users
                                    .Where(t => t.Username == username)
                                    .FirstOrDefault();
                }

                if (existingUser != null)
                {
                    existingUser.HashedPassword = newHashedPassword;
                    existingUser.FirstTime = false;

                    using (var context = new KioskWebDBEntities())
                    {
                        using (var transaction = context.Database.BeginTransaction())
                        {
                            context.Entry(existingUser).State = EntityState.Modified;
                            context.SaveChanges();

                            KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.User thirdPartyUser = new KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.User();

                            thirdPartyUser.UserName = username;
                            if (ThirdPartyDL.UserExists(thirdPartyUser))
                                ThirdPartyDL.ChangePassword(username, newPassword);

                            transaction.Commit();
                        }
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
 public static bool Save(Function function)
 {
     try
     {
         using (var context = new KioskWebDBEntities())
         {
             context.Functions.Add(function);
             context.SaveChanges();
         }
         return true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 3
0
        public static List<Function> RetrieveFunctions()
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var functions = context.Functions.ToList();

                    return functions;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
0
 public static bool Save(Role role)
 {
     try
     {
         using (var context = new KioskWebDBEntities())
         {
             context.Roles.Add(role);
             context.SaveChanges();
         }
         return true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 5
0
        public static User AuthenticateUser(string username, string hashedPassword)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var users = context.Users
                                        .Where(f => f.Username == username && f.HashedPassword == hashedPassword);

                    return users.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 6
0
        public static Function RetrieveFunctionByID(long functionID)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var function = context.Functions
                                            .Where(f => f.ID == functionID);

                    return function.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 7
0
        public static List<Role> RetrieveRoles()
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var roles = context.Roles
                                .Include(r => r.RoleFunctions.Select(rf => rf.Function))
                                .ToList();

                    return roles;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        public static List<Branch> RetrieveBranches()
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var branches = context.Branches
                                    .Include("Users")
                                    .ToList();

                    return branches;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 9
0
        public static Branch RetrieveBranchByID(long? branchID)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var branches = context.Branches
                                            .Include("Users")
                                            .Where(f => f.ID == branchID);

                    return branches.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 10
0
        public static Role RetrieveRoleByID(long? roleID)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var role = context.Roles
                                .Include(r => r.RoleFunctions.Select(rf => rf.Function))
                                .Where(r => r.ID == roleID)
                                .ToList().FirstOrDefault();

                    return role;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 11
0
        public static List<CardRequest> RetrieveCardRequest(long branchID)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var cardRequests = context.CardRequests
                                    .Where(x => x.PickupBranchID == branchID)
                                    .Include(cr => cr.Branch)
                                    .Include(cr => cr.Customer)
                                    .ToList();

                    return cardRequests;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 12
0
        public static bool CustomerCardRequestExists(string serialNumber)
        {
            try
            {
                var existingCardRequest = new CardRequest();
                using (var context = new KioskWebDBEntities())
                {
                    existingCardRequest = context.CardRequests
                                    .Where(t => t.SerialNumber.Equals(serialNumber))
                                    .FirstOrDefault();
                }

                if (existingCardRequest == null)
                    return false;
                else
                    return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 13
0
        public static bool FunctionExists(Function function)
        {
            try
            {
                var existingFunction = new Function();
                using (var context = new KioskWebDBEntities())
                {
                    existingFunction = context.Functions
                                    .Where(t => t.Name.Equals(function.Name))
                                    .FirstOrDefault();
                }

                if (existingFunction == null)
                    return false;
                else
                    return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 14
0
        public static bool RoleExists(Role role)
        {
            try
            {
                var existingRole = new Role();
                using (var context = new KioskWebDBEntities())
                {
                    existingRole = context.Roles
                                    .Where(t => t.Name.Equals(role.Name))
                                    .FirstOrDefault();
                }

                if (existingRole == null)
                    return false;
                else
                    return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 15
0
        public static bool CustomerExists(Customer customer)
        {
            try
            {
                var existingCustomer = new Customer();
                using (var context = new KioskWebDBEntities())
                {
                    existingCustomer = context.Customers
                                    .Where(t => t.EmailAddress.Equals(customer.EmailAddress))
                                    .FirstOrDefault();
                }

                if (existingCustomer == null)
                    return false;
                else
                    return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 16
0
        public static bool BranchExists(Branch branch)
        {
            try
            {
                var existingBranch = new Branch();
                using (var context = new KioskWebDBEntities())
                {
                    existingBranch = context.Branches
                                    .Include("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;
            }
        }
Exemplo n.º 17
0
        public static bool Update(Function function)
        {
            try
            {
                Function existingfunction = new Function();
                using (var context = new KioskWebDBEntities())
                {
                    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 KioskWebDBEntities())
                    {
                        context.Entry(existingfunction).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 18
0
        public static Customer RetrieveCustomerByID(long? customerID)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var customers = context.Customers
                                            .Where(f => f.ID == customerID);

                    return customers.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 19
0
        public static Customer RetrieveCustomerByAccountNumber(string accountNumber)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var customers = context.Customers
                                            .Where(f => f.AccountNumber == accountNumber);

                    return customers.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 20
0
 public static bool Save(Customer customer)
 {
     try
     {
         using (var context = new KioskWebDBEntities())
         {
             context.Customers.Add(customer);
             context.SaveChanges();
         }
         return true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 21
0
        public static List<Customer> RetrieveCustomers()
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var customers = context.Customers
                                    .ToList();

                    return customers;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 22
0
        public static bool SaveCardRequest(CardRequest cardRequest, string loggedInUsername, out CardRequest savedCardRequest)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    using (var transaction = context.Database.BeginTransaction())
                    {
                        context.CardRequests.Add(cardRequest);
                        context.SaveChanges();

                        KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.User thirdPartyUser = ThirdPartyDL.RetrieveUserByUsername(loggedInUsername);

                        Customer cardRequestCustomer = RetrieveCustomerByID(cardRequest.CustomerID);

                        KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.CardAccountRequest car = new ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.CardAccountRequest();

                        car.NameOnCard = string.Format("{0} {1}", cardRequestCustomer.Lastname, cardRequestCustomer.Othernames);

                        if (cardRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                        {
                            KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.PANDetail panDetail = ThirdPartyDL.RetrievePanDetailByAccountNumber(cardRequest.SerialNumber);

                            car.PAN = panDetail.pan;

                            ThirdPartyDL.UpdatePan(panDetail.pan);
                        }

                        car.PrintStatus = 1;
                        car.UserPrinting = thirdPartyUser.id.ToString();
                        car.DATE = System.DateTime.Now;
                        if (cardRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                            car.HolderIDNumber = cardRequest.SerialNumber;
                        car.PhoneNumber = cardRequestCustomer.PhoneNumber;
                        car.LastName = cardRequestCustomer.Lastname;
                        car.OtherName = cardRequestCustomer.Othernames;
                        car.emailaddress = cardRequestCustomer.EmailAddress;
                        car.Updateddate = System.DateTime.Now;
                        ThirdPartyDL.SaveCar(car);

                        cardRequest.Customer = cardRequestCustomer;

                        transaction.Commit();
                    }
                }
                cardRequest.Branch = BranchDL.RetrieveBranchByID(cardRequest.PickupBranchID);
                savedCardRequest = cardRequest;
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 23
0
        public static User RetrieveUserByUsername(string username)
        {
            try
            {
                var existingUser = new User();
                using (var context = new KioskWebDBEntities())
                {
                    existingUser = context.Users
                                    .Where(t => t.Username.Equals(username))
                                    .FirstOrDefault();
                }

                return existingUser;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 24
0
        public static bool UserExists(User user)
        {
            try
            {
                var existingUser = new User();
                using (var context = new KioskWebDBEntities())
                {
                    existingUser = context.Users
                                    .Where(t => t.Username.Equals(user.Username))
                                    .FirstOrDefault();
                }

                if (existingUser == null)
                    return false;
                else
                    return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 25
0
        public static bool Update(Customer customer)
        {
            try
            {
                Customer existingCustomer = new Customer();
                using (var context = new KioskWebDBEntities())
                {
                    existingCustomer = context.Customers
                                    .Where(t => t.ID == customer.ID)
                                    .FirstOrDefault();
                }

                if (existingCustomer != null)
                {
                    existingCustomer.Lastname = customer.Lastname;
                    existingCustomer.Othernames = customer.Othernames;
                    existingCustomer.EmailAddress = customer.EmailAddress;
                    existingCustomer.PhoneNumber = customer.PhoneNumber;

                    using (var context = new KioskWebDBEntities())
                    {
                        context.Entry(existingCustomer).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 26
0
        public static bool Update(User user)
        {
            try
            {
                User existingUser = new User();
                using (var context = new KioskWebDBEntities())
                {
                    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 KioskWebDBEntities())
                    {
                        context.Entry(existingUser).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 27
0
        public static bool Save(User user)
        {
            try
            {
                string password = user.HashedPassword;
                user.HashedPassword = PasswordHash.MD5Hash(password);
                using (var context = new KioskWebDBEntities())
                {
                    using (var transaction = context.Database.BeginTransaction())
                    {
                        context.Users.Add(user);
                        context.SaveChanges();

                        KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.User thirdPartyUser = new KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.User();

                        thirdPartyUser.UserName = user.Username;
                        thirdPartyUser.Password = password;
                        thirdPartyUser.UserType = "1";
                        thirdPartyUser.status = 1;
                        thirdPartyUser.OfficialEmail = user.Email;

                        if (!ThirdPartyDL.UserExists(thirdPartyUser))
                            ThirdPartyDL.Save(thirdPartyUser);

                        transaction.Commit();
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 28
0
        public static List<User> RetrieveUsers()
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var users = context.Users
                                        .Include("Branch")
                                        .Include("Role.RoleFunctions.Function")
                                        .ToList();

                    return users;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 29
0
        public static CardRequest RetrieveCardRequestByID(long? cardRequestID)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    var cardRequests = context.CardRequests
                                            .Include(x => x.Customer)
                                            .Include(x => x.Branch)
                                            .Where(f => f.ID == cardRequestID);

                    return cardRequests.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 30
0
        public static bool UpdateCardRequest(long cardRequestID, string clearPan, string loggedInUsername, out CardRequest cardRequest)
        {
            try
            {
                CardRequest existingRequest = new CardRequest();
                using (var context = new KioskWebDBEntities())
                {
                    existingRequest = context.CardRequests
                                    .Include(cr => cr.Customer)
                                    .Include(cr => cr.Branch)
                                    .Where(t => t.ID == cardRequestID)
                                    .FirstOrDefault();
                }

                if (existingRequest != null)
                {
                    if (existingRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                    {
                        existingRequest.HashedPan = PasswordHash.MD5Hash(clearPan);
                        existingRequest.EncryptedPan = Crypter.Encrypt(System.Configuration.ConfigurationManager.AppSettings.Get("ekey"), clearPan);
                    }
                    existingRequest.Status = StatusUtil.CardStatus.Approved.ToString();

                    using (var context = new KioskWebDBEntities())
                    {
                        using (var transaction = context.Database.BeginTransaction())
                        {
                            context.Entry(existingRequest).State = EntityState.Modified;
                            context.SaveChanges();

                            KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.User thirdPartyUser = ThirdPartyDL.RetrieveUserByUsername(loggedInUsername);

                            KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.CardAccountRequest car = new ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.CardAccountRequest();

                            car.NameOnCard = string.Format("{0} {1}", existingRequest.Customer.Lastname, existingRequest.Customer.Othernames);
                            if (existingRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                                car.PAN = clearPan;
                            car.PrintStatus = 1;
                            car.UserPrinting = thirdPartyUser.id.ToString();
                            car.DATE = System.DateTime.Now;
                            if (existingRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                                car.HolderIDNumber = existingRequest.SerialNumber;
                            car.PhoneNumber = existingRequest.Customer.PhoneNumber;
                            car.LastName = existingRequest.Customer.Lastname;
                            car.OtherName = existingRequest.Customer.Othernames;
                            car.emailaddress = existingRequest.Customer.EmailAddress;
                            car.Updateddate = System.DateTime.Now;
                            ThirdPartyDL.SaveCar(car);

                            ThirdPartyDL.UpdatePan(clearPan);

                            transaction.Commit();
                        }
                    }
                    cardRequest = existingRequest;
                    return true;
                }
                else
                {
                    cardRequest = null;
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }