public ActionResult Create(Conference conference)
        {
            if (!IsConferenceHashTagAvailable(conference.HashTag))
            {
                ModelState.AddModelError("HashTag", "Unfortunately that hashtag is not available.");
            }

            if (ModelState.IsValid)
            {
                var conferenceTimeZone = TimeZoneInfo.FindSystemTimeZoneById(conference.TimeZoneId);
                conference.StartDate = TimeZoneInfo.ConvertTimeToUtc(conference.StartDate, conferenceTimeZone);
                conference.EndDate = TimeZoneInfo.ConvertTimeToUtc(conference.EndDate, conferenceTimeZone);

                var currentUserProfile = YouConfDbContext.UserProfiles.FirstOrDefault(x => x.UserName == User.Identity.Name);
                conference.Administrators.Add(currentUserProfile);

                YouConfDbContext.Conferences.Add(conference);
                YouConfDbContext.SaveChanges();

                UpdateConferenceInSolrIndex(conference.Id, Common.Messaging.SolrIndexAction.Update);

                return RedirectToAction("Details", new { hashTag = conference.HashTag });
            }
            return View(conference);
        }
 public ActionResult Create()
 {
     var model = new Conference()
     {
         StartDate = DateTime.UtcNow,
         EndDate = DateTime.UtcNow.AddDays(1)
     };
     return View(model);
 }
        public void Create_WithAlreadyUsedHashTag_Should_ReturnViewAndAddModelError()
        {
            _context.Conferences.Add(new Conference() { HashTag = "abcde", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = false });
            _context.SaveChangesWithErrors();

            var conferenceController = new ConferenceController(_context);

            var newConference = new Conference() { HashTag = "abcde" };
            var result = conferenceController.Create(newConference)
                .As<ViewResult>();

            result.ViewData.ModelState["HashTag"]
                .Errors
                .Count
                .Should()
                .Be(1);
        }
        public void Details_WithValidHashTag_Should_ReturnCorrectConference()
        {
            var stubConference = new Conference() { HashTag = "abcde", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = true };
            _context.Conferences.Add(stubConference);
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = false });
            _context.SaveChangesWithErrors(); ;

            var conferenceController = new ConferenceController(_context);
            conferenceController.ControllerContext = TestHelper.MockContext(conferenceController, "TestUser");

            var result = conferenceController.Details("abcde")
                .As<ViewResult>();

            result.Model
                .As<Conference>()
                .Should()
                .Be(stubConference);
        }
        private void PopulateSpeakers(Conference conference, Presentation presentation, long[] speakerIds)
        {
            presentation.Speakers.Clear();

            //Could look at creating a custom model binder here, but doing it simple for now....
            if (speakerIds == null)
                return;

            foreach (var speakerId in speakerIds)
            {
                var speaker = conference.Speakers.First(x => x.Id == speakerId);
                presentation.Speakers.Add(speaker);
            }
        }
 private bool IsCurrentUserAuthorizedToAdministerConference(Conference conference)
 {
     var userProfile = YouConfDbContext.UserProfiles.FirstOrDefault(x => x.UserName == User.Identity.Name);
     return conference.Administrators.Contains(userProfile);
 }
        public ActionResult Edit(string currentHashTag, Conference conference)
        {
            //If the user has changed the conference hashtag we have to make sure that the new one hasn't already been taken
            if (currentHashTag != conference.HashTag && !IsConferenceHashTagAvailable(conference.HashTag))
            {
                ModelState.AddModelError("HashTag", "Unfortunately that hashtag is not available.");
            }

            if (ModelState.IsValid)
            {
                var existingConference = YouConfDbContext.Conferences
                .FirstOrDefault(x => x.Id == conference.Id);
                if (conference == null)
                {
                    return HttpNotFound();
                }
                if (!IsCurrentUserAuthorizedToAdministerConference(existingConference))
                {
                    return HttpUnauthorized();
                }

                var conferenceTimeZone = TimeZoneInfo.FindSystemTimeZoneById(conference.TimeZoneId);
                conference.StartDate = TimeZoneInfo.ConvertTimeToUtc(conference.StartDate, conferenceTimeZone);
                conference.EndDate = TimeZoneInfo.ConvertTimeToUtc(conference.EndDate, conferenceTimeZone);

                var hasHangoutIdUpdated = existingConference.HangoutId != conference.HangoutId;

                Mapper.Map(conference, existingConference);
                YouConfDbContext.SaveChanges();

                if (hasHangoutIdUpdated)
                {
                    //User has changed the conference hangout id, so notify any listeners/viewers out there if they're watching (e.g. during the live conference streaming)
                    var context = GlobalHost.ConnectionManager.GetHubContext<YouConfHub>();
                    context.Clients.Group(conference.HashTag).updateConferenceVideoUrl(conference.HangoutId);
                }

                UpdateConferenceInSolrIndex(conference.Id, Common.Messaging.SolrIndexAction.Update);

                return RedirectToAction("Details", new { hashTag = conference.HashTag });
            }

            return View(conference);
        }