Beispiel #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;
            }
        }
Beispiel #2
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;
            }
        }
Beispiel #3
0
        public static bool Update(Branch branch)
        {
            try
            {
                Branch existingBranch = new Branch();
                using (var context = new KioskWebDBEntities())
                {
                    existingBranch = context.Branches
                                     .Include("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 KioskWebDBEntities())
                    {
                        context.Entry(existingBranch).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
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;
            }
        }
Beispiel #5
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;
            }
        }
Beispiel #6
0
        public static bool Update(Role role)
        {
            try
            {
                Role existingRole = new Role();
                using (var context = new KioskWebDBEntities())
                {
                    existingRole = context.Roles
                                   .Where(t => t.ID == role.ID)
                                   .FirstOrDefault();
                }

                if (existingRole != null)
                {
                    existingRole.Name = role.Name;

                    using (var context = new KioskWebDBEntities())
                    {
                        //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;
            }
        }
Beispiel #7
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;
            }
        }