コード例 #1
0
        public UserModel UpdateUser(UserModel user)
        {
            using (var context = new connected_usersContext())
            {
                Customers exist = context.Customers.Where(x => x.Name == user.UserName &&
                                                          x.Dob.Day.ToString("D2") + "/" + x.Dob.Month.ToString("D2") + "/" + x.Dob.Year == user.DOB).FirstOrDefault();

                if (exist == null || exist.CustomerId <= -1)
                {
                    return(null);
                }

                var verify = context.Users.Find(exist.CustomerId);
                if (verify != null || verify.UserId > -1)
                {
                    verify.RoleId = context.Roles.Where(x => x.RoleName == user.Role).Select(y => y.RoleId).FirstOrDefault();
                    context.SaveChanges();
                }
                else
                {
                    return(null);
                }

                return(user);
            }
        }
コード例 #2
0
        public bool AddUser(UserModel user, string createdPersonUserId)
        {
            using (var context = new connected_usersContext())
            {
                try
                {
                    int custID = context.Customers.Where(x => x.Name == user.UserName &&
                                                         x.Dob.Day.ToString("D2") + "/" + x.Dob.Month.ToString("D2") + "/" + x.Dob.Year == user.DOB).Select(x => x.CustomerId).FirstOrDefault();

                    context.Users.Add(new Users()
                    {
                        UserId      = custID,
                        Password    = "******",
                        RoleId      = user.RoleId,
                        CreatedBy   = Convert.ToInt32(createdPersonUserId),
                        CreatedTime = DateTime.Now,
                    });


                    context.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
        }
コード例 #3
0
        public bool DeleteUsers(Users user)
        {
            using (var context = new connected_usersContext())
            {
                var entity = context.Users.Find(user.UserId);
                if (entity == null)
                {
                    return(false);
                }


                context.Users.Remove(entity);
                context.SaveChanges();
                return(true);
            }
        }
コード例 #4
0
        public bool UpdatePassword(UpdatePasswordModel user, bool isReset)
        {
            using (var context = new connected_usersContext())
            {
                var entity = context.Users.Find(user.UserId);
                if (entity == null)
                {
                    return(false);
                }


                if (entity.UserId == user.UserId)
                {
                    if (isReset)
                    {
                        entity.Password = "******";
                    }
                    else if (entity.Password == user.oldPassword &&
                             user.newPassword == user.confirmPassword)
                    {
                        entity.Password = user.newPassword;
                    }
                    else
                    {
                        return(false);
                    }
                    context.SaveChanges();
                }
                else
                {
                    return(false);
                }
                //context.Customers.Update(cust);
                //context.SaveChanges();

                return(true);
            }
        }