// GET: Positions
        public async Task <IActionResult> Index(int?page, int?pageSizeID)
        {
            var positions = _context.Positions
                            .Include(p => p.Occupation)
                            .Include(p => p.PositionSkills).ThenInclude(p => p.Skill)
                            .OrderBy(p => p.Name);
            int pageSize;//This is the value we will pass to PaginatedList

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 3 : pageSize;//Neither Selected or in Cookie so go with default
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Position> .CreateAsync(positions.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }
Example #2
0
        // GET: Skills
        public async Task <IActionResult> Index(int?page, int?pageSizeID)
        {
            //Clear the sort/filter/paging URL Cookie
            CookieHelper.CookieSet(HttpContext, "SkillsURL", "", -1);

            var skills = _context.Skills
                         .OrderBy(s => s.Name);

            //Handle Paging
            int pageSize;//This is the value we will pass to PaginatedList

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 5 : pageSize;//Neither Selected or in Cookie so go with default
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Skill> .CreateAsync(skills.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }
Example #3
0
        // GET: Roles
        public async Task <IActionResult> Index(int?page, int?pageSizeID)
        {
            var role = from r in _context.Roles
                       select r;
            //For Paging
            int pageSize;

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 5 : pageSize;
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Role> .CreateAsync(role.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }
Example #4
0
        // GET: Contacts
        public async Task <IActionResult> Index()
        {
            //Clear the sort/filter/paging URL Cookie
            CookieHelper.CookieSet(HttpContext, "ContactsURL", "", -1);
            IQueryable <Contact> query = _context.Contacts
                                         .Include(c => c.Company)
                                         .Include(c => c.ContactCategories).ThenInclude(c => c.Categories)
                                         .OrderBy(c => c.FirstName)
                                         .ThenBy(c => c.LastName);

            _gridFilter.ParseQuery(HttpContext);
            ViewBag.gridFilter       = _gridFilter;
            ViewData["CategoriesID"] = GetCategoriesSelectList();

            await _gridFilter.GetFilteredData(query);

            int countFilter = _gridFilter.OuterFields.Count;

            if (countFilter > 2)
            {
                ViewData["ChangeColor"] = 1;
            }
            else
            {
                ViewData["ChangeColor"] = 0;
            }

            return(View(await _gridFilter.GetFilteredData(query)));
        }
        // GET: Employees
        public async Task <IActionResult> Index()
        {
            //Clear the sort/filter/paging URL Cookie
            CookieHelper.CookieSet(HttpContext, "EmployeesURL", "", -1);

            var query = _context.Employees
                        .Include(e => e.EmployeeCountry)
                        .Include(e => e.EmployeeProvince)
                        .Include(e => e.EmploymentType)
                        .Include(e => e.JobPosition);

            _gridFilter.ParseQuery(HttpContext);
            ViewBag.gridFilter           = _gridFilter;
            ViewData["EmploymentTypeID"] = GetEmploymentTypesSelectList();
            ViewData["JobPositionID"]    = GetPositionsSelectList();

            await _gridFilter.GetFilteredData(query);

            int countFilter = _gridFilter.OuterFields.Count;

            if (countFilter > 2)
            {
                ViewData["ChangeColor"] = 1;
            }
            else
            {
                ViewData["ChangeColor"] = 0;
            }

            return(View(await _gridFilter.GetFilteredData(query)));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    var emp = _context.Employees.Where(e => e.Email == Input.Email).FirstOrDefault();
                    if (emp != null)
                    {
                        CookieHelper.CookieSet(HttpContext, "userName", emp.FullName, 3200);
                    }
                    else
                    {
                        //What better time to create the profile?
                        returnUrl = "~/EmployeeAccount/Create";
                    }
                    _logger.LogInformation("User logged in.");
                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Example #7
0
        // GET: Companies
        public async Task <IActionResult> Index()
        {
            //Clear the sort/filter/paging URL Cookie
            CookieHelper.CookieSet(HttpContext, "CompaniesURL", "", -1);

            IQueryable <Company> query = _context.Companies
                                         .Include(c => c.BillingCountry)
                                         .Include(c => c.BillingProvince)
                                         .Include(c => c.BillingTerm)
                                         .Include(c => c.ShippingCountry)
                                         .Include(c => c.ShippingProvince)
                                         //.Include(c => c.VendorType)
                                         .Include(c => c.CompanyCustomers).ThenInclude(c => c.CustomerType)
                                         .Include(c => c.CompanyContractors).ThenInclude(c => c.ContractorType)
                                         .Include(c => c.CompanyVendors).ThenInclude(c => c.VendorType)
                                         .OrderBy(c => c.Name);

            _gridFilter.ParseQuery(HttpContext);
            ViewBag.gridFilter             = _gridFilter;
            ViewData["CountryID"]          = GetCountriesSelectList();
            ViewData["ProvinceID"]         = GetProvincesSelectList();
            ViewData["DuplicationCompany"] = GetSimillarCompanies(await _context.Companies.OrderBy(c => c.CompanyID).Take(20).ToListAsync());
            //string urlcheck = _gridFilter.GetFilteredData(query).Ur
            await _gridFilter.GetFilteredData(query);

            int countFilter = _gridFilter.OuterFields.Count;

            if (countFilter > 2)
            {
                ViewData["ChangeColor"] = 1;
            }
            else
            {
                ViewData["ChangeColor"] = 0;
            }
            return(View(await _gridFilter.GetFilteredData(query)));
        }
Example #8
0
        // GET: Applicants
        public async Task <IActionResult> Index(string SearchName, string SearchPhone, string SearchEmail, int?page, int?pageSizeID,
                                                int?PostingID, int?SkillID, string actionButton, string sortDirection = "asc", string sortField = "Applicant")
        {
            //Prepare SelectLists for filters
            var dQuery = (from d in _context.Postings.Include(p => p.Position)
                          orderby d.Position.Name, d.ClosingDate
                          select d).ToList();

            ViewData["PostingID"] = new SelectList(dQuery, "ID", "PostingSummary");
            ViewData["SkillID"]   = new SelectList(_context.Skills.OrderBy(s => s.Name), "ID", "Name");
            ViewData["Filtering"] = "";  //Assume not filtering

            //Start with Includes
            var applicants = from a in _context.Applicants
                             .Include(a => a.RetrainingProgram)
                             .Include(d => d.ApplicantDocuments)
                             .Include(p => p.ApplicantPhoto).ThenInclude(p => p.FileContent)
                             .Include(a => a.ApplicantSkills)
                             .ThenInclude(a => a.Skill)
                             select a;

            //Add as many filters as needed
            if (SkillID.HasValue)
            {
                applicants            = applicants.Where(p => p.ApplicantSkills.Any(c => c.SkillID == SkillID));
                ViewData["Filtering"] = " show";
            }
            if (PostingID.HasValue)
            {
                applicants            = applicants.Where(p => p.Applications.Any(c => c.PostingID == PostingID));
                ViewData["Filtering"] = " show";
            }
            if (!String.IsNullOrEmpty(SearchName))
            {
                applicants = applicants.Where(p => p.LastName.ToUpper().Contains(SearchName.ToUpper()) ||
                                              p.FirstName.ToUpper().Contains(SearchName.ToUpper()));
                ViewData["Filtering"] = " show";
            }
            if (!String.IsNullOrEmpty(SearchEmail))
            {
                applicants            = applicants.Where(p => p.eMail.ToUpper().Contains(SearchEmail.ToUpper()));
                ViewData["Filtering"] = " show";
            }
            //Before we sort, see if we have called for a change of filtering or sorting
            if (!String.IsNullOrEmpty(actionButton)) //Form Submitted so lets sort!
            {
                page = 1;                            //Reset page to start

                if (actionButton != "Filter")        //Change of sort is requested
                {
                    if (actionButton == sortField)   //Reverse order on same field
                    {
                        sortDirection = sortDirection == "asc" ? "desc" : "asc";
                    }
                    sortField = actionButton;//Sort by the button clicked
                }
            }
            //Now we know which field and direction to sort by
            if (sortField == "eMail")
            {
                if (sortDirection == "asc")
                {
                    applicants = applicants
                                 .OrderBy(p => p.eMail);
                }
                else
                {
                    applicants = applicants
                                 .OrderByDescending(p => p.eMail);
                }
            }
            else if (sortField == "Phone")
            {
                if (sortDirection == "asc")
                {
                    applicants = applicants
                                 .OrderBy(p => p.Phone);
                }
                else
                {
                    applicants = applicants
                                 .OrderByDescending(p => p.Phone);
                }
            }
            else //Sorting by Applicant Name
            {
                if (sortDirection == "asc")
                {
                    applicants = applicants
                                 .OrderBy(p => p.LastName)
                                 .ThenBy(p => p.FirstName);
                }
                else
                {
                    applicants = applicants
                                 .OrderByDescending(p => p.LastName)
                                 .ThenByDescending(p => p.FirstName);
                }
            }
            //Set sort for next time
            ViewData["sortField"]     = sortField;
            ViewData["sortDirection"] = sortDirection;

            //Handle Paging
            int pageSize;//This is the value we will pass to PaginatedList

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 3 : pageSize;//Neither Selected or in Cookie so go with default
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Applicant> .CreateAsync(applicants.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }
Example #9
0
 private void UpdateUserNameCookie(string userName)
 {
     CookieHelper.CookieSet(HttpContext, "userName", userName, 960);
 }
Example #10
0
        // GET: PatientAppt
        public async Task <IActionResult> Index(int?PatientID, int?page, int?pageSizeID, int?ApptReasonID, string actionButton,
                                                string SearchString, string sortDirection = "desc", string sortField = "Appointment")
        {
            if (!PatientID.HasValue)
            {
                return(RedirectToAction("Index", "Patients"));
            }

            PopulateDropDownLists();
            ViewData["Filtering"] = "btn-outline-dark";

            //Get the URL with the last filter, sort and page parameters from the Patients Index View
            ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Patients");

            //Clear the sort/filter/paging URL Cookie for Patient Appointments Master/Details
            CookieHelper.CookieSet(HttpContext, "PatientApptURL", "", -1);

            var appts = from a in _context.Appointments.Include(a => a.ApptReason).Include(a => a.Patient)
                        where a.PatientID == PatientID.GetValueOrDefault()
                        select a;

            if (ApptReasonID.HasValue)
            {
                appts = appts.Where(p => p.ApptReasonID == ApptReasonID);
                ViewData["Filtering"] = "btn-danger";
            }
            if (!String.IsNullOrEmpty(SearchString))
            {
                appts = appts.Where(p => p.Notes.ToUpper().Contains(SearchString.ToUpper()));
                ViewData["Filtering"] = "btn-danger";
            }
            //Before we sort, see if we have called for a change of filtering or sorting
            if (!String.IsNullOrEmpty(actionButton)) //Form Submitted so lets sort!
            {
                page = 1;                            //Reset back to first page when sorting or filtering

                if (actionButton != "Filter")        //Change of sort is requested
                {
                    if (actionButton == sortField)   //Reverse order on same field
                    {
                        sortDirection = sortDirection == "asc" ? "desc" : "asc";
                    }
                    sortField = actionButton;//Sort by the button clicked
                }
            }
            //Now we know which field and direction to sort by, but a Switch is hard to use for 2 criteria
            //so we will use an if() structure instead.
            if (sortField.Contains("Reason"))
            {
                if (sortDirection == "asc")
                {
                    appts = appts
                            .OrderBy(p => p.ApptReason.ReasonName);
                }
                else
                {
                    appts = appts
                            .OrderByDescending(p => p.ApptReason.ReasonName);
                }
            }
            else //Date
            {
                if (sortDirection == "asc")
                {
                    appts = appts
                            .OrderByDescending(p => p.appDate);
                }
                else
                {
                    appts = appts
                            .OrderBy(p => p.appDate);
                }
            }
            //Set sort for next time
            ViewData["sortField"]     = sortField;
            ViewData["sortDirection"] = sortDirection;

            //Now get the MASTER record, the patient, so it can be displayed at the top of the screen
            Patient patient = _context.Patients
                              .Include(p => p.Doctor)
                              .Include(p => p.MedicalTrial)
                              .Include(p => p.PatientPhoto).ThenInclude(p => p.PhotoContentThumb)
                              .Include(p => p.PatientConditions).ThenInclude(pc => pc.Condition)
                              .Where(p => p.ID == PatientID.GetValueOrDefault()).FirstOrDefault();

            ViewBag.Patient = patient;

            //Handle Paging
            int pageSize;//This is the value we will pass to PaginatedList

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 3 : pageSize;//Neither Selected or in Cookie so go with default
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Appointment> .CreateAsync(appts.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }
Example #11
0
        // GET: Patients
        public async Task <IActionResult> Index(string SearchString, int?DoctorID, int?ConditionID,
                                                int?page, int?pageSizeID, string actionButton, string sortDirection = "asc", string sortField = "Patient")
        {
            ViewData["ConditionID"] = new SelectList(_context
                                                     .Conditions
                                                     .OrderBy(c => c.ConditionName), "ID", "ConditionName");
            PopulateDropDownLists();    //Data for Doctor Filter DDL
            ViewData["Filtering"] = ""; //Assume not filtering
            //Clear the sort/filter/paging URL Cookie
            CookieHelper.CookieSet(HttpContext, "PatientsURL", "", -1);

            //Start with Includes but make sure your expression returns an
            //IQueryable<Patient> so we can add filter and sort
            //options later.
            var patients = from p in _context.Patients
                           .Include(p => p.Doctor)
                           .Include(p => p.PatientPhoto).ThenInclude(p => p.PhotoContentThumb)
                           .Include(p => p.PatientConditions).ThenInclude(p => p.Condition)
                           select p;

            //Add as many filters as needed
            if (DoctorID.HasValue)
            {
                patients = patients.Where(p => p.DoctorID == DoctorID);
                ViewData["Filtering"] = " show";
            }
            if (!String.IsNullOrEmpty(SearchString))
            {
                patients = patients.Where(p => p.LastName.ToUpper().Contains(SearchString.ToUpper()) ||
                                          p.FirstName.ToUpper().Contains(SearchString.ToUpper()));
                ViewData["Filtering"] = " show";
            }
            if (ConditionID.HasValue)
            {
                patients = patients.Where(p => p.PatientConditions.Any(c => c.ConditionID == ConditionID));
                ViewData["Filtering"] = " show";
            }
            //Before we sort, see if we have called for a change of filtering or sorting
            if (!String.IsNullOrEmpty(actionButton)) //Form Submitted so lets sort!
            {
                page = 1;                            //Reset page to start

                if (actionButton != "Filter")        //Change of sort is requested
                {
                    if (actionButton == sortField)   //Reverse order on same field
                    {
                        sortDirection = sortDirection == "asc" ? "desc" : "asc";
                    }
                    sortField = actionButton;//Sort by the button clicked
                }
            }
            //Now we know which field and direction to sort by
            if (sortField == "Age")
            {
                if (sortDirection == "asc")
                {
                    patients = patients
                               .OrderByDescending(p => p.DOB);
                }
                else
                {
                    patients = patients
                               .OrderBy(p => p.DOB);
                }
            }
            else if (sortField == "Doctor")
            {
                if (sortDirection == "asc")
                {
                    patients = patients
                               .OrderBy(p => p.Doctor.LastName)
                               .ThenBy(p => p.Doctor.FirstName);
                }
                else
                {
                    patients = patients
                               .OrderByDescending(p => p.Doctor.LastName)
                               .ThenByDescending(p => p.Doctor.FirstName);
                }
            }
            else //Sorting by Patient Name
            {
                if (sortDirection == "asc")
                {
                    patients = patients
                               .OrderBy(p => p.LastName)
                               .ThenBy(p => p.FirstName);
                }
                else
                {
                    patients = patients
                               .OrderByDescending(p => p.LastName)
                               .ThenByDescending(p => p.FirstName);
                }
            }
            //Set sort for next time
            ViewData["sortField"]     = sortField;
            ViewData["sortDirection"] = sortDirection;

            //Handle Paging
            int pageSize;//This is the value we will pass to PaginatedList

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 3 : pageSize;//Neither Selected or in Cookie so go with default
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Patient> .CreateAsync(patients.AsNoTracking(), page ?? 1, pageSize);

            //Which version of the View based on Authorization
            if (User.IsInRole("Admin"))
            {
                return(View("IndexAdmin", pagedData));
            }
            else if (User.IsInRole("Supervisor"))
            {
                return(View("IndexSupervisor", pagedData));
            }
            else
            {
                return(View(pagedData));
            }
        }
Example #12
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    var users = _userManager.Users.Where(r => r.Email == Input.Email).FirstOrDefault();
                    var roles = _signInManager.UserManager.GetRolesAsync(users).Result;

                    var role = "";
                    foreach (var r in roles)
                    {
                        role = r;
                        break;
                    }

                    if (role == "Parent")
                    {
                        var user = _context.Users.Where(u => u.userEmail == Input.Email).FirstOrDefault();
                        if (user != null)
                        {
                            CookieHelper.CookieSet(HttpContext, "userName", user.FullName, 3200);
                        }
                        else
                        {
                            //What better time to create the profile?
                            returnUrl = "~/UsersProfile/Create";
                        }
                    }
                    else if (role == "Instructor")
                    {
                        var leader = _context.Leaders.Where(l => l.leaderEmail == Input.Email).FirstOrDefault();
                        if (leader != null)
                        {
                            CookieHelper.CookieSet(HttpContext, "userName", leader.FullName, 3200);
                        }
                        else
                        {
                            //What better time to create the profile?
                            returnUrl = "~/LeadersProfile/Create";
                        }
                    }
                    _logger.LogInformation("User logged in.");
                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Example #13
0
        public async Task <IActionResult> Index(string QuickSearchName, string SearchName, string SearchProject, string SearchOrg, string SearchEmail,
                                                int?page, int?pageSizeID, string actionButton, string sortDirection = "asc", string sortField = "Customer")
        {
            var customers = from p in _context.Customers
                            .Include(p => p.Projects)
                            select p;

            ViewData["Filtering"] = "";

            CookieHelper.CookieSet(HttpContext, "CustomersURL", "", -1);


            if (!String.IsNullOrEmpty(SearchName))
            {
                customers = customers.Where(p => p.LastName.ToUpper().Contains(SearchName.ToUpper()) ||
                                            p.FirstName.ToUpper().Contains(SearchName.ToUpper()));
                ViewData["Filtering"] = "show";
            }

            if (!String.IsNullOrEmpty(SearchOrg))
            {
                customers             = customers.Where(p => p.OrgName.ToUpper().Contains(SearchOrg.ToUpper()));
                ViewData["Filtering"] = "show";
            }
            if (String.IsNullOrEmpty(SearchName))
            {
                if (!String.IsNullOrEmpty(QuickSearchName))
                {
                    customers = customers.Where(p => p.LastName.ToUpper().Contains(QuickSearchName.ToUpper()) ||
                                                p.FirstName.ToUpper().Contains(QuickSearchName.ToUpper()));
                }
            }


            if (!String.IsNullOrEmpty(SearchEmail))
            {
                customers             = customers.Where(p => p.Email.ToUpper().Contains(SearchEmail.ToUpper()));
                ViewData["Filtering"] = "show";
            }

            if (!String.IsNullOrEmpty(SearchProject))
            {
                customers             = customers.Where(p => p.Projects.Any(m => m.Name.ToLower().Contains(SearchProject.ToLower())));
                ViewData["Filtering"] = "show";
            }

            if (!String.IsNullOrEmpty(actionButton))
            {
                if (actionButton != "Filter")
                {
                    if (actionButton == sortField)
                    {
                        sortDirection = sortDirection == "asc" ? "desc" : "asc";
                    }
                    sortField = actionButton;
                }
            }

            if (sortField == "Projects")
            {
                if (sortDirection == "asc")
                {
                    customers = customers
                                .OrderByDescending(p => p.Projects.FirstOrDefault(m => m.CustomerID == p.ID));
                }
                else
                {
                    customers = customers
                                .OrderBy(p => p.Projects.FirstOrDefault(m => m.CustomerID == p.ID));
                }
            }
            else if (sortField.Contains("Customer"))
            {
                if (sortDirection == "asc")
                {
                    customers = customers
                                .OrderBy(p => p.LastName)
                                .ThenBy(p => p.FirstName);
                }
                else
                {
                    customers = customers
                                .OrderByDescending(p => p.LastName)
                                .ThenByDescending(p => p.FirstName);
                }
            }
            else
            {
                if (sortDirection == "asc")
                {
                    customers = customers
                                .OrderBy(p => p.OrgName);
                }
                else
                {
                    customers = customers
                                .OrderByDescending(p => p.OrgName);
                }
            }
            //Set sort for next time
            ViewData["sortField"]     = sortField;
            ViewData["sortDirection"] = sortDirection;

            //For Paging
            int pageSize;

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ?5 : pageSize;
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Customer> .CreateAsync(customers.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }
Example #14
0
        // GET: ProductTypes
        public async Task <IActionResult> Index(string SearchByName,
                                                int?page, int?pageSizeID, string actionButton, string sortDirection = "asc", string sortField = "Name")
        {
            var productTypes = from b in _context.ProductTypes select b;

            ViewData["Filtering"] = ""; //Assume not filtering

            //Clear the sort/filter/paging URL Cookie
            CookieHelper.CookieSet(HttpContext, "CustomersURL", "", -1);


            if (!String.IsNullOrEmpty(SearchByName))
            {
                productTypes          = productTypes.Where(p => p.Name.ToUpper().Contains(SearchByName.ToUpper()));
                ViewData["Filtering"] = "show";
            }

            //Before we sort, see if we have called for a change of filtering or sorting
            if (!String.IsNullOrEmpty(actionButton))
            {
                page = 1;//Reset page to start
                if (actionButton != "Filter")
                {
                    if (actionButton == sortField)
                    {
                        sortDirection = sortDirection == "asc" ? "desc" : "asc";
                    }
                    sortField = actionButton;
                }
            }

            if (sortField == "Name")
            {
                if (sortDirection == "asc")
                {
                    productTypes = productTypes
                                   .OrderBy(p => p.Name);
                }
                else
                {
                    productTypes = productTypes
                                   .OrderByDescending(p => p.Name);
                }
            }

            //Set sort for next time
            ViewData["sortField"]     = sortField;
            ViewData["sortDirection"] = sortDirection;

            //For Paging
            int pageSize;

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 5 : pageSize;
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <ProductType> .CreateAsync(productTypes.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }
Example #15
0
        public async Task <IActionResult> Index(string QuickSearchName, string SearchProjectName, string BidAmountBelow, string BidAmountAbove,
                                                string EstStartDateAbove, string EstStartDateBelow, string EstFinishDateBelow, string EstFinishDateAbove,
                                                int?BidstatusID, int?DesignerStatusID, int?ClientStatusID, int?DesignerID, int?SalesAsscID,
                                                int?page, int?pageSizeID, string actionButton, string sortDirection = "asc", string sortField = "DateCreated")
        {
            var bids = from b in _context.Bids
                       .Include(b => b.BidStatus)
                       .Include(b => b.Designer)
                       .Include(b => b.BidLabours).ThenInclude(b => b.Role)
                       .Include(b => b.SalesAsscociate)
                       .Include(b => b.Project).ThenInclude(p => p.Customer)
                       .Include(b => b.BidProducts)
                       .Include(b => b.BidLabours)
                       .Include(b => b.Approval).ThenInclude(b => b.ApprovalStatuses)
                       select b;

            ViewData["Filtering"] = ""; //Assume not filtering

            //DDL
            ViewData["BidstatusID"] = new SelectList(_context
                                                     .BidStatuses
                                                     .OrderBy(c => c.Name), "ID", "Name");

            ViewData["DesignerStatusID"] = new SelectList(_context
                                                          .ApprovalStatuses
                                                          .OrderBy(c => c.Name), "ID", "Name");

            ViewData["ClientStatusID"] = new SelectList(_context
                                                        .ApprovalStatuses
                                                        .OrderBy(c => c.Name), "ID", "Name");

            ViewData["DesignerID"] = new SelectList(_context
                                                    .Employees.Where(p => p.Role.Name == "Designer")
                                                    .OrderBy(c => c.LastName), "ID", "FullName");

            ViewData["SalesAsscID"] = new SelectList(_context
                                                     .Employees.Where(p => p.Role.Name == "Sales Associate")
                                                     .OrderBy(c => c.LastName), "ID", "FullName");


            //Clear the sort/filter/paging URL Cookie
            CookieHelper.CookieSet(HttpContext, "CustomersURL", "", -1);

            if (!String.IsNullOrEmpty(SearchProjectName))
            {
                bids = bids.Where(p => p.Project.Name.ToUpper().Contains(SearchProjectName.ToUpper()));
                ViewData["Filtering"] = "show";
            }

            if (String.IsNullOrEmpty(SearchProjectName))
            {
                if (!String.IsNullOrEmpty(QuickSearchName))
                {
                    bids = bids.Where(p => p.Project.Name.ToUpper().Contains(QuickSearchName.ToUpper()));
                }
            }

            //Estimated Amount
            if (!String.IsNullOrEmpty(BidAmountBelow))
            {
                bids = bids.Where(p => p.EstAmount < (double)Convert.ToDecimal(BidAmountBelow));
                ViewData["Filtering"] = "show";
            }

            if (!String.IsNullOrEmpty(BidAmountAbove))
            {
                bids = bids.Where(p => p.EstAmount > (double)Convert.ToDecimal(BidAmountAbove));
                ViewData["Filtering"] = "show";
            }

            // Est StartDates
            if (!String.IsNullOrEmpty(EstStartDateAbove))
            {
                bids = bids.Where(p => p.EstBidStartDate > Convert.ToDateTime(EstStartDateAbove));
                ViewData["Filtering"] = "show";
            }

            if (!String.IsNullOrEmpty(EstStartDateBelow))
            {
                bids = bids.Where(p => p.EstBidStartDate < Convert.ToDateTime(EstStartDateBelow));
                ViewData["Filtering"] = "show";
            }

            //Est Finish Date
            if (!String.IsNullOrEmpty(EstFinishDateBelow))
            {
                bids = bids.Where(p => p.EstBidEndDate < Convert.ToDateTime(EstFinishDateBelow));
                ViewData["Filtering"] = "show";
            }

            if (!String.IsNullOrEmpty(EstFinishDateAbove))
            {
                bids = bids.Where(p => p.EstBidEndDate > Convert.ToDateTime(EstFinishDateAbove));
                ViewData["Filtering"] = "show";
            }

            // BidStatus
            if (BidstatusID.HasValue)
            {
                bids = bids.Where(p => p.BidStatusID == BidstatusID);
                ViewData["Filtering"] = " show";
            }

            //Designer
            if (DesignerID.HasValue)
            {
                bids = bids.Where(p => p.DesignerID == DesignerID);
                ViewData["Filtering"] = " show";
            }

            //Sales Associate
            if (SalesAsscID.HasValue)
            {
                bids = bids.Where(p => p.SalesAsscociateID == SalesAsscID);
                ViewData["Filtering"] = " show";
            }


            // DesignerStatus
            if (DesignerStatusID.HasValue)
            {
                bids = bids.Where(p => p.Approval.DesignerStatusID == DesignerStatusID);
                ViewData["Filtering"] = " show";
            }

            // ClientStatus
            if (ClientStatusID.HasValue)
            {
                bids = bids.Where(p => p.Approval.ClientStatusID == ClientStatusID);
                ViewData["Filtering"] = " show";
            }

            //Before we sort, see if we have called for a change of filtering or sorting
            if (!String.IsNullOrEmpty(actionButton))
            {
                if (actionButton != "Filter")
                {
                    if (actionButton == sortField)
                    {
                        sortDirection = sortDirection == "asc" ? "desc" : "asc";
                    }
                    sortField = actionButton;
                }
            }

            if (sortField.Contains("DateCreated")) //Sort By product type:Name
            {
                if (sortDirection == "asc")
                {
                    bids = bids
                           .OrderBy(p => p.DateCreated);
                }
                else
                {
                    bids = bids
                           .OrderByDescending(p => p.DateCreated);
                }
            }

            else if (sortField == "Project")
            {
                if (sortDirection == "asc")
                {
                    bids = bids
                           .OrderBy(p => p.Project.Name);
                }
                else
                {
                    bids = bids
                           .OrderByDescending(p => p.Project.Name);
                }
            }
            else if (sortField == "Organization")
            {
                if (sortDirection == "asc")
                {
                    bids = bids
                           .OrderBy(p => p.Project.Customer.OrgName);
                }
                else
                {
                    bids = bids
                           .OrderByDescending(p => p.Project.Customer.OrgName);
                }
            }
            else if (sortField == "Designer")
            {
                if (sortDirection == "asc")
                {
                    bids = bids
                           .OrderBy(p => p.Designer.LastName)
                           .ThenBy(p => p.Designer.FirstName);
                }
                else
                {
                    bids = bids
                           .OrderByDescending(p => p.Designer.LastName)
                           .ThenByDescending(p => p.Designer.FirstName);
                }
            }

            else
            {
                if (sortDirection == "asc")
                {
                    bids = bids
                           .OrderBy(p => p.EstAmount);
                }
                else
                {
                    bids = bids
                           .OrderByDescending(p => p.EstAmount);
                }
            }
            //Set sort for next time
            ViewData["sortField"]     = sortField;
            ViewData["sortDirection"] = sortDirection;


            //For Paging
            int pageSize;

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 5 : pageSize;
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Bid> .CreateAsync(bids.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }
Example #16
0
        public async Task <IActionResult> Index(string QuickSearchName, string SearchProdCode, string SearchProdSize, int?ProductTypeID,
                                                int?page, int?pageSizeID, string actionButton, string sortDirection = "asc", string sortField = "Price")
        {
            //Start with Includes
            var products = from b in _context.Products
                           .Include(b => b.ProductType)
                           select b;



            // PopulateDropDownLists1(); //Data for ProductType filter DDL
            ViewData["ProductTypeID"] = new SelectList(_context
                                                       .ProductTypes
                                                       .OrderBy(c => c.Name), "ID", "Name");

            ViewData["Filtering"] = ""; //Assume not filtering

            //Clear the sort/filter/paging URL Cookie
            CookieHelper.CookieSet(HttpContext, "CustomersURL", "", -1);

            if (!String.IsNullOrEmpty(SearchProdCode))
            {
                products = products.Where(p => p.Code.ToUpper().Contains(SearchProdCode.ToUpper()));
                ViewData["Filtering"] = "show";
            }

            if (String.IsNullOrEmpty(SearchProdCode))
            {
                if (!String.IsNullOrEmpty(QuickSearchName))
                {
                    products = products.Where(p => p.Code.ToUpper().Contains(QuickSearchName.ToUpper()));
                }
            }

            if (!String.IsNullOrEmpty(SearchProdSize))
            {
                products = products.Where(p => p.size.Contains(SearchProdSize));
                ViewData["Filtering"] = "show";
            }

            if (ProductTypeID.HasValue)
            {
                products = products.Where(p => p.ProductTypeID == ProductTypeID);
                ViewData["Filtering"] = " show";
            }


            //Before we sort, see if we have called for a change of filtering or sorting
            if (!String.IsNullOrEmpty(actionButton))
            {
                if (actionButton != "Filter")
                {
                    if (actionButton == sortField)
                    {
                        sortDirection = sortDirection == "asc" ? "desc" : "asc";
                    }
                    sortField = actionButton;
                }
            }

            else if (sortField == "Description")
            {
                if (sortDirection == "asc")
                {
                    products = products
                               .OrderBy(p => p.Description);
                }
                else
                {
                    products = products
                               .OrderByDescending(p => p.Description);
                }
            }
            else if (sortField == "Price")
            {
                if (sortDirection == "asc")
                {
                    products = products
                               .OrderBy(p => p.Price);
                }
                else
                {
                    products = products
                               .OrderByDescending(p => p.Price);
                }
            }

            else //Sort By product type:Name
            {
                if (sortDirection == "asc")
                {
                    products = products
                               .OrderBy(p => p.ProductType.Name);
                }
                else
                {
                    products = products
                               .OrderByDescending(p => p.ProductType.Name);
                }
            }
            //Set sort for next time
            ViewData["sortField"]     = sortField;
            ViewData["sortDirection"] = sortDirection;

            //For Paging
            int pageSize;

            if (pageSizeID.HasValue)
            {
                //Value selected from DDL so use and save it to Cookie
                pageSize = pageSizeID.GetValueOrDefault();
                CookieHelper.CookieSet(HttpContext, "pageSizeValue", pageSize.ToString(), 30);
            }
            else
            {
                //Not selected so see if it is in Cookie
                pageSize = Convert.ToInt32(HttpContext.Request.Cookies["pageSizeValue"]);
            }
            pageSize = (pageSize == 0) ? 5 : pageSize;
            ViewData["pageSizeID"] =
                new SelectList(new[] { "3", "5", "10", "20", "30", "40", "50", "100", "500" }, pageSize.ToString());
            var pagedData = await PaginatedList <Product> .CreateAsync(products.AsNoTracking(), page ?? 1, pageSize);

            return(View(pagedData));
        }