예제 #1
0
 public List <Notification> GetNotificationsForService(int serviceId)
 {
     using (var c = new ServiceDBModel())
     {
         return(c.Notifications.Where(x => x.ServiceId == serviceId).ToList());
     }
 }
예제 #2
0
        public List <Service> GetAllWithDetails()
        {
            try
            {
                using (var c = new ServiceDBModel())
                {
                    c.Configuration.LazyLoadingEnabled   = false;
                    c.Configuration.ProxyCreationEnabled = false;
                    var services = c.Services.ToList();

                    foreach (var service in services)
                    {
                        var ServiceStatus = new ServiceStatusMgt().GetByServiceId(service.Id);
                        if (ServiceStatus != null)
                        {
                            service.LastUpdateTime  = ServiceStatus.LastUpdateTime;
                            service.LastWorkingTime = ServiceStatus.LastWorkingTime; // assign last status to service
                        }
                    }
                    var serviceList = services.OrderByDescending(o => DateTime.UtcNow - o.LastUpdateTime).ToList();

                    return(serviceList);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
예제 #3
0
 public List <ServiceOutage> GetServiceOutagesForService(int serviceId)
 {
     using (var c = new ServiceDBModel())
     {
         return(c.ServiceOutages.Where(x => x.ServiceId == serviceId).ToList());
     }
 }
예제 #4
0
        public ServiceStatus GetByServiceId(int id)
        {
            using (var c = new ServiceDBModel())

            {
                return(c.ServiceStatus.FirstOrDefault(x => x.ServiceId == id));
            }
        }
        public ServiceStatusLog GetLastWorkingTimeByServiceId(int id)
        {
            using (var c = new ServiceDBModel())

            {
                return(c.ServiceStatusLogs.Where(x => x.ServiceStatus.ServiceId == id && x.IsWorking).OrderByDescending(o => id).FirstOrDefault());
            }
        }
 public NotificationLog GetLastNotification(int serviceId)
 {
     using (var c = new ServiceDBModel())
     {
         return(c.NotificationLogs.Where(x => x.ServiceId == serviceId).OrderByDescending(o => o.Id)
                .FirstOrDefault());
     }
 }
예제 #7
0
 public bool IsServiceOutage(int serviceId)
 {
     using (var c = new ServiceDBModel())
     {
         return(c.ServiceOutages.Any(x =>
                                     x.ServiceId == serviceId && x.StartDateTime <= DateTime.Now && x.EndDateTime >= DateTime.Now));
     }
 }
예제 #8
0
 public List <NotificationType> GetAll()
 {
     using (var c = new ServiceDBModel())
     {
         c.Configuration.LazyLoadingEnabled   = false;
         c.Configuration.ProxyCreationEnabled = false;
         return(c.NotificationTypes.ToList());
     }
 }
예제 #9
0
 public Notification GetById(int id)
 {
     using (var c = new ServiceDBModel())
     {
         c.Configuration.LazyLoadingEnabled   = false;
         c.Configuration.ProxyCreationEnabled = false;
         return(c.Notifications.FirstOrDefault(x => x.Id == id));
     }
 }
 public ServiceStatusLog Add(ServiceStatusLog serviceStatusLog)
 {
     using (var c = new ServiceDBModel())
     {
         c.ServiceStatusLogs.Add(serviceStatusLog);
         c.SaveChanges();
         return(serviceStatusLog);
     }
 }
예제 #11
0
 public NotificationLog AddNotificationLog(NotificationLog notificationLog)
 {
     using (var c = new ServiceDBModel())
     {
         c.NotificationLogs.Add(notificationLog);
         c.SaveChanges();
         return(notificationLog);
     }
 }
예제 #12
0
 public List <Notification> GetByServiceId(int id)
 {
     using (var c = new ServiceDBModel())
     {
         c.Configuration.LazyLoadingEnabled   = false;
         c.Configuration.ProxyCreationEnabled = false;
         return(c.Notifications.Where(x => x.ServiceId == id).ToList());
     }
 }
예제 #13
0
 public Service Add(Service service)
 {
     try
     {
         using (var c = new ServiceDBModel())
         {
             c.Services.Add(service);
             c.SaveChanges();
             return(service);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
예제 #14
0
 public List <Notification> GetAll()
 {
     try
     {
         using (var c = new ServiceDBModel())
         {
             c.Configuration.LazyLoadingEnabled   = false;
             c.Configuration.ProxyCreationEnabled = false;
             return(c.Notifications.ToList());
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
예제 #15
0
 public Notification Add(Notification service)
 {
     try
     {
         using (var c = new ServiceDBModel())
         {
             c.Notifications.Add(service);
             c.SaveChanges();
             return(service);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
예제 #16
0
 public Notification Update(Notification service)
 {
     try
     {
         using (var c = new ServiceDBModel())
         {
             c.Entry(service).State = EntityState.Modified;
             c.SaveChanges();
             return(service);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
예제 #17
0
 public Notification Delete(Notification service)
 {
     try
     {
         using (var c = new ServiceDBModel())
         {
             c.Notifications.Remove(c.Notifications.FirstOrDefault(x => x.Id == service.Id));
             c.SaveChanges();
             return(service);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
예제 #18
0
        public bool UpdateServiceStatus(int serviceId, bool isWorking)
        {
            using (var c = new ServiceDBModel())
            {
                bool statusChanged;
                var  service = c.ServiceStatus.FirstOrDefault(x => x.ServiceId == serviceId);
                if (service != null)
                {
                    statusChanged           = service.IsWorking != isWorking; // check the service status is changed
                    service.LastUpdateTime  = DateTime.UtcNow;
                    service.LastWorkingTime = isWorking ? DateTime.UtcNow :service.LastWorkingTime;
                    service.IsWorking       = isWorking;
                    c.Entry(service).State  = EntityState.Modified;
                }
                else
                {
                    statusChanged = !isWorking;

                    service = new ServiceStatus
                    {
                        IsWorking       = isWorking,
                        LastUpdateTime  = DateTime.UtcNow,
                        LastWorkingTime = isWorking ? DateTime.UtcNow : (DateTime?)null,
                        ServiceId       = serviceId
                    };
                    c.ServiceStatus.Add(service);
                }

                c.SaveChanges();

                new ServiceStatusLogMgt().Add(new ServiceStatusLog
                {
                    CreatedTime     = DateTime.UtcNow,
                    IsWorking       = isWorking,
                    ServiceStatusId = service.Id,
                });
                return(statusChanged);
            }
        }