public async Task <VehicleDetailsModel> VehicleServiceSave(VehicleServiceModel model) { VehicleServiceEntity entity; decimal serviceCost = model.TotalServiceCost; if (model.VehicleServiceId != 0) { VehicleServiceEntity currentServiceEntity = await this.SingleAsync <VehicleServiceEntity>(e => e.VehicleServiceId == model.VehicleServiceId); serviceCost = model.TotalServiceCost - currentServiceEntity.TotalServiceCost; entity = await this.UpdateEntity <VehicleServiceEntity, VehicleServiceModel>(currentServiceEntity, model, false); } else { entity = await this.AddEntity <VehicleServiceEntity, VehicleServiceModel>(model, false); } // updating the vehicle details await this.VehicleServiceVehicleUpdate(entity, serviceCost); await this.DbContext.SaveChangesAsync(); return(await this.VehicleDetailsGet(model.VehicleId)); }
private async Task VehicleServiceVehicleUpdate(VehicleServiceEntity entity, decimal serviceCost) { //Updating Vehicle VehicleEntity vehicle = await(from vh in this.DbContext.Vehicles where vh.VehicleId == entity.VehicleId select vh).SingleAsync(); vehicle.TotalServiceCost += serviceCost; vehicle.LastServiceDate = entity.ServiceStartDate; this.DbContext.Vehicles.Update(vehicle); }
private async Task VehicleServiceVehicleUpdate(VehicleServiceEntity entity, decimal serviceCost) { // Updating Vehicle VehicleEntity vehicle = await this.SingleAsync <VehicleEntity>(e => e.VehicleId == entity.VehicleId); vehicle.TotalServiceCost += serviceCost; vehicle.LastServiceDate = entity.ServiceStartDate; this.DbContext.Vehicles.Update(vehicle); }
public async Task <VehicleDetailsModel> VehicleServiceSave(VehicleServiceModel model) { decimal serviceCost = model.TotalServiceCost; if (model.VehicleServiceId != 0) { VehicleServiceEntity currentService = await(from vsm in this.DbContext.VehicleServices where vsm.VehicleServiceId == model.VehicleServiceId select vsm).SingleAsync(); serviceCost = model.TotalServiceCost - currentService.TotalServiceCost; } //saving vehicle service and updating the vehicle details VehicleServiceEntity entity = await SaveEntity <VehicleServiceEntity, VehicleServiceModel>(model, false); await VehicleServiceVehicleUpdate(entity, serviceCost); await this.DbContext.SaveChangesAsync(); return(await VehicleDetailsGet(model.VehicleId)); }