Example #1
0
        public ActionResult Users(string sortOrder, string searchString)
        {
            ViewBag.Message            = "View/Edit all Users.";
            ViewBag.UserFNameSortParam = String.IsNullOrEmpty(sortOrder) ? "fname_desc" : "";
            ViewBag.UserLNameSortParam = sortOrder == "LName" ? "lname_desc" : "LName";
            ViewBag.UserMailSortParam  = sortOrder == "Mail" ? "mail_desc" : "Mail";

            List <SelectListItem> items = new List <SelectListItem>();

            items.Add(new SelectListItem {
                Text = "Active", Value = "0"
            });
            items.Add(new SelectListItem {
                Text = "Inactive", Value = "1"
            });

            ViewBag.ActiveList = items;

            UsersDataHandler   dataSource = new UsersDataHandler();
            ICollection <User> data       = dataSource.GetAllUsers();

            if (!string.IsNullOrEmpty(searchString))
            {
                data = data.Where(s => s.firstName.Contains(searchString) || s.lastName.Contains(searchString)).ToList();
            }

            switch (sortOrder)
            {
            case "fname_desc":
                data = data.OrderByDescending(s => s.firstName).ToList();
                break;

            case "LName":
                data = data.OrderBy(s => s.lastName).ToList();
                break;

            case "lname_desc":
                data = data.OrderByDescending(s => s.lastName).ToList();
                break;

            case "Mail":
                data = data.OrderBy(s => s.emailID).ToList();
                break;

            case "mail_desc":
                data = data.OrderByDescending(s => s.emailID).ToList();
                break;

            default:
                data = data.OrderBy(s => s.firstName).ToList();
                break;
            }

            ModelState.Clear();

            return(View(data));
        }
Example #2
0
        public ActionResult Users(string sortOrder, string searchString, User user, string ActiveList)
        {
            ViewBag.Message            = "View/Edit all Users.";
            ViewBag.UserFNameSortParam = String.IsNullOrEmpty(sortOrder) ? "fname_desc" : "";
            ViewBag.UserLNameSortParam = sortOrder == "LName" ? "lname_desc" : "LName";
            ViewBag.UserMailSortParam  = sortOrder == "Mail" ? "mail_desc" : "Mail";

            List <SelectListItem> items = new List <SelectListItem>();

            items.Add(new SelectListItem {
                Text = "Active", Value = "0"
            });
            items.Add(new SelectListItem {
                Text = "Inactive", Value = "1"
            });

            ViewBag.ActiveList = items;

            ErrorModel context  = new ErrorModel();
            User       thisUser = context.Users.FirstOrDefault(x => x.emailID == user.emailID);

            try
            {
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    var usertoSave = db.Users.ToList().FirstOrDefault(m => m.Email == thisUser.emailID);
                    if (ActiveList == "1")
                    {
                        usertoSave.LockoutEndDateUtc = DateTime.MaxValue;
                        thisUser.activeStatus        = "inactive";
                        thisUser.userType            = thisUser.userType;
                    }
                    else
                    {
                        usertoSave.LockoutEndDateUtc = null;
                        thisUser.activeStatus        = "active";
                        thisUser.userType            = thisUser.userType;
                    }
                    db.SaveChanges();
                }
                context.SaveChanges();
            }

            catch (Exception ex)
            {
                string s = ex.InnerException.Message;
            }

            UsersDataHandler   dataSource = new UsersDataHandler();
            ICollection <User> data       = dataSource.GetAllUsers();

            if (!String.IsNullOrEmpty(searchString))
            {
                data = data.Where(s => s.firstName.Contains(searchString) || s.lastName.Contains(searchString)).ToList();
            }

            switch (sortOrder)
            {
            case "fname_desc":
                data = data.OrderByDescending(s => s.firstName).ToList();
                break;

            case "LName":
                data = data.OrderBy(s => s.lastName).ToList();
                break;

            case "lname_desc":
                data = data.OrderByDescending(s => s.lastName).ToList();
                break;

            case "Mail":
                data = data.OrderBy(s => s.emailID).ToList();
                break;

            case "mail_desc":
                data = data.OrderByDescending(s => s.emailID).ToList();
                break;

            default:
                data = data.OrderBy(s => s.firstName).ToList();
                break;
            }

            ModelState.Clear();

            return(View(data));
        }