Exemple #1
0
        public int AddTrip(TripVm trip, string userName)
        {
            var tripRepo = _repository;
            var tripId   = tripRepo.AddTrip(trip, userName);

            return(tripId);
        }
        public int AddTrip(TripVm tripVm, string userName)
        {
            var trip = new Trip
            {
                OperationalIntervalId = tripVm.OperationalIntervalId,
                LineId        = tripVm.LineId,
                ArrivalTime   = TimeSpan.Parse(tripVm.ArrivalTime),
                DepartureTime = TimeSpan.Parse(tripVm.DepartureTime)
            };

            if (tripVm.Schedules != null)
            {
                trip.Schedules = tripVm.Schedules.Select(a => new Schedule
                {
                    ArrivalTime   = a.ArrivalTime,
                    DepartureTime = a.DepartureTime,
                    StationId     = a.StationId
                }).ToList();
            }

            using (Oblig1Context db = new Oblig1Context())
            {
                db.Trips.Add(trip);
                db.SaveChanges();
            }

            return(trip.Id);
        }
Exemple #3
0
        public ActionResult UpdateTrip(TripVm trip)
        {
            var tripService = new TripService();

            tripService.UpdateTrip(trip, User.Identity.Name);

            return(RedirectToAction("DetailsTrip", new { id = trip.Id }));
        }
Exemple #4
0
        public ActionResult Addtrip(TripVm trip)
        {
            var tripService = new TripService();

            tripService.AddTrip(trip, User.Identity.Name);

            return(RedirectToAction("Index"));
        }
        public int AddTrip(TripVm tripVm, string userName)
        {
            var trip = new Trip
            {
                Id = 1
            };

            return(trip.Id);
        }
        public TripVm GetTrip(int id)
        {
            var trip = new TripVm
            {
                Id = 1,
                OperationalIntervalId   = 1,
                OperationalIntervalName = "Sommerruter",
                LineId        = 1,
                LineName      = "Stavanger - Audnedal",
                DepartureTime = "12:15",
                ArrivalTime   = "14:35"
            };

            return(trip);
        }
        static void Main(string[] args)
        {
            StreamReader jsonFile = new StreamReader(@"c:\data\tripdata.json");
            TripVm       TripData = JsonConvert.DeserializeObject <TripVm>(jsonFile.ReadToEnd());

            TimeSpan totalChannelAlarmDuration, totalChannelEventDuration, totalOverallDuration = new TimeSpan();

            foreach (var setting in TripData.TripSettings)
            {
                totalOverallDuration += totalChannelAlarmDuration = checkAlarms(setting.ChannelName, TripData);
                totalOverallDuration += totalChannelEventDuration = checkEvents(setting.ChannelName, TripData);
            }

            Console.WriteLine("\nTOTAL TIME IN ALARM : {0}", totalOverallDuration);

            Console.ReadKey(true);
        }
        static TimeSpan checkAlarms(string channel, TripVm TripData)
        {
            var UploadData = (from uploadData in TripData.TripUploadData where uploadData.Channel == channel select uploadData).OrderBy(ud => ud.Timestamp).ToList();

            DateTime?beginAlarm = null;
            TimeSpan alarmDuration, totalDuration = new TimeSpan();
            var      MinSetting = TripData.TripSettings.Where(ts => ts.ChannelName == channel).FirstOrDefault().Min;
            var      MaxSetting = TripData.TripSettings.Where(ts => ts.ChannelName == channel).FirstOrDefault().Max;

            foreach (var uploadData in UploadData)
            {
                if ((uploadData.Data < MinSetting || uploadData.Data > MaxSetting) && beginAlarm == null)
                {
                    Console.WriteLine("{0} - {1} : ", channel.ToUpper(), TripData.TripSettings.Where(ts => ts.ChannelName == channel).FirstOrDefault().DataType);
                    beginAlarm = uploadData.Timestamp;
                    Console.WriteLine("Entered Alarm @ {0}", beginAlarm.ToString());
                }
                if (uploadData.Data >= MinSetting && uploadData.Data <= MaxSetting && beginAlarm != null)
                {
                    Console.WriteLine("Exited Alarm @ {0}", uploadData.Timestamp.ToString());
                    alarmDuration = uploadData.Timestamp.Subtract((DateTime)beginAlarm);
                    Console.WriteLine("\t\t\t{0} Alarm Duration : {1}\n", channel, alarmDuration.ToString());
                    beginAlarm = null;

                    totalDuration += alarmDuration;
                }
            }

            // Checks if there are still Alarms at Collection Ending
            if (beginAlarm != null)
            {
                alarmDuration  = TripData.EndTime.Subtract((DateTime)beginAlarm);
                totalDuration += alarmDuration;
                Console.WriteLine("Exited Alarm @ {0}", TripData.EndTime.ToString());
                Console.WriteLine("\t\t\t{0} Alarm Duration : {1}\n", channel, alarmDuration.ToString());
                beginAlarm = null;
            }

            Console.WriteLine("\t\t\t\tTotal {0} Alarm duration : {1}\n", channel, totalDuration.ToString());
            return(totalDuration);
        }
        static TimeSpan checkEvents(string channel, TripVm TripData)
        {
            var uploadEvents = (from uploadEvent in TripData.TripUploadEvents where uploadEvent.Channel == channel select uploadEvent).OrderBy(ud => ud.Timestamp).ToList();

            DateTime?beginAlarm = null;
            TimeSpan alarmDuration, totalDuration = new TimeSpan();

            foreach (var uploadEvent in uploadEvents)
            {
                if (((AlarmState)uploadEvent.EventType == AlarmState.MaxAlarmOut || (AlarmState)uploadEvent.EventType == AlarmState.MinAlarmOut) && beginAlarm == null)
                {
                    Console.WriteLine("{0} - {1} : ", channel.ToUpper(), TripData.TripSettings.Where(ts => ts.ChannelName == channel).FirstOrDefault().DataType);
                    beginAlarm = uploadEvent.Timestamp;
                    Console.WriteLine("Entered Event @ {0}", beginAlarm.ToString());
                }
                if (((AlarmState)uploadEvent.EventType == AlarmState.MaxAlarmIn || (AlarmState)uploadEvent.EventType == AlarmState.MinAlarmIn) && beginAlarm != null)
                {
                    Console.WriteLine("Exited Event @ {0}", uploadEvent.Timestamp.ToString());
                    alarmDuration = uploadEvent.Timestamp.Subtract((DateTime)beginAlarm);
                    Console.WriteLine("\t\t\t{0} Event Duration : {1}\n", channel, alarmDuration.ToString());
                    beginAlarm = null;

                    totalDuration += alarmDuration;
                }
            }

            // Checks if there are still Events Open at Collection Ending
            if (beginAlarm != null)
            {
                alarmDuration  = TripData.EndTime.Subtract((DateTime)beginAlarm);
                totalDuration += alarmDuration;
                Console.WriteLine("Exited Event @ {0}", TripData.EndTime.ToString());
                Console.WriteLine("\t\t\t{0} Event Duration : {1}\n", channel, alarmDuration.ToString());
                beginAlarm = null;
            }

            Console.WriteLine("\t\t\t\tTotal {0} Event duration : {1}\n", channel, totalDuration.ToString());
            return(totalDuration);
        }
        public List <TripVm> GetTrips()
        {
            using (Oblig1Context db = new Oblig1Context())
            {
                var tripList = new List <TripVm>();
                var tripItem = new TripVm()
                {
                    Id = 1,
                    OperationalIntervalId   = 1,
                    OperationalIntervalName = "Sommerruter",
                    LineId        = 1,
                    LineName      = "Stavanger - Audnedal",
                    DepartureTime = "12:15",
                    ArrivalTime   = "14:35"
                };
                tripList.Add(tripItem);
                tripList.Add(tripItem);
                tripList.Add(tripItem);

                return(tripList);
            }
        }
Exemple #11
0
        public void UpdateTrip(TripVm trip, string userName)
        {
            var tripRepo = _repository;

            tripRepo.UpdateTrip(trip, userName);
        }
        public void UpdateTrip(TripVm tripVm, string userName)
        {
            using (Oblig1Context db = new Oblig1Context())
            {
                var tripDb = db.Trips.Where(a => a.Id == tripVm.Id).SingleOrDefault();

                if (tripDb != null)
                {
                    var auditLog = new AuditLog
                    {
                        TimeStamp = DateTime.Now,
                        Model     = nameof(Trip),
                        Type      = AuditType.Updated,
                        User      = userName
                    };

                    var sb = new StringBuilder();

                    if (tripDb.LineId != tripVm.LineId)
                    {
                        sb.AppendLine($"Updated Line from: {tripDb.Line.LineName} To: {tripVm.LineName}");
                    }

                    if (tripDb.OperationalIntervalId != tripVm.OperationalIntervalId)
                    {
                        sb.AppendLine($"Updated OperationalInterval from: {tripDb.OperationalInterval.Name} To: {tripVm.OperationalIntervalName}");
                    }

                    if (tripDb.LineId != tripVm.LineId)
                    {
                        sb.AppendLine($"Updated Line from: {tripDb.Line.LineName} To: {tripVm.LineName}");
                    }

                    var arrivalTime   = TimeSpan.Parse(tripVm.ArrivalTime);
                    var departureTime = TimeSpan.Parse(tripVm.DepartureTime);

                    if (tripDb.ArrivalTime != arrivalTime)
                    {
                        sb.AppendLine($"Updated ArrivalTime from: {tripDb.ArrivalTime} To: {arrivalTime}");
                    }

                    if (tripDb.DepartureTime != departureTime)
                    {
                        sb.AppendLine($"Updated DepartureTime from: {tripDb.DepartureTime} To: {departureTime}");
                    }

                    auditLog.Log = sb.ToString();

                    tripDb.OperationalIntervalId = tripVm.OperationalIntervalId;
                    tripDb.LineId        = tripVm.LineId;
                    tripDb.ArrivalTime   = arrivalTime;
                    tripDb.DepartureTime = departureTime;

                    if (tripVm.Schedules == null || tripVm.Schedules.Count == 0)
                    {
                        db.Schedules.RemoveRange(tripDb.Schedules);
                    }
                    else
                    {
                        var scheduleIds       = tripVm.Schedules.Select(a => a.Id).ToList();
                        var schedulesToRemove = tripDb.Schedules.Where(a => !scheduleIds.Contains(a.Id));
                        var schedulesToUpdate = tripDb.Schedules.Where(a => scheduleIds.Contains(a.Id));
                        var schedulesToAdd    = tripVm.Schedules.Where(a => a.Id == 0);

                        if (schedulesToRemove.Any())
                        {
                            db.Schedules.RemoveRange(schedulesToRemove);
                        }

                        foreach (var schedule in schedulesToUpdate)
                        {
                            var scheduleVm = tripVm.Schedules.Single(a => a.Id == schedule.Id);

                            schedule.StationId     = scheduleVm.StationId;
                            schedule.ArrivalTime   = scheduleVm.ArrivalTime;
                            schedule.DepartureTime = scheduleVm.DepartureTime;
                        }

                        foreach (var schedule in schedulesToAdd)
                        {
                            tripDb.Schedules.Add(new Schedule
                            {
                                StationId     = schedule.StationId,
                                ArrivalTime   = schedule.ArrivalTime,
                                DepartureTime = schedule.DepartureTime
                            });
                        }
                    }

                    if (!string.IsNullOrEmpty(auditLog.Log))
                    {
                        db.AuditLogs.Add(auditLog);
                    }

                    db.SaveChanges();
                }
            }
        }
 public void UpdateTrip(TripVm tripVm, string userName)
 {
 }