예제 #1
0
        public async Task <HttpResponseMessage> NewCostingSlab(CostingSlabRequest costingSlabRequest)
        {
            Services.Log.Info("New CostingSlab Request [API]");
            string responseText;

            stranddContext context = new stranddContext();

            CostingSlab newCostingSlab = new CostingSlab
            {
                Id                    = Guid.NewGuid().ToString(),
                IdentifierGUID        = costingSlabRequest.IdentifierGUID,
                ServiceType           = costingSlabRequest.ServiceType,
                Status                = costingSlabRequest.Status,
                StartTime             = costingSlabRequest.StartTime,
                EndTime               = costingSlabRequest.EndTime,
                BaseCharge            = costingSlabRequest.BaseCharge,
                BaseKilometersFloor   = costingSlabRequest.BaseKilometersFloor,
                ExtraKilometersCharge = costingSlabRequest.ExtraKilometersCharge

                                        // Version = new Byte[125],
                                        //CreatedAt = costingSlabRequest.StartTime,
                                        //UpdatedAt=costingSlabRequest.StartTime,
                                        //Deleted= false
            };

            context.CostingSlabs.Add(newCostingSlab);
            await context.SaveChangesAsync();

            responseText = "CostingSlab Successfully Generated";
            Services.Log.Info(responseText);
            return(this.Request.CreateResponse(HttpStatusCode.Created, responseText));
        }
예제 #2
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);
        }
예제 #3
0
        public async Task <HttpResponseMessage> RemoveCostingSlabs(string id)
        {
            List <CostingSlab> dbCostingSlab = new List <CostingSlab>();


            Services.Log.Info("CostingSlabID [" + id + "] Remove Costing Slabs Request [API]");
            string responseText;

            stranddContext context = new stranddContext();

            //if (id == "")
            //{
            //    responseText = "No Costing Slabs Defined";
            //    Services.Log.Warn(responseText);
            //    return this.Request.CreateResponse(HttpStatusCode.BadRequest, responseText);

            //}
            CostingSlab lookupCostingSlabs = await context.CostingSlabs.Where(a => a.Id == id).SingleOrDefaultAsync();

            if (lookupCostingSlabs == null)
            {
                responseText = "Costing Slabs Not Found";
                Services.Log.Info(responseText);
                return(this.Request.CreateResponse(HttpStatusCode.NotFound, responseText));
            }
            else
            {
                //Staff Assignment Removal
                context.CostingSlabs.Remove(lookupCostingSlabs);
                await context.SaveChangesAsync();

                responseText = "Costing Slabs Successfully Removed";
                Services.Log.Info(responseText);
                return(this.Request.CreateResponse(HttpStatusCode.Created, responseText));
            }
        }
예제 #4
0
        public async Task <HttpResponseMessage> UpdateCostingSlabs(CostingSlabRequest costingSlabRequest)
        {
            Services.Log.Info("Update Costing Slabs Request");

            stranddContext context = new stranddContext();

            //Determine Account ProviderUserID for Updation based upon Request (or Authenticated Token)
            string costingslabsID;

            if (costingSlabRequest.ID != null)
            {
                costingslabsID = costingSlabRequest.ID;
            }

            else
            {
                var currentUser = this.User as ServiceUser;

                if (currentUser != null)
                {
                    costingslabsID = currentUser.Id;
                }
                else
                {
                    string responsetext = "No Costing Slabs ID";
                    Services.Log.Warn(responsetext);
                    return(this.Request.CreateResponse(HttpStatusCode.BadRequest, responsetext));
                }
            }

            //Looks up the Account for Update by ProviderUserID
            CostingSlab updateCostingSlab = await context.CostingSlabs.Where(a => a.Id == costingSlabRequest.ID).SingleOrDefaultAsync();

            if (updateCostingSlab != null)
            {
                string responseText;

                //Account Updation
                updateCostingSlab.IdentifierGUID        = costingSlabRequest.IdentifierGUID;
                updateCostingSlab.ServiceType           = costingSlabRequest.ServiceType;
                updateCostingSlab.Status                = costingSlabRequest.Status;
                updateCostingSlab.StartTime             = costingSlabRequest.StartTime;
                updateCostingSlab.EndTime               = costingSlabRequest.EndTime;
                updateCostingSlab.BaseCharge            = costingSlabRequest.BaseCharge;
                updateCostingSlab.BaseKilometersFloor   = costingSlabRequest.BaseKilometersFloor;
                updateCostingSlab.ExtraKilometersCharge = costingSlabRequest.ExtraKilometersCharge;

                await context.SaveChangesAsync();

                //Return Successful Response
                responseText = "Updated Costing Slabs [" + costingslabsID + "]";
                Services.Log.Info(responseText);
                return(this.Request.CreateResponse(HttpStatusCode.Created, responseText));
            }
            else
            {
                //Return Failed Response
                string responseText;
                responseText = "Costing Slabs not found by ID [" + costingslabsID + "]";
                Services.Log.Warn(responseText);
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, 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";
            }
        }