public ActionResult Index(int conferenceId = currentConference)
        {
            var conference = ConferenceLayer.GetConferenceById(IbaDb,conferenceId);
            var eventLocationData = Db.EventLocations.Where(r => r.ConferenceId == conferenceId);
            var eventLocations = new List<ScheduleEventLocationItemViewModel>();
            foreach(var evl in eventLocationData)
            {
                var floorName = Db.FloorNames.AsEnumerable().FirstOrDefault(r => r.Building == evl.Building && r.Floor == evl.Floor);
                eventLocations.Add(new ScheduleEventLocationItemViewModel()
                {
                    BuildingName = evl.Building.Name,
                    BuildingId = evl.Building.ScheduleEventBuildingId,
                    Id = evl.ScheduleEventLocationId,
                    RoomName = evl.LocationName,
                    CentreX = evl.CentreX,
                    CentreY = evl.CentreY,
                    Lat = evl.Lat,
                    Long = evl.Long,
                    TranslatedTitle = evl.TranslatedTitle,
                    Floor = evl.Floor,
                    FloorName = floorName != null ? floorName.Name : "",
                    IsOffsite = evl.IsOffsite
                });
            }
            var viewModel = new ScheduleEventLocationViewModel
            {
                EventName = conference.Name,
                Locations = eventLocations
            };

            return View(viewModel);
        }
        public HttpResponseMessage GetConferenceBuildingEvent(int id, int take = 20, int skip = 0)
        {
            var access = UserRights.V2Login(Db, Request);

            if (access.HasErrors)
            {
                return(Request.CreateErrorResponse(access.ErrorCode, access.ErrorMessage));
            }
            var result = ConferenceLayer.GetConferenceWithBuildingEventsById(CmsDb, Db, id, access.Session.record_id, take, skip);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
 public ActionResult MapSchedule(int conferenceId)
 {
     var result = ConferenceLayer.GetConfRoomsForConference(IbaDb, conferenceId);
     ConferenceLayer.CreateScheduleEventLocationsIfDoesntExist(Db, result);
     var vm = new MapScheduleViewModel()
     {
         Rooms = result,
         VenueName = "Sydney"
     };
     ViewBag.id = conferenceId;
     return View(vm);
 }
        public void LoadInSchedule(int conferenceId)
        {
            var allConferenceRooms = ConferenceLayer.GetConfRoomsForConference(IbaDb, conferenceId);
            for (var level = 2; level < 6; level++)
            {
                var path = Server.MapPath("~/App_Data/level" + level + ".json");
                using (var r = new StreamReader(path))
                {
                    var json = r.ReadToEnd();
                    var items = JsonConvert.DeserializeObject<List<ScheduleEventJsonViewModel>>(json);
                    foreach (var item in items)
                    {
                        var scheduleLocation = Db.EventLocations.SingleOrDefault(s => s.LocationName == item.linkedLocation);
                        if (scheduleLocation == null)
                        {
                            //NOTE: If no location exists check it's is valid
                            if(allConferenceRooms.Select(t=>t.RoomName).Contains(item.linkedLocation))
                            {
                                var roomEvent = new ScheduleEventLocation
                                {
                                    Floor = level,
                                    CentreX = item.centreX,
                                    CentreY = item.centreY,
                                    LocationName = item.linkedLocation,
                                    ConferenceId = conferenceId,

                                };
                                Db.EventLocations.Add(roomEvent);
                            }
                        } else
                        {
                            scheduleLocation.Floor = level;
                            scheduleLocation.ConferenceId = conferenceId;
                            scheduleLocation.CentreX = item.centreX;
                            scheduleLocation.CentreY = item.centreY;
                        }
                        
                        Db.SaveChanges();
                    }
                }
            }
        }
        //Returns the conference the user is attending next.
        public HttpResponseMessage Get(int id)
        {
            var access = UserRights.V2Login(Db, Request);

            if (access.HasErrors)
            {
                return(Request.CreateErrorResponse(access.ErrorCode, access.ErrorMessage));
            }
            var result = ConferenceLayer.GetConferenceById(Db, id);

            if (result.Start.HasValue && result.End.HasValue)
            {
                var start = result.Start.Value;
                var end   = result.End.Value;
                if (start < DateTime.UtcNow && end > DateTime.UtcNow)
                {
                    //Conference is Live
                    return(Request.CreateResponse(HttpStatusCode.OK, result));
                }
            }
            return(Request.CreateResponse(HttpStatusCode.NoContent, result));
        }
        public JsonResult SaveConferenceEvents([ModelBinder(typeof(JsonNetModelBinder))]ScheduleEventMainJsonViewModel model)
        {
            var allConferenceRooms = ConferenceLayer.GetConfRoomsForConference(IbaDb, model.id);


            foreach (var building in model.locations)
            {
                var floorNumber = 0;
                foreach(var floor in building.floors)
                {
                    foreach(var ev in floor)
                    {

                        //NOTE: Create building if needed
                        var scheduleLocation = Db.EventLocations.SingleOrDefault(s => s.LocationName == ev.linkedLocation);
                        if (scheduleLocation == null || ev.isOffsite)
                        {
                            //NOTE: First check if this location is offsite
                            if(ev.isOffsite)
                            {
                                var eventBuilding = Db.EventBuildings.SingleOrDefault(r => r.Name == "Offsite" && r.ConferenceId == model.id);
                                if( eventBuilding == null)
                                {
                                    eventBuilding = new ScheduleEventBuilding()
                                    {
                                        Name = "Offsite",
                                        ConferenceId = model.id,
                                    };
                                }

                                if (scheduleLocation != null)
                                {
                                    scheduleLocation.ConferenceId = model.id;
                                    scheduleLocation.Long = ev.lon;
                                    scheduleLocation.Lat = ev.lat;
                                    scheduleLocation.TranslatedTitle = ev.TranslatedTitle;
                                    scheduleLocation.Building = eventBuilding;
                                } else
                                {
                                    var roomEvent = new ScheduleEventLocation
                                    {
                                        IsOffsite = true,
                                        Long = ev.lon,
                                        Lat = ev.lat,
                                        TranslatedTitle = ev.TranslatedTitle,
                                        LocationName = ev.linkedLocation,
                                        ConferenceId = model.id,
                                        Building = eventBuilding

                                    };
                                    Db.EventLocations.Add(roomEvent);
                                }

                                
                                Db.SaveChanges();

                            } else
                            {
                                //NOTE: If no location exists check it's is valid
                                if (allConferenceRooms.Select(t => t.RoomName).Contains(ev.linkedLocation))
                                {
                                    var eventBuilding = Db.EventBuildings.SingleOrDefault(r => r.Name == building.buildingName && r.ConferenceId == model.id);
                                    if (eventBuilding == null)
                                    {
                                        eventBuilding = new ScheduleEventBuilding()
                                        {
                                            Name = building.buildingName,
                                            ConferenceId = model.id,
                                        };
                                    }
                                    var roomEvent = new ScheduleEventLocation
                                    {
                                        Floor = floorNumber,
                                        CentreX = ev.centreX,
                                        CentreY = ev.centreY,
                                        LocationName = ev.linkedLocation,
                                        ConferenceId = model.id,
                                        Building = eventBuilding

                                    };
                                    Db.EventLocations.Add(roomEvent);
                                    Db.SaveChanges();
                                }
                            }
                        }
                        else
                        {
                            var eventBuilding = Db.EventBuildings.SingleOrDefault(r => r.Name == building.buildingName && r.ConferenceId == model.id);
                            if (eventBuilding == null)
                            {
                                eventBuilding = new ScheduleEventBuilding()
                                {
                                    Name = building.buildingName,
                                    ConferenceId = model.id,
                                };
                            }
                            scheduleLocation.Floor = floorNumber;
                            scheduleLocation.ConferenceId = model.id;
                            scheduleLocation.CentreX = ev.centreX;
                            scheduleLocation.CentreY = ev.centreY;
                            scheduleLocation.Building = eventBuilding;
                            Db.SaveChanges();

                        }
                    }
                    floorNumber += 1;
                }
            }
            return new JsonResult();
        }