示例#1
0
        public static bool ChangePassword(string username, string newHashedPassword)
        {
            try
            {
                User existingUser = new User();
                using (var context = new LicenseDBEntities())
                {
                    existingUser = context.Users
                                   .Where(t => t.Username == username)
                                   .FirstOrDefault();
                }

                if (existingUser != null)
                {
                    existingUser.HashedPassword = newHashedPassword;
                    existingUser.FirstTime      = false;
                    using (var context = new LicenseDBEntities())
                    {
                        context.Entry(existingUser).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
 public static bool Save(List <PregeneratedCard> pregeneratedCards)
 {
     try
     {
         using (var context = new LicenseDBEntities())
         {
             context.PregeneratedCards.AddRange(pregeneratedCards);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
 public static bool Save(User user)
 {
     try
     {
         using (var context = new LicenseDBEntities())
         {
             context.Users.Add(user);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#4
0
 public static bool Save(Function function)
 {
     try
     {
         using (var context = new LicenseDBEntities())
         {
             context.Functions.Add(function);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#5
0
 public static bool Save(Branch branch)
 {
     try
     {
         using (var context = new LicenseDBEntities())
         {
             context.Branches.Add(branch);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static bool Update(CardAccountRequest car)
        {
            try
            {
                using (var context = new LicenseDBEntities())
                {
                    context.Entry(car).State = EntityState.Modified;
                    context.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public static bool Save(CardAccountRequest car, out long recordId)
 {
     try
     {
         using (var context = new LicenseDBEntities())
         {
             context.CardAccountRequests.Add(car);
             context.SaveChanges();
         }
         recordId = car.ID;
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#8
0
 public static bool Save(Fine fine, out long recordID)
 {
     try
     {
         using (var context = new LicenseDBEntities())
         {
             context.Fines.Add(fine);
             context.SaveChanges();
         }
         recordID = fine.ID;
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#9
0
        public static bool Update(User user)
        {
            try
            {
                User existingUser = new User();
                using (var context = new LicenseDBEntities())
                {
                    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 LicenseDBEntities())
                    {
                        context.Entry(existingUser).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#10
0
        public static bool Update(Branch branch)
        {
            try
            {
                Branch existingBranch = new Branch();
                using (var context = new LicenseDBEntities())
                {
                    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 LicenseDBEntities())
                    {
                        context.Entry(existingBranch).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#11
0
        public static bool Update(Function function)
        {
            try
            {
                Function existingfunction = new Function();
                using (var context = new LicenseDBEntities())
                {
                    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 LicenseDBEntities())
                    {
                        context.Entry(existingfunction).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool UpdateStatus(string cardSerialNumber, string licenseNumber, int printStatus, string userPrinting, string printedName)
        {
            try
            {
                bool result = false;

                using (var context = new LicenseDBEntities())
                {
                    using (var transaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            var car = context.CardAccountRequests
                                      .Where(x => x.LicenseID == licenseNumber).FirstOrDefault();


                            string key = System.Configuration.ConfigurationManager.AppSettings.Get("ekey");
                            string hashedCardNumber = PasswordHash.MD5Hash(cardSerialNumber);

                            if (car != null)
                            {
                                car.PrintStatus            = printStatus;
                                car.DatePrinted            = System.DateTime.Now;
                                car.UserPrinting           = userPrinting;
                                car.CardSerialNumber       = Crypter.Encrypt(key, cardSerialNumber);
                                car.HashedCardSerialNumber = hashedCardNumber;
                                car.PrintedName            = printedName;

                                context.Entry(car).State = EntityState.Modified;
                                context.SaveChanges();

                                var card = context.PregeneratedCards
                                           .Where(x => x.HashedCardNumber == hashedCardNumber).FirstOrDefault();

                                if (card != null)
                                {
                                    card.Status = true;

                                    context.Entry(card).State = EntityState.Modified;
                                    context.SaveChanges();

                                    result = true;
                                    transaction.Commit();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            throw ex;
                        }
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#13
0
        public static bool Update(Role role)
        {
            try
            {
                Role existingRole = new Role();
                using (var context = new LicenseDBEntities())
                {
                    existingRole = context.Roles
                                   .Where(t => t.ID == role.ID)
                                   .FirstOrDefault();
                }

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

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