public static async Task SaveCostingSlabAsync(IncidentCostingRequest costingRequest, CostingSlab inputSlab, string slabType, ApiServices Services)
        {

            string responseText;

            //Get Tax Rate
            decimal taxZoneRate = System.Convert.ToDecimal(WebConfigurationManager.AppSettings["RZ_DefaultTaxZoneRate"]);

            //Calulate Provider
            decimal calculatedBaseServiceCost =
                (costingRequest.ServiceKilometers > inputSlab.BaseKilometersFloor) ? (inputSlab.BaseCharge + ((costingRequest.ServiceKilometers - inputSlab.BaseKilometersFloor)) * inputSlab.ExtraKilometersCharge) : inputSlab.BaseCharge;
            decimal calculatedSubtotal = calculatedBaseServiceCost + costingRequest.ParkingCosts + costingRequest.TollCosts + costingRequest.OtherCosts - costingRequest.OffsetDiscount;
            decimal calculatedTaxes = (calculatedSubtotal * taxZoneRate) / 100;
            decimal calculatedTotalCost = calculatedSubtotal + calculatedTaxes;

            stranddContext context = new stranddContext();

            //Check for Provider Incident in IncidentCosting
            IncidentCosting updateIncidentCosting = await (from r in context.IncidentCostings where (r.IncidentGUID == costingRequest.IncidentGUID && r.Type == slabType) 
                                                          select r).FirstOrDefaultAsync();

            if (updateIncidentCosting != null)
            {
                updateIncidentCosting.IdentifierGUID = inputSlab.IdentifierGUID;
                updateIncidentCosting.ServiceType = costingRequest.ServiceType;
                updateIncidentCosting.CostingSlabGUID = inputSlab.Id;
                updateIncidentCosting.TaxZoneRate = taxZoneRate;
                updateIncidentCosting.ServiceKilometers = costingRequest.ServiceKilometers;
                updateIncidentCosting.ParkingCosts = costingRequest.ParkingCosts;
                updateIncidentCosting.TollCosts = costingRequest.TollCosts;
                updateIncidentCosting.OtherCosts = costingRequest.OtherCosts;
                updateIncidentCosting.OffsetDiscount = (slabType=="CUSTOMER") ? costingRequest.OffsetDiscount : 0;
                updateIncidentCosting.CalculatedSubtotal = calculatedSubtotal;
                updateIncidentCosting.CalculatedBaseServiceCost = calculatedBaseServiceCost;
                updateIncidentCosting.CalculatedTaxes = calculatedTaxes;
                updateIncidentCosting.CalculatedTotalCost = calculatedTotalCost;

                await context.SaveChangesAsync();

                responseText = "IncidentCostings (" + slabType + ") Successfully Updated";
            }

            else
            {
                IncidentCosting newIncidentCosting = new IncidentCosting
                {
                    Id = Guid.NewGuid().ToString(),
                    IncidentGUID = costingRequest.IncidentGUID,
                    IdentifierGUID = inputSlab.IdentifierGUID,
                    Type = slabType,
                    ServiceType = costingRequest.ServiceType,
                    CostingSlabGUID = inputSlab.Id,
                    TaxZoneRate = taxZoneRate,
                    ServiceKilometers = costingRequest.ServiceKilometers,
                    ParkingCosts = costingRequest.ParkingCosts,
                    TollCosts = costingRequest.TollCosts,
                    OtherCosts = costingRequest.OtherCosts,
                    OffsetDiscount = (slabType == "CUSTOMER") ? costingRequest.OffsetDiscount : 0,
                    CalculatedSubtotal = calculatedSubtotal,
                    CalculatedBaseServiceCost = calculatedBaseServiceCost,
                    CalculatedTaxes = calculatedTaxes,
                    CalculatedTotalCost = calculatedTotalCost

                };
                context.IncidentCostings.Add(newIncidentCosting);
                await context.SaveChangesAsync();

                responseText = "IncidentCostings (" + slabType + ") Successfully Generated";
            }

        }
        public IncidentInfo(Incident baseIncident)
        {
            //Create UserInfo Object based upon Passed in ProviderUserID [Call to DB Made in Constructor]
            AccountInfo lookupUser = new AccountInfo(baseIncident.ProviderUserID);

            //Create VehicleInfo Object based upon Passed in VehicleGUID [Call to DB Made in Constructor]
            VehicleInfo lookupVehicle = new VehicleInfo(baseIncident.VehicleGUID);

            stranddContext context = new stranddContext();

            IncidentCosting lookupIncidentCosting = context.IncidentCostings
                                                    .Where(u => u.IncidentGUID == baseIncident.Id)
                                                    .Where(v => v.Type == "CUSTOMER")
                                                    .FirstOrDefault();

            //Payment Information
            List <Payment> lookupPaymentList = context.Payments
                                               .Where(u => u.IncidentGUID == baseIncident.Id)
                                               .ToList <Payment>();

            string paymentMethodString = null;

            if (lookupPaymentList.Count != 0)
            {
                if (lookupPaymentList.Count > 1)
                {
                    paymentMethodString = "Multiple Payments [" + lookupPaymentList.Count.ToString() + "]";
                }
                else
                {
                    paymentMethodString = lookupPaymentList[0].PaymentPlatform;
                }
            }

            decimal sumPaymentTotal = lookupPaymentList.Sum(a => a.Amount);

            //Confirmed Admin Information
            HistoryEvent lookupAdminEvent = context.HistoryLog
                                            .Where(u => u.ReferenceID == baseIncident.Id)
                                            .OrderByDescending(d => d.CreatedAt)
                                            .Where(v => v.Code == "INCIDENT_STATUS_ADMIN")
                                            .Where(x => x.Attribute == "CONFIRMED" || x.Attribute == "OPERATOR-ASSIGNED")
                                            .FirstOrDefault();

            AccountInfo lookupAdmin;

            if (lookupAdminEvent != null)
            {
                lookupAdmin = new AccountInfo(lookupAdminEvent.AdminID);
            }
            else
            {
                lookupAdmin = new AccountInfo(null);
            }

            this.IncidentGUID          = baseIncident.Id;
            this.IncidentUserInfo      = lookupUser;
            this.IncidentVehicleInfo   = lookupVehicle;
            this.ConfirmedAdminAccount = lookupAdmin;
            this.JobCode             = baseIncident.JobCode;
            this.LocationObj         = (baseIncident.LocationObj != null) ? JsonConvert.DeserializeObject <IncidentLocation>(baseIncident.LocationObj) : null;
            this.ConcertoCaseID      = baseIncident.ConcertoCaseID;
            this.StatusCode          = baseIncident.StatusCode;
            this.Rating              = baseIncident.Rating;
            this.ServiceFee          = baseIncident.ServiceFee;
            this.CoordinateX         = baseIncident.CoordinateX;
            this.CoordinateY         = baseIncident.CoordinateY;
            this.ProviderArrivalTime = baseIncident.ProviderArrivalTime;
            this.CreatedAt           = baseIncident.CreatedAt;
            this.UpdatedAt           = baseIncident.UpdatedAt;
            this.CustomerComments    = baseIncident.CustomerComments;
            this.StaffNotes          = baseIncident.StaffNotes;
            this.PaymentAmount       = sumPaymentTotal;     //(lookupPayment != null) ? lookupPayment.Amount : 0;
            this.PaymentMethod       = paymentMethodString; //(lookupPayment != null) ? lookupPayment.PaymentPlatform : null;
            this.AdditionalDetails   = baseIncident.AdditionalDetails;

            //retrive data IncidentCostings
            this.ServiceType               = (lookupIncidentCosting != null) ? lookupIncidentCosting.ServiceType   : null;
            this.ServiceKilometers         = (lookupIncidentCosting != null) ? lookupIncidentCosting.ServiceKilometers : 0;
            this.CalculatedBaseServiceCost = (lookupIncidentCosting != null) ? lookupIncidentCosting.CalculatedBaseServiceCost : 0;
            this.ParkingCosts              = (lookupIncidentCosting != null) ? lookupIncidentCosting.ParkingCosts : 0;
            this.TollCosts           = (lookupIncidentCosting != null) ? lookupIncidentCosting.TollCosts : 0;
            this.OtherCosts          = (lookupIncidentCosting != null) ? lookupIncidentCosting.OtherCosts : 0;
            this.OffsetDiscount      = (lookupIncidentCosting != null) ? lookupIncidentCosting.OffsetDiscount : 0;
            this.CalculatedSubtotal  = (lookupIncidentCosting != null) ? lookupIncidentCosting.CalculatedSubtotal : 0;
            this.TaxZoneRate         = (lookupIncidentCosting != null) ? lookupIncidentCosting.TaxZoneRate : 0;
            this.CalculatedTaxes     = (lookupIncidentCosting != null) ? lookupIncidentCosting.CalculatedTaxes : 0;
            this.CalculatedTotalCost = (lookupIncidentCosting != null) ? lookupIncidentCosting.CalculatedTotalCost : 0;
        }