public async Task <IActionResult> ScheduleBoat(BoatScheDetails bId) { var disPerimeterTODock = Convert.ToDouble(_configuration.GetSection("Distance").GetSection("distPerimeterTODock").Value); var dbResult = await _context.BoatSchedule .Join(_context.BoatMaster, s => s.BoatMasterId, sa => sa.Id, (s, sa) => new { BoatSchedule = s, BoatMaster = sa }) .Where(x => x.BoatSchedule.Id == bId.Id).FirstOrDefaultAsync(); // get time to reach TimeSpan duration = TimeSpan.FromMinutes(cal_time(disPerimeterTODock, Convert.ToDouble(dbResult.BoatMaster.Speed)) * 60); DateTime today = DateTime.Now; dbResult.BoatSchedule.ModifyDate = today; dbResult.BoatSchedule.ProcessStartDate = today; dbResult.BoatSchedule.ProcessEndDate = today.Add(duration); dbResult.BoatSchedule.BoatStatus = (int)BoatStatus.InProcess; BoatSchedule boatSchedule = new BoatSchedule(); boatSchedule = dbResult.BoatSchedule; // Console.WriteLine(span.ToString(@"hh\:mm\:ss")); _context.Entry(boatSchedule).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(NoContent())); }
public async Task <IActionResult> CreateRandomBoats() { BoatSchedule boatSchedule = new BoatSchedule(); boatSchedule.BoatMasterId = RandomNumber(1, 4); boatSchedule.BoatStatus = (int)BoatStatus.At_Perimeter; // at Perimeter; boatSchedule.BoatName = GenerateName(5); boatSchedule.CreatedDate = DateTime.Now; _context.BoatSchedule.Add(boatSchedule); await _context.SaveChangesAsync(); return(Ok("Boat created")); }