public async Task ApplyDroneFlight(Models.DroneFlight flight, Models.ExponentPortalEntities db) { if (flight == null) { return; } String SQL = $@"SELECT {CalculateField} * {CostMultipliedBy} / {_CostDividedBy} FROM DroneFlight WHERE ID={flight.ID}"; if (!String.IsNullOrWhiteSpace(ApplyCondition)) { SQL += $" AND ({ApplyCondition})"; } using (var cmd = db.Database.Connection.CreateCommand()) { cmd.CommandText = SQL; var Result = await cmd.ExecuteScalarAsync(); if (Result == null) { _CalculatedCost = 0; } else { Decimal.TryParse(Result.ToString(), out _CalculatedCost); } }//using ctx.Database.Connection.CreateCommand }
public async Task <List <BillingGroupRule> > GenerateBilling(BillingNOC noc, Models.DroneFlight flight = null) { using (var db = new Models.ExponentPortalEntities()) { await db.Database.Connection.OpenAsync(); await CreateTempTableFor(noc, db); foreach (var rule in Rules.Where(w => w.IsActive && w.CalculateOn == "NOC_Details")) { await rule.ApplyNoc(noc, db); } foreach (var rule in Rules.Where(w => w.IsActive && w.CalculateOn == "DroneFlight")) { await rule.ApplyDroneFlight(flight, db); } } //if no flight return only the NOC Rules if (flight == null) { return(Rules.Where(w => w.IsActive && w.CalculateOn == "NOC_Details").ToList()); } //Return all active ruels applied return(Rules.Where(w => w.IsActive).ToList()); }
public async Task<ActionResult> FlightReport([Bind(Prefix = "ID")]int FlightID = 0) { // if (!exLogic.User.hasAccess("FLIGHT.MAP")) return RedirectToAction("NoAccess", "Home"); ViewBag.FlightID = FlightID; var FlightData = await ( from n in db.DroneFlight where n.ID == FlightID select new FlightViewModel { ID = n.ID, PilotID = n.PilotID, GSCID = n.GSCID, FlightDate = n.FlightDate, FlightHours = n.FlightHours, FlightDistance = n.FlightDistance, DroneID = n.DroneID, CreatedOn = n.CreatedOn, ApprovalID = n.ApprovalID }).FirstOrDefaultAsync(); if (FlightData == null) return HttpNotFound(); if (FlightData.FlightHours == null) FlightData.FlightHours = 0; FlightData.PilotName = await ( from n in db.MSTR_User where n.UserId == FlightData.PilotID select n.FirstName + " " + n.LastName).FirstOrDefaultAsync(); FlightData.GSCName = await ( from n in db.MSTR_User where n.UserId == FlightData.GSCID select n.FirstName + " " + n.LastName).FirstOrDefaultAsync(); FlightData.DroneName = await ( from n in db.MSTR_Drone where n.DroneId == FlightData.DroneID select n.DroneName).FirstOrDefaultAsync(); FlightData.PortalAlerts = await ( from n in db.PortalAlerts where n.FlightID == FlightID select n).ToListAsync(); var thisApproval = from n in db.GCA_Approval where n.ApprovalID == FlightData.ApprovalID select n; FlightData.Approval = await thisApproval.FirstOrDefaultAsync(); //set Alert message for Report //setReportMessages(FlightData.PortalAlerts, FlightData.Approval); FlightData.MapData = await ( from n in db.FlightMapDatas where n.FlightID == FlightID orderby n.FlightMapDataID select new LatLng{ Lat = (Decimal)n.Latitude, Lng =(Decimal)n.Longitude } ).ToListAsync(); FlightData.Videos = await ( from n in db.DroneFlightVideos where n.FlightID == FlightID select n) .OrderBy(o => o.CreatedDate) .ToListAsync(); FlightData.Approvals = await ( from n in db.GCA_Approval where FlightData.FlightDate >= n.StartDate && FlightData.FlightDate <= n.EndDate && n.DroneID == FlightData.DroneID select n ).ToListAsync(); FlightData.Info = await ( from n in db.FlightInfoes where n.FlightID == FlightID select n).FirstOrDefaultAsync(); if(FlightData.Info == null) { FlightData.Info = new Models.FlightInfo(); LatLng FirstPoint = FlightData.MapData.FirstOrDefault(); Exponent.WeatherAPI ReportWeather = new Exponent.WeatherAPI(); Exponent.WeatherForcast Condition = ReportWeather.GetByLocation((Double)FirstPoint.Lat, (Double)FirstPoint.Lng); FlightData.Info.Condition = Condition.Today.ConditionText; FlightData.Info.WindSpeed = Condition.Today.WindSpeed.ToString("0.0"); FlightData.Info.Humidity = Condition.Today.Humidity.ToString("0"); FlightData.Info.Visibility = (Decimal)Condition.Today.Visibility; FlightData.Info.Pressure = (Decimal)Condition.Today.Pressure; FlightData.Info.Temperature = Condition.Today.Temperature.ToString("0.0"); } //Billing int BillingGroupID = 1; BillingModule.BillingGroup grp = new BillingModule.BillingGroup(BillingGroupID); BillingModule.BillingNOC noc = new BillingModule.BillingNOC(); Models.DroneFlight flight = await noc.LoadNocForFlight(FlightID); //await noc.GenerateFields(); FlightData.Billing = await grp.GenerateBilling(noc, flight); return View(FlightData); }