Example #1
0
        public ActionResult <DriverAvailability> Get(string driverId, DateTime startTime, DateTime stopTime)
        {
            if (!Guid.TryParse(driverId, out var guid))
            {
                return(BadRequest("Invalid driverId"));
            }

            var driver = m_Context.Driver.FirstOrDefault(c => c.Id == guid);

            if (driver == null)
            {
                return(NotFound("driverId Not Found"));
            }

            var courseLocationHistory =
                m_Context.VehicleLocationTimeHistory.Where(c => c.driverId == guid && c.dateTime >= startTime && c.dateTime <= stopTime);
            var dutyStatusLogs       = m_Context.LogEvent.Where(c => c.driverId == guid && c.dateTime >= startTime && c.dateTime <= stopTime);
            var vehicleFlaggedEvents =
                m_Context.VehicleFlaggedEvent.Where(c => c.driverId == guid && c.eventStart >= startTime && c.eventEnd <= stopTime);
            var locationhistoryModel = new CoarseVehicleLocationTimeHistoryModel(courseLocationHistory.ToList(), m_appSettings.ProviderId);

            var model = new DriverAvailability
            {
                CoarseVehicleLocationTimeHistory = locationhistoryModel,
                LogEvents            = LogEventsToLogEventModel(dutyStatusLogs.ToList()).ToArray(),
                VehicleFlaggedEvents = VehicleFlaggedEventsToVehicleFlaggedEventsModel(vehicleFlaggedEvents.ToList()).ToArray()
            };

            return(model);
        }
Example #2
0
        public async Task <ActionResult> Toggle([Bind(Include = "Driver,Status")] DriverAvailability driverAvailability)
        {
            if (ModelState.IsValid)
            {
                var isExist = await context.DriverAvailabilities.FindAsync(GetCurrentUser().Username);

                if (isExist == null)
                {
                    // No record exists, therefore add
                    context.DriverAvailabilities.Add(driverAvailability);
                }
                else
                {
                    // Record exists, therefore update
                    isExist.Status = driverAvailability.Status ? true : false;
                }

                var isStatusExist = await context.DriverStatusCounts.SingleOrDefaultAsync(d => d.Driver == driverAvailability.Driver && d.Date.Day == DateTime.Now.Day &&
                                                                                          d.Date.Month == DateTime.Now.Month && d.Date.Year == DateTime.Now.Year);

                DriverStatusCount statusCount = new DriverStatusCount();

                if (isStatusExist == null)
                {
                    // No record exists, therefore add
                    statusCount.Driver = driverAvailability.Driver;
                    if (driverAvailability.Status)
                    {
                        statusCount.OnlineCount += 1;
                    }
                    else
                    {
                        statusCount.OfflineCount += 1;
                    }
                    statusCount.Date = DateTime.Now.Date;
                    context.DriverStatusCounts.Add(statusCount);
                }
                else
                {
                    // Record exists, therefore update
                    if (driverAvailability.Status)
                    {
                        isStatusExist.OnlineCount += 1;
                    }
                    else
                    {
                        isStatusExist.OfflineCount += 1;
                    }
                }

                await context.SaveChangesAsync();
            }
            return(RedirectToAction("Toggle"));
        }
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            // Delete the record and redirect to create
            DriverLocation location = await context.DriverLocations.FindAsync(id);

            context.DriverLocations.Remove(location);
            DriverAvailability availability = await context.DriverAvailabilities.FindAsync(id);

            if (availability != null)
            {
                // Change availability status to false
                availability.Status = false;
            }
            await context.SaveChangesAsync();

            return(RedirectToAction("Create", new { Id = location.Driver }));
        }