public ActionResult Result(int statusCode, string message) { DashboardViewModel model = new DashboardViewModel(); string UserId = User.Identity.GetUserId(); LogicService cmLogic = new LogicService(); //Get jobs for user for dashboard view model model.ClientsForUser.ClientsToDisplay = cmLogic.GetClientsForUser(UserId); var jobsForUser = cmLogic.GetJobsForUser(UserId); //Remove any completed jobs var incompleteJobs = jobsForUser.Where(j => j.Complete == false).ToList(); //Remove any jobs with a start date greater than 30 days from now var upcomingJobs = incompleteJobs.Where(j => ((j.StartDate >= DateTime.Now) && (j.StartDate < DateTime.Now.AddDays(30)))).ToList(); //Sort jobs by start date List <jobDTO> sortedJobsForUser = new List <jobDTO>(); sortedJobsForUser = upcomingJobs.OrderBy(j => j.StartDate).ToList(); model.JobsForUser.JobsToDisplay = sortedJobsForUser; model.statusCode = statusCode; model.message = message; return(View(model)); }
public ActionResult ViewJob(int jobId) { string UserId = User.Identity.GetUserId(); var model = new JobViewModel(); LogicService cmLogic = new LogicService(); //Check if job is completed bool jobCompleted = cmLogic.JobCompletionStatus(jobId.ToString(), UserId); if (!jobCompleted) { //Acquire job from logic var jobsForUser = cmLogic.GetJobsForUser(UserId); var matchingJob = jobsForUser.Where(j => j.Id == jobId); if (matchingJob.Count() > 0) { var job = matchingJob.First(); model.ServiceType = job.type.Name; model.ClientName = job.client.Name; model.Duration = job.EstimatedDuration.ToString(); model.Notes = job.Notes; model.Completed = job.Complete ? "Complete" : "Incomplete"; model.StartDate = job.StartDate; model.JobId = job.Id.ToString(); return(View(model)); } else { return(RedirectToAction("Result", "Dashboard", new { statusCode = 1, message = "Unable To Access Job Information" })); } } else { //Generate invoice for job Invoice jobInvoice = cmLogic.GetJobInvoice(jobId.ToString(), UserId); if (jobInvoice != null) { //Display invoice for job model.JobInvoice = jobInvoice; return(View(model)); } else { return(RedirectToAction("Result", "Dashboard", new { statusCode = 1, message = "Unable To Access Job Information" })); } } }
public ActionResult ViewClient(int clientId) { string UserId = User.Identity.GetUserId(); var model = new ClientViewModel(); LogicService cmLogic = new LogicService(); //Acquire client var clientsForUser = cmLogic.GetClientsForUser(UserId); var matchingClient = clientsForUser.Where(cl => cl.Id == clientId); //Acquire jobs for client var jobsForUser = cmLogic.GetJobsForUser(UserId); var matchingJobsForClient = jobsForUser.Where(j => j.ClientId == clientId); //Split list into complete and incomplete lists var jobsForClientComplete = matchingJobsForClient.Where(j => j.Complete == true); var jobsForClientIncomplete = matchingJobsForClient.Where(j => j.Complete == false); //Sort jobs by start date var sortedJobsForClientComplete = jobsForClientComplete.OrderBy(j => j.StartDate).Reverse().ToList(); var sortedJobsForClientIncomplete = jobsForClientIncomplete.OrderBy(j => j.StartDate).ToList(); if (matchingClient.Count() > 0) { var client = matchingClient.First(); model.Name = client.Name; model.Email = client.Email; model.PhoneNumber = client.PhoneNumber; model.StreetAddress = client.Address.Street; model.City = client.Address.City; model.State = client.Address.State; model.Zip = client.Address.Zip; model.JobsForClientComplete = sortedJobsForClientComplete; model.JobsForClientIncomplete = sortedJobsForClientIncomplete; return(View(model)); } else { return(RedirectToAction("Result", "Dashboard", new { statusCode = 1, message = "Unable To Access Client Information" })); } }