Beispiel #1
0
        public async Task <string> UpdateCosting(IncidentCostingRequest costingRequest)
        {
            Services.Log.Info("Update Incident Costing Request [HUB]");
            string responseText;

            IncidentInfo infoOutput;

            //Get Defaults From Configuration and overrride from Request (To be Modified in Expansions)

            string companyGUID = (costingRequest.ProviderIdentifierGUID == null || costingRequest.ProviderIdentifierGUID == "") ? WebConfigurationManager.AppSettings["RZ_DefaultProviderCompany"] : costingRequest.ProviderIdentifierGUID;
            string policyGUID  = (costingRequest.CustomerIdentifierGUID == null || costingRequest.CustomerIdentifierGUID == "") ? WebConfigurationManager.AppSettings["RZ_DefaultCustomerPolicy"] : costingRequest.CustomerIdentifierGUID;

            stranddContext context = new stranddContext();

            CostingSlab providerSlab = new CostingSlab();

            providerSlab = await(from r in context.CostingSlabs where (r.IdentifierGUID == companyGUID && r.ServiceType == costingRequest.ServiceType && r.Status == "CURRENT") select r).FirstOrDefaultAsync();
            if (providerSlab == null)
            {
                responseText = "Provider Company Costing Slab Not Found"; Services.Log.Warn(responseText);
            }
            else
            {
                IncidentController.SaveCostingSlabAsync(costingRequest, providerSlab, "PROVIDER", Services);
            }

            CostingSlab customerSlab = new CostingSlab();

            customerSlab = await(from r in context.CostingSlabs where (r.IdentifierGUID == policyGUID && r.ServiceType == costingRequest.ServiceType && r.Status == "CURRENT") select r).FirstOrDefaultAsync();

            if (customerSlab == null)
            {
                responseText = "Customer Policy Costing Slab Not Found"; Services.Log.Warn(responseText);
            }
            else
            {
                await IncidentController.SaveCostingSlabAsync(costingRequest, customerSlab, "CUSTOMER", Services);

                responseText = "Incident Costings Request Processed";

                infoOutput = new IncidentInfo(costingRequest.IncidentGUID);

                //Web Client Notifications
                IHubContext hubContext = Services.GetRealtime <IncidentHub>();
                hubContext.Clients.All.updateIncidentCostingAdmin(infoOutput);
                Services.Log.Info("Connected Clients Generated");
            }

            return(responseText);
        }
        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";
            }
        }