public async Task <ActionResult> QuoteDecline(int Id) { var WeedHackSesh = System.Web.HttpContext.Current.Request.Cookies["WeedHackersSession"].Value; var UserDetails = MvcApplication.Sessions[WeedHackSesh].User; var serviceRequest = WeedHackersContext.ServiceRequests .Include(sa => sa.ServiceAdvisor.User) .Single(sr => sr.Id == Id); var emailmodel = new EmailFormModel { Message = UserDetails.Name + " " + UserDetails.Surname + " has declined Quote #" + serviceRequest.Id + " issued to him <br/>", Recipient = serviceRequest.ServiceAdvisor.User.Email }; var ServiceRequestStatus = new ServiceRequestStatusUpdate { ServiceRequestId = serviceRequest.Id, ServiceStatusId = WeedHackersContext.ServiceStatuses.Single(s => s.Name == "Rejected").Id, Message = "Service Requested has been rejected", }; WeedHackersContext.ServiceRequests.AddOrUpdate(sr => sr.Id, serviceRequest); WeedHackersContext.ServiceRequestStatusUpdates.Add(ServiceRequestStatus); await WeedHackersContext.SaveChangesAsync(); var email = new EmailHelper(); await email.SendEmail(emailmodel); FlashMessage.Confirmation("Quote Rejected", ""); return(RedirectToAction("QuotesReceived", "Customer")); }
public async Task <ActionResult> AssignEmployeedToQuote(ManagerQuoteManagmentModel request) { var serviceRequest = await WeedHackersContext .ServiceRequests .SingleAsync(sr => sr.Id == request.ServiceRequest.Id); serviceRequest.LeadEmployeeId = request.ServiceRequest.LeadEmployeeId; foreach (int requestAssignedEmployeeId in request.AssignedEmployeeIds) { serviceRequest.AssignedEmployees.Add(await WeedHackersContext.Employees.SingleAsync(e => e.Id == requestAssignedEmployeeId)); } WeedHackersContext.ServiceRequests.AddOrUpdate(sr => sr.Id, serviceRequest); var serviceStatus = await WeedHackersContext.ServiceStatuses.SingleAsync(ss => ss.Name == "In Progress"); var serviceStatusUpdate = new ServiceRequestStatusUpdate { ServiceRequestId = serviceRequest.Id, Message = "The Job is assigned and is in progress", ServiceStatusId = serviceStatus.Id }; WeedHackersContext.ServiceRequestStatusUpdates.Add(serviceStatusUpdate); await WeedHackersContext.SaveChangesAsync(); return(RedirectToAction("QuotesManagement", new { Id = request.ServiceRequest.Id })); }
public async Task <ActionResult> RequestService(CustomerInformationModel model) { var WeedHackSesh = System.Web.HttpContext.Current.Request.Cookies["WeedHackersSession"].Value; var UserDetails = MvcApplication.Sessions[WeedHackSesh].User; var CustomerDetails = WeedHackersContext.Customers.ToList().Find(u => u.Id == UserDetails.Id); ServiceRequestStatusUpdate ServiceRequestStatus; CustomerDetails.Address = model.Address; WeedHackersContext.Customers.AddOrUpdate(c => c.Id, CustomerDetails); if (ModelState.IsValid) { model.ServiceRequestModel.ServiceRequest.CustomerId = CustomerDetails.Id; WeedHackersContext.ServiceRequests.Add(model.ServiceRequestModel.ServiceRequest); ServiceRequestStatus = new ServiceRequestStatusUpdate { ServiceRequestId = model.ServiceRequestModel.ServiceRequest.Id, ServiceStatusId = WeedHackersContext.ServiceStatuses.Single(s => s.Name == "Created").Id, Message = "Service Requested has been created", }; WeedHackersContext.ServiceRequestStatusUpdates.Add(ServiceRequestStatus); // Magic WeedHackers_Data.Entities.Service service = WeedHackersContext .Services .Single(s => s.Id == model.ServiceRequestModel.ServiceRequest.ServiceId); var assigningEmployee = WeedHackersContext .Employees .Include(e => e.EmployeeType) .Where(e => e.DepartmentId == service.DepartmentId && e.EmployeeType.Name == "Service Advisor") .Include(e => e.AssignedServiceRequests) .OrderByDescending(e => e.AssignedServiceRequests.Count) .First(); model.ServiceRequestModel.ServiceRequest.ServiceAdvisorId = assigningEmployee.Id; await WeedHackersContext.SaveChangesAsync(); } FlashMessage.Confirmation("Service Requested", "Your service has successfully been requested and is awaiting inspection."); return(RedirectToAction("Index", "Customer")); }
public async Task <ActionResult> SendQuote(InspectionModel model) { EmailHelper send = new EmailHelper(); try { var dbServiceRequest = await WeedHackersContext .ServiceRequests .Include(ct => ct.Customer.CustomerType) .Include(ct => ct.Customer.User) .Include(s => s.Service) .Include(d => d.Service.Department) .Include(d => d.ServiceAdvisor.User) .Include(ss => ss.ServiceRequestStatusUpdates.Select(srsu => srsu.ServiceStatus)) .SingleAsync(s => s.Id == model.ServiceRequest.ServiceRequest.Id); double subtotal = dbServiceRequest.Service.PricePerUnit * (double)model.ServiceRequest.ServiceRequest.UnitQuantity; double Total = subtotal * 1.14; dbServiceRequest.UnitQuantity = model.ServiceRequest.ServiceRequest.UnitQuantity; var serviceStatus = await WeedHackersContext.ServiceStatuses.SingleAsync(ss => ss.Name == "Inspected"); ServiceRequestStatusUpdate serviceRequestStatusUpdate = new ServiceRequestStatusUpdate { ServiceRequestId = dbServiceRequest.Id, ServiceStatusId = serviceStatus.Id, Message = "Service Request has been Inspected." }; WeedHackersContext.ServiceRequestStatusUpdates.Add(serviceRequestStatusUpdate); await WeedHackersContext.SaveChangesAsync(); var emailRequest = new EmailQuoteModel(); emailRequest.Email = dbServiceRequest.ServiceAdvisor.User.Email; emailRequest.QuotationNumber = dbServiceRequest.Id.ToString(); emailRequest.ServiceType = dbServiceRequest.Service.ServiceName; emailRequest.Tell = dbServiceRequest.ServiceAdvisor.User.PhoneNumber; emailRequest.UnitQuantity = dbServiceRequest.UnitQuantity.ToString(); emailRequest.UnitPrice = dbServiceRequest.Service.PricePerUnit.ToString("R0.00"); emailRequest.UnitSubtotal = subtotal.ToString("R0.00"); emailRequest.UnitTotal = Total.ToString("R0.00"); emailRequest.EmailFormModel = new EmailFormModel { Recipient = dbServiceRequest.Customer.User.Email, Message = "" }; await send.SendQuotationEmail(emailRequest); FlashMessage.Confirmation("Inspection Complete", "Quote of inspection has been sent to the customer."); return(RedirectToAction("Index", "Employee")); } catch (Exception) { FlashMessage.Danger("Inspection Error", "There was a problem processing the inspection."); return(View("Index")); } }