public static void ProcessStatusRequestBehavior(IncidentStatusRequest statusRequest, Incident updateIncident, ApiServices Services)
        {
            IHubContext hubContext = Services.GetRealtime <IncidentHub>();

            switch (updateIncident.StatusCode)
            {
            case "PROVER-FOUND":

                //Notify Particular Connected User through SignalR
                hubContext.Clients.Group(updateIncident.ProviderUserID).updateMobileClientStatus(statusRequest.GetCustomerPushObject());
                Services.Log.Info("Mobile Client [" + updateIncident.ProviderUserID + "] Status Update Payload Sent");

                //Notifying Connect WebClients with IncidentInfo Package
                hubContext.Clients.All.updateIncidentStatusAdmin(new IncidentInfo(updateIncident));
                Services.Log.Info("Connected Clients Updated");

                RevokeProviderJobs(updateIncident, Services);
                Services.Log.Info("Provider Jobs Revoked");

                break;

            case "ARRIVED":

                //Notify Particular Connected User through SignalR
                hubContext.Clients.Group(updateIncident.ProviderUserID).updateMobileClientStatus(statusRequest.GetCustomerPushObject());
                Services.Log.Info("Mobile Client [" + updateIncident.ProviderUserID + "] Status Update Payload Sent");

                //Notifying Connect WebClients with IncidentInfo Package
                hubContext.Clients.All.updateIncidentStatusAdmin(new IncidentInfo(updateIncident));
                Services.Log.Info("Connected Clients Updated");

                SendGridController.SendCurrentIncidentInvoiceEmail(updateIncident, Services);

                break;

            case "COMPLETED":

                //Notify Particular Connected User through SignalR
                hubContext.Clients.Group(updateIncident.ProviderUserID).updateMobileClientStatus(statusRequest.GetCustomerPushObject());
                Services.Log.Info("Mobile Client [" + updateIncident.ProviderUserID + "] Status Update Payload Sent");

                //Notifying Connect WebClients with IncidentInfo Package
                hubContext.Clients.All.updateIncidentStatusAdmin(new IncidentInfo(updateIncident));
                Services.Log.Info("Connected Clients Updated");
                break;

            case "DECLINED":

                //Notify Particular Connected User through SignalR
                hubContext.Clients.Group(updateIncident.ProviderUserID).updateMobileClientStatus(statusRequest.GetCustomerPushObject());
                Services.Log.Info("Mobile Client [" + updateIncident.ProviderUserID + "] Status Update Payload Sent");

                //Notifying Connect WebClients with IncidentInfo Package
                hubContext.Clients.All.updateIncidentStatusAdmin(new IncidentInfo(updateIncident));
                Services.Log.Info("Connected Clients Updated");

                RevokeProviderJobs(updateIncident, Services);
                Services.Log.Info("Provider Jobs Revoked");

                break;

            case "CANCELLED":
                //Notifying Connect WebClients with IncidentInfo Package
                hubContext.Clients.All.updateIncidentStatusCustomerCancel(new IncidentInfo(updateIncident));
                Services.Log.Info("Connected Clients Updated");

                RevokeProviderJobs(updateIncident, Services);
                Services.Log.Info("Provider Jobs Revoked");

                break;

            default:
                //Notify Particular Connected User through SignalR
                hubContext.Clients.Group(updateIncident.ProviderUserID).updateMobileClientStatus(statusRequest.GetCustomerPushObject());
                Services.Log.Info("Mobile Client [" + updateIncident.ProviderUserID + "] Status Update Payload Sent");

                //Notifying Connect WebClients with IncidentInfo Package
                hubContext.Clients.All.updateIncidentStatusAdmin(new IncidentInfo(updateIncident));
                Services.Log.Info("Connected Clients Updated");

                break;
            }
        }
        public async Task <HttpResponseMessage> InstamojoWebHookReceiver(InstamojoWebhookRequest request)
        {
            Services.Log.Info("Instamojo Webhook Request");

            string incidentPropertyName = WebConfigurationManager.AppSettings["RZ_InstamojoIncidentDataField"];

            //var customFieldsObject = JsonConvert.DeserializeObject<InstamojoCustomFields>(request.Custom_Fields);
            //var parsedIncidentGUID = customFieldsObject.Field_25373.value;

            Services.Log.Info(incidentPropertyName);
            Services.Log.Info(request.Custom_Fields);

            JObject customFieldSetObj = JObject.Parse(request.Custom_Fields);

            Services.Log.Info(customFieldSetObj.ToString());
            JObject customFieldInstanceObj = (JObject)customFieldSetObj[incidentPropertyName];

            Services.Log.Info(customFieldInstanceObj.ToString());
            string parsedIncidentGUID = customFieldInstanceObj["value"].ToString();

            Services.Log.Info(parsedIncidentGUID);

            // Set the Payment Platform.
            string nameInstamojo = "Instamojo";

            Payment newPayment = new Payment()
            {
                Id = Guid.NewGuid().ToString(),
                PlatformPaymentID = request.Payment_ID,
                Status            = request.Status,
                BuyerName         = request.Buyer_Name,
                BuyerEmail        = request.Buyer,
                BuyerPhone        = request.Buyer_Phone,
                Currency          = request.Currency,
                Amount            = request.Amount,
                Fees = request.Fees,
                AuthenticationCode = request.MAC,
                PaymentPlatform    = nameInstamojo,
                IncidentGUID       = parsedIncidentGUID,
                ProviderUserID     = IncidentInfo.GetProviderID(parsedIncidentGUID)
            };

            stranddContext context = new stranddContext();

            context.Payments.Add(newPayment);

            await context.SaveChangesAsync();

            //Initiating Hub Context
            Microsoft.AspNet.SignalR.IHubContext hubContext = Services.GetRealtime <IncidentHub>();

            if (newPayment.ProviderUserID == "NO INCIDENT - NO PROVIDER ID")
            {
                Services.Log.Warn("New Instamojo Payment Received - No Incident");
            }
            else if (newPayment.ProviderUserID == "INCIDENT NOT FOUND - NO PROVIDER ID")
            {
                Services.Log.Warn("New Instamojo Payment Received - No Found Incident");
            }
            else if (newPayment.ProviderUserID == "NO ASSOCIATED USER")
            {
                Services.Log.Warn("New Instamojo Payment Received - No Associated User");
            }
            else
            {
                Services.Log.Info("New Instamojo Payment Received from User [" + newPayment.ProviderUserID + "]");

                //Notify Particular Connected User through SignalR
                hubContext.Clients.Group(newPayment.ProviderUserID).updateMobileClientStatus(newPayment.GetCustomerPushObject());
                Services.Log.Info("Mobile Client [" + newPayment.ProviderUserID + "] Status Update Payload Sent");

                SendGridController.SendIncidentPaymentReceiptEmail(newPayment, Services);
            }

            //Web Client Notifications
            hubContext.Clients.All.saveNewPayment(newPayment);
            Services.Log.Info("Connected Clients Updated");

            return(this.Request.CreateResponse(HttpStatusCode.Created));
        }
        public async Task <HttpResponseMessage> CustomerNewIncident(IncidentRequest incidentRequest)
        {
            Services.Log.Info("New Incident Request [API]");

            // Get the logged-in user.
            var currentUser = this.User as ServiceUser;

            double locationX = 0;
            double locationY = 0;

            //Check Provided Location JObject & Process Accordingly
            if (incidentRequest.Location != null)
            {
                if (incidentRequest.Location.X != -1 && incidentRequest.Location.Y != -1)
                {
                    //Coordinates Flow - X & Y Coordinate Passed
                    locationX = incidentRequest.Location.X;
                    locationY = incidentRequest.Location.Y;
                }
                else
                {
                    //No Coordinates
                    //Consider Geocoding
                }
            }
            else
            {
                //No Location Flow - No Location JObject
            }

            Incident newIncident = new Incident()
            {
                Id                    = Guid.NewGuid().ToString(),
                JobCode               = incidentRequest.JobCode,
                LocationObj           = await JsonConvert.SerializeObjectAsync(incidentRequest.Location),
                CoordinateX           = locationX,
                CoordinateY           = locationY,
                ProviderUserID        = currentUser.Id,
                VehicleGUID           = incidentRequest.VehicleGUID,
                AdditionalDetails     = incidentRequest.AdditionalDetails,
                StatusCode            = "SUBMITTED", // Set the Initial Status
                StatusCustomerConfirm = true,
                StatusProviderConfirm = false,
                ServiceFee            = (incidentRequest.ServiceFee != 0 || incidentRequest.ServiceFee != null) ? incidentRequest.ServiceFee : 0
            };

            stranddContext context = new stranddContext();

            context.Incidents.Add(newIncident);

            await context.SaveChangesAsync();

            Services.Log.Info("New Incident Created [" + newIncident.Id + "]");

            IncidentRequestResponse returnObject = new IncidentRequestResponse {
                IncidentGUID = newIncident.Id
            };
            string responseText = JsonConvert.SerializeObject(returnObject);

            //Notifying Connect WebClients with IncidentInfo Package
            IHubContext hubContext = Services.GetRealtime <IncidentHub>();

            hubContext.Clients.All.saveNewIncidentCustomer(new IncidentInfo(newIncident));
            ProcessProviderOutreach(newIncident, Services);

            Services.Log.Info("Connected Clients Updated");

            SendGridController.SendIncidentSubmissionAdminEmail(newIncident, Services);

            await HistoryEvent.logHistoryEventAsync("INCIDENT_NEW_CUSTOMER", null, newIncident.Id, null, currentUser.Id, null);

            return(this.Request.CreateResponse(HttpStatusCode.Created, responseText));
        }