public List <Notification> GetNotificationsForService(int serviceId) { using (var c = new ServiceDBModel()) { return(c.Notifications.Where(x => x.ServiceId == serviceId).ToList()); } }
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); } }
public List <ServiceOutage> GetServiceOutagesForService(int serviceId) { using (var c = new ServiceDBModel()) { return(c.ServiceOutages.Where(x => x.ServiceId == serviceId).ToList()); } }
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()); } }
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)); } }
public List <NotificationType> GetAll() { using (var c = new ServiceDBModel()) { c.Configuration.LazyLoadingEnabled = false; c.Configuration.ProxyCreationEnabled = false; return(c.NotificationTypes.ToList()); } }
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); } }
public NotificationLog AddNotificationLog(NotificationLog notificationLog) { using (var c = new ServiceDBModel()) { c.NotificationLogs.Add(notificationLog); c.SaveChanges(); return(notificationLog); } }
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()); } }
public Service Add(Service service) { try { using (var c = new ServiceDBModel()) { c.Services.Add(service); c.SaveChanges(); return(service); } } catch (Exception e) { return(null); } }
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); } }
public Notification Add(Notification service) { try { using (var c = new ServiceDBModel()) { c.Notifications.Add(service); c.SaveChanges(); return(service); } } catch (Exception e) { return(null); } }
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); } }
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); } }
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); } }