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); }
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); } }