Exemple #1
0
        public async Task <JsonResult> CompleteRepair(int id, string status, FeedbackViewModel feedbackVm)
        {
            var result = await Factory.DeleteAsync <IRepairDto>(id.ToString());

            if (result && feedbackVm != null)
            {
                Factory.Save <IFeedbackDto>(feedbackVm);

                if (!string.IsNullOrWhiteSpace(feedbackVm.AdditionalFeedback) ||
                    feedbackVm.ConcernsAddressedRate < 5 ||
                    feedbackVm.ReportCompletionRate < 5 ||
                    feedbackVm.ReportCompletionRate < 5 ||
                    feedbackVm.ResponseTimeRate < 5 ||
                    feedbackVm.TechnicianCommunicationRate < 5 ||
                    feedbackVm.TechnicianKnowledgeRate < 5)
                {
                    using (var queue = new MessageQueue())
                    {
                        var userGuid = Guid.Parse(User.Identity.GetUserId());
                        await queue.AddNotificationQueueMessageAsync(template : NotificationTemplate.RepairFeedbackEmail, id : feedbackVm.RepairId, userGuid : userGuid);
                    }
                }
            }

            if (!result)
            {
                return(Json(result));
            }

            if (status == "complete")
            {
                string billingUrl = Url.Action("Invoice", "Invoicing", new { Area = "Billing", ID = id }, Request?.Url?.Scheme);
                var    task       = new ClientHubMessenger().RepairCompleted(id, billingUrl);

                Task.WhenAll(task);
            }

            return(Json(new
            {
                message = "Repair Updated Successfully.",
                success = true
            }));
        }
Exemple #2
0
        public async Task <ActionResult> SelfScanCreate(SelfScanViewModel selfScan)
        {
            try
            {
                // Create Request.
                var request = new RepairRequestScanViewModel
                {
                    RequestTypeID         = 6,
                    ProblemDescription    = "Self Scan",
                    RequestTypeCategoryId = selfScan.CategoryId,
                    SeatRemovedInd        = selfScan.SeatRemovedInd
                };

                // Create Request.
                var requestId = await QuickRequestSave(selfScan, request);

                // Load Report.
                var report = Factory.GetById <IReportDto>(requestId.ToString());

                // Generate Report Html.
                if (report != null && selfScan.DiagnosticResultId.HasValue)
                {
                    // Set Diagnostic.
                    report.DiagnosticResultSelections = new List <IReportDiagnosticResultSelectionItemDto>
                    {
                        new ReportDiagnosticResultSelectionItemViewModel
                        {
                            ResultId             = selfScan.DiagnosticResultId.Value,
                            AssignedToRequestInd = true,
                            SelectedForReportInd = true
                        }
                    };

                    // Set User.
                    report.ResponsibleTechUserId = Factory.User.UserGuid;

                    // Set Header.
                    report.ReportHeaderHTML = "Self Scan Report<br/>";

                    if (selfScan.IsAssistedScanRecommended)
                    {
                        report.ReportHeaderHTML += "<b style='color:red;'>All modules were not read on this Vehicle, recommend an Assisted Scan be performed.</b><br/>";
                    }

                    // Complete Report.
                    report.CompleteReport = true;

                    // Save Report.
                    Factory.Save(report);

                    // Create Notification Tasks.
                    var notifications = new List <Task>();

                    // Generate Notifications.
                    using (var queue = new MessageQueue())
                    {
                        notifications.Add(queue.AddNotificationQueueMessageAsync(NotificationTemplate.ShopReportEmail, report.RequestId, Factory.User.UserGuid));
                        notifications.Add(queue.AddMitchellReportQueueMessageAsync(report.RequestId, Factory.User.UserGuid));
                    }

                    // Open Connection.
                    using (var conn = new SqlConnection(MvcApplication.ConnectionString))
                    {
                        // Get Repair Id.
                        var repairId = await conn.QueryFirstOrDefaultAsync <int>("Repair.usp_CloseRepairByRequestId",
                                                                                 new { report.RequestId }, null, null, CommandType.StoredProcedure);

                        // Check Repair.
                        if (repairId > 0)
                        {
                            // Close Repair.
                            if (await Factory.DeleteAsync <IRepairDto>(repairId.ToString()))
                            {
                                // Send Notifications.
                                var clientMessenger = new ClientHubMessenger();
                                notifications.Add(clientMessenger.RepairCompleted());
                            }
                        }
                    }

                    // Execute Notifications.
                    await Task.WhenAll(notifications.ToArray());
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e);

                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, e.Message));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Exemple #3
0
        public async Task <JsonCamelCaseResult> SaveScanReport(ReportViewModel report)
        {
            try
            {
                // Save Report.
                var update = Factory.Save(Mapper.Map <IReportDto>(report));

                // Check for Failure.
                if (update.UpdateResult?.Success != true)
                {
                    return(new JsonCamelCaseResult(update));
                }

                // Load Messengers.
                var clientMessenger  = new ClientHubMessenger();
                var requestMessenger = new ScanRequestHubMessenger();

                // Notify Listeners.
                await(requestMessenger.NotifyScanUpdated(update.RequestId));
                await(clientMessenger.ScanRequestOutDated(Factory.User.UserGuid, update.RequestId));

                // Check for Completed.
                if (!update.CompleteReport)
                {
                    return(new JsonCamelCaseResult(Mapper.Map <ReportViewModel>(update)));
                }

                // Notify Listeners.
                await(clientMessenger.ScanRequestCompleted());
                await(requestMessenger.NotifyScanRemoved(update.RequestId));

                // Load Notification Queue.
                var queue = new MessageQueue();

                // Check for Not Cancel.
                if (!update.CancelReport && report.UserCompletedInd)
                {
                    // Send Notifications.
                    await(queue.AddNotificationQueueMessageAsync(NotificationTemplate.ShopReportEmail, update.RequestId,
                                                                 Factory.User.UserGuid));

                    // Send Completed Report to Mitchell.
                    await(queue.AddMitchellReportQueueMessageAsync(update.RequestId, Factory.User.UserGuid));

                    // Check for Auto Close Bypass.
                    if (!report.AutoRepairCloseBypass)
                    {
                        // Run Auto Close Logic.
                        using (var conn = new SqlConnection(MvcApplication.ConnectionString))
                        {
                            // Get Repair Id.
                            var repairId = await conn.QueryFirstOrDefaultAsync <int>("Repair.usp_CloseRepairByRequestId",
                                                                                     new { report.RequestId }, null, null, CommandType.StoredProcedure);

                            // Check Repair.
                            if (repairId > 0)
                            {
                                // Close Repair.
                                if (await Factory.DeleteAsync <IRepairDto>(repairId.ToString()))
                                {
                                    // Update Repair Complete.
                                    update.AllowEdit      = false;
                                    update.RepairComplete = true;

                                    // Send Notifications.
                                    await(clientMessenger.RepairCompleted());
                                }
                            }
                        }
                    }
                }

                // Check for Cancelled.
                if (update.CancelReport)
                {
                    // Look for Cancel Reason Template.
                    var cancelReason = await Factory.GetByIdAsync <ICancelReasonTypeDto>(update.CancelReasonTypeId.ToString());

                    if (cancelReason?.NotificationTemplate != null)
                    {
                        // Send Notification.
                        await(queue.AddNotificationQueueMessageAsync(cancelReason.NotificationTemplate.Value, report.RequestId, Factory.User.UserGuid));
                    }
                }

                // Return Data.
                return(new JsonCamelCaseResult(Mapper.Map <ReportViewModel>(update)));
            }
            catch (Exception e)
            {
                // Log Exception.
                Logger.LogException(e);

                // Create Result.
                report.UpdateResult = new UpdateResultViewModel(false, e.Message);

                // Return Data.
                return(new JsonCamelCaseResult(report));
            }
        }