Example #1
0
 public HttpResponseMessage Post([FromBody] TimeSlotVM times)
 {
     try
     {
         var roomList = roomInfo.GetRoomsByTime(times);
         if (roomInfo != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, roomList));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "room is not available at this time slot"));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Example #2
0
        public List <RoomVM> GetRoomsByTime(TimeSlotVM times)
        {
            try
            {
                DateTime startTime = times.StartTime;
                DateTime endTime   = times.EndTime;
                var      roomList  = new List <RoomVM>();
                using (TrainingAppEntities1 dc = new TrainingAppEntities1())
                {
                    var bookedSlotList = dc.Schedules.Where(a => a.StartTime == startTime || a.EndTime == endTime || (a.StartTime <endTime && a.StartTime> startTime) || (startTime > a.StartTime && endTime < a.EndTime) || (endTime > a.EndTime && startTime < a.StartTime));

                    HashSet <int?> bookedIdList  = new HashSet <int?>();
                    var            uniqueDetails = dc.RoomDetails.ToList();
                    int            count         = 0;

                    foreach (var item in bookedSlotList)
                    {
                        bookedIdList.Add(item.RoomId);
                        count++;
                    }
                    Console.WriteLine(count);
                    foreach (var item in bookedIdList)
                    {
                        uniqueDetails.RemoveAll(a => a.RoomId == item);
                    }
                    foreach (var item in uniqueDetails)
                    {
                        RoomVM roomVM = new RoomVM();
                        roomVM.RoomId   = item.RoomId;
                        roomVM.RoomName = item.RoomName;
                        roomList.Add(roomVM);
                    }
                }
                return(roomList);
            }
            catch (Exception)
            {
                return(null);
            }
        }