Ejemplo n.º 1
0
        public List <Notification> GetAll()
        {
            List <Notification> notifications = new List <Notification>();

            try
            {
                var json     = apiCalls.GetRequest(apiConfig.Url + apiConfig.GetAllNotifications);
                var messages = JObject.Parse(json)["Messages"];
                foreach (var message in messages)
                {
                    Notification notification = JsonConvert.DeserializeObject <Notification>(message.ToString());
                    notifications.Add(notification);
                }
            }
            catch (Exception e)
            {
                var stackTrace = new StackTrace(e, true);
                var frame      = stackTrace.GetFrame(0);
                var line       = frame.GetFileLineNumber();
                var file       = frame.GetFileName();

                logger.LogError($"{DateTime.Now} - [{file} : {line}] Cannot get notifications from API");
            }

            return(notifications);
        }
        public List <Room> GetAll()
        {
            List <Room> rooms = new List <Room>();

            try
            {
                var json       = apiCalls.GetRequest(apiConfig.Url + apiConfig.GetAllRooms);
                var classRooms = JObject.Parse(json)["Classroom"];

                foreach (JToken classroom in classRooms)
                {
                    foreach (JToken room in classroom.Children())
                    {
                        Room r = JsonConvert.DeserializeObject <Room>(room.ToString());
                        rooms.Add(r);
                    }
                }
            }
            catch (Exception e)
            {
                var stackTrace = new StackTrace(e, true);
                var frame      = stackTrace.GetFrame(0);
                var line       = frame.GetFileLineNumber();
                var file       = frame.GetFileName();

                logger.LogError($"{DateTime.Now} - [{file} : {line}] Cannot get rooms from API");
            }

            return(rooms);
        }
Ejemplo n.º 3
0
        private Dictionary <int, Dictionary <int, Reservation> > GetWeekFromApi(string roomName, int year, int week)
        {
            string parameters = $"/{roomName}/{year}/{week}";
            Dictionary <int, Dictionary <int, Reservation> > reservationsForWeek = new Dictionary <int, Dictionary <int, Reservation> >();

            try
            {
                logger.LogInformation($"{DateTime.Now} - Getting week {roomName}, {year}, {week} from API");

                var json      = apiCalls.GetRequest(apiConfig.Url + apiConfig.GetWeek + parameters);
                var days      = JObject.Parse(json)["Days"];
                int dayNumber = 1;

                foreach (var day in days)
                {
                    reservationsForWeek.Add(dayNumber, new Dictionary <int, Reservation>());
                    var hours = JObject.Parse(day.ToString())["Hours"];

                    foreach (var hour in hours)
                    {
                        Reservation reservation = hour.ToObject <Reservation>();
                        reservation.RoomId = roomName;
                        reservationsForWeek[dayNumber].Add(reservation.HourId, reservation);
                    }

                    for (int i = 1; i <= 15; i++)
                    {
                        if (!reservationsForWeek[dayNumber].ContainsKey(i))
                        {
                            reservationsForWeek[dayNumber].Add(i, null);
                        }
                    }
                    dayNumber++;
                }
                reservationsForWeek.Add(0, GetEmptyDay());
                reservationsForWeek.Add(6, GetEmptyDay());
            }
            catch (Exception e)
            {
                var stackTrace = new StackTrace(e, true);
                var frame      = stackTrace.GetFrame(0);
                var line       = frame.GetFileLineNumber();
                var file       = frame.GetFileName();

                logger.LogError($"{DateTime.Now} - [{file} : {line}] GetWeek({roomName}, {year}, {week}) NOT FOUND");
                logger.LogInformation($"{DateTime.Now} - Returning empty week");

                for (int i = 0; i < 7; i++)
                {
                    reservationsForWeek.Add(i, GetEmptyDay());
                }
            }
            return(reservationsForWeek);
        }
 public string GetAllUsers()
 {
     try
     {
         apiCallString = _apiCalls.GetRequest(apiConfig.Url + apiConfig.GetUsers);
     }
     catch (Exception e)
     {
         var stackTrace = new StackTrace(e, true);
         var frame      = stackTrace.GetFrame(0);
         var line       = frame.GetFileLineNumber();
         var file       = frame.GetFileName();
         _logger.LogError($"{DateTime.Now} - {file} : {line}] Cannot get users from API");
     }
     return(apiCallString);
 }