public async Task <IActionResult> Create([Bind("SessionId,Name,Description,SkillLevel,Keywords")] Session session) { if (ModelState.IsValid) { var theEvent = await _eventBL.GetActiveEvent(); if (theEvent != null) { session.EventId = theEvent.EventId; // Add the user to the list of speakers Speaker speaker = null; // Get the user information var user = await _userManager.GetUserAsync(User); // Does the user exist and are they a speaker? if (user != null && user.SpeakerId.HasValue) { speaker = await _speakerBL.GetSpeaker(user.SpeakerId.Value); } // If the user is not a speaker, return to the speakers page if (speaker == null) { return(RedirectToAction(nameof(Index))); } await _sessionBL.CreateSession(session, speaker.SpeakerId); return(RedirectToAction(nameof(Index))); } } return(View(session)); }
public async Task <IActionResult> OnGetAsync(string returnUrl = null) { var theEvent = await _eventBL.GetActiveEvent(); Event = new EventData { EventTitle = theEvent != null ? theEvent.Name : "the current event was not found." }; return(Page()); }
public async Task <IActionResult> Index() { var viewModel = new HomePageViewModel { Event = await _eventBL.GetActiveEvent(), Announcements = await _announcementBL.GetActiveAnnouncementsViewModelForActiveEvent(), FeaturedSponsor = await _sponsorBL.GetRandomSponsor() }; return(View(viewModel)); }
public async Task <IActionResult> Create([Bind("TimeslotId,StartTime,EndTime,ContainsNoSessions,Name,EventId")] Timeslot timeslot) { if (ModelState.IsValid) { var theEvent = await _eventBL.GetActiveEvent(); if (theEvent != null) { timeslot.EventId = theEvent.EventId; await _timeslotBL.CreateTimeslot(timeslot); return(RedirectToAction(nameof(Index))); } } return(View(timeslot)); }
// POST: Announcements/Create public async Task <IActionResult> Create([Bind("AnnouncementId,Message,Rank,PublishOn,ExpiresOn")] Announcement announcement) { if (ModelState.IsValid) { var theEvent = await _eventBL.GetActiveEvent(); if (theEvent != null) { announcement.EventId = theEvent.EventId; await _announcementBL.CreateAnnouncement(announcement); return(RedirectToAction(nameof(Index))); } } return(View(announcement)); }
public async Task <IActionResult> Create([Bind("TrackId,Name,RoomNumber,EventId")] Track track) { if (ModelState.IsValid) { var theEvent = await _eventBL.GetActiveEvent(); if (theEvent != null) { track.EventId = theEvent.EventId; await _trackBL.CreateTrack(track); return(RedirectToAction(nameof(Index))); } } return(View(track)); }
public async Task <IActionResult> Create([Bind("SponsorId,CompanyName,SponsorLevel,Bio,TwitterHandle,WebsiteUrl,ImageFile,PointOfContact,EmailAddress,PhoneNumber")] SponsorViewModel sponsorVM) { if (ModelState.IsValid) { var theEvent = await _eventBL.GetActiveEvent(); if (theEvent != null) { var sponsor = new Sponsor { SponsorId = sponsorVM.SponsorId, CompanyName = sponsorVM.CompanyName, SponsorLevel = sponsorVM.SponsorLevel, Bio = sponsorVM.Bio, TwitterHandle = sponsorVM.TwitterHandle, WebsiteUrl = sponsorVM.WebsiteUrl, PointOfContact = sponsorVM.PointOfContact, EmailAddress = sponsorVM.EmailAddress, PhoneNumber = sponsorVM.PhoneNumber, EventId = theEvent.EventId }; // Convert the image to a byte array, reduce the size to 500px x 500px // and store it in the database if (sponsorVM.ImageFile != null && sponsorVM.ImageFile.ContentType.ToLower().StartsWith("image/") && sponsorVM.ImageFile.Length <= SponsorViewModel.MaxImageSize) { MemoryStream ms = new MemoryStream(); sponsorVM.ImageFile.OpenReadStream().CopyTo(ms); sponsor.Image = _sponsorBL.ResizeImage(ms.ToArray()); } await _sponsorBL.CreateSponsor(sponsor); return(RedirectToAction(nameof(Index))); } } ViewBag.SponsorshipLevels = SponsorLevel.GetSponsorshipLevels(); return(View(sponsorVM)); }
public async Task <IActionResult> OnGetAsync(string loginWithRegistration = null) { ViewData["MaxImageSize"] = SpeakerViewModel.MaxImageSize / 1000; LoginWithRegistration = loginWithRegistration; var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } // Finish registering the user as a speaker if (loginWithRegistration == "Speaker") { // Set role as Speaker user.IsAttending = true; user.IsSpeaker = true; await _userManager.AddToRoleAsync(user, "Speaker"); // Remove Attendee role await _userManager.RemoveFromRoleAsync(user, "Attendee"); // Set the users event to the current event var currentEvent = await _eventBL.GetActiveEvent(); if (user.EventId.HasValue == false || (user.EventId.HasValue == true && user.EventId.Value != currentEvent.EventId)) { user.EventId = currentEvent.EventId; } // Save the changes await _context.SaveChangesAsync(); } else if (LoginWithRegistration == "Attendee") { // Set role as Speaker user.IsAttending = true; // Set the users event to the current event var currentEvent = await _eventBL.GetActiveEvent(); if (user.EventId.HasValue == false || (user.EventId.HasValue == true && user.EventId.Value != currentEvent.EventId)) { user.EventId = currentEvent.EventId; } // Save the changes await _context.SaveChangesAsync(); } IsSpeaker = User.IsInRole("Speaker"); var userName = await _userManager.GetUserNameAsync(user); var email = await _userManager.GetEmailAsync(user); var phoneNumber = await _userManager.GetPhoneNumberAsync(user); Username = userName; if (IsSpeaker && user.SpeakerId.HasValue) { // Retrieve the associated speaker var speaker = await _speakerBL.GetSpeakerViewModel(user.SpeakerId.Value); Input = new InputModel() { SpeakerId = speaker.SpeakerId, FirstName = user.FirstName, LastName = user.LastName, GeographicLocation = user.GeographicLocation, TwitterHandle = user.TwitterHandle, IsVolunteer = user.IsVolunteer, Email = email, PhoneNumber = phoneNumber, CompanyName = speaker != null ? speaker.CompanyName : string.Empty, Bio = speaker != null ? speaker.Bio : string.Empty, WebsiteUrl = speaker != null ? speaker.WebsiteUrl : string.Empty, BlogUrl = speaker != null ? speaker.BlogUrl : string.Empty, LinkedIn = speaker != null ? speaker.LinkedIn : string.Empty, IsMvp = speaker != null ? speaker.IsMvp : false, NoteToOrganizers = speaker != null ? speaker.NoteToOrganizers : string.Empty }; } else // An Attendee { Input = new InputModel { FirstName = user.FirstName, LastName = user.LastName, GeographicLocation = user.GeographicLocation, TwitterHandle = user.TwitterHandle, IsVolunteer = user.IsVolunteer, Email = email, PhoneNumber = phoneNumber }; } IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user); return(Page()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { if (ModelState.IsValid) { // Get the current event var theEvent = await _eventBL.GetActiveEvent(); var user = new CodecampUser { IsAttending = true, IsSpeaker = false, UserName = Input.Email, Email = Input.Email, IsVolunteer = Input.IsVolunteer, EventId = theEvent != null ? theEvent.EventId : (int?)null }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _userManager.AddToRoleAsync(user, "Attendee"); // Save the DB changes await _context.SaveChangesAsync(); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); // Generate and send a confirmation email to the user await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); // Redirect to the registration almost complete page return(RedirectToPage("./RegistrationAlmostComplete")); } foreach (var error in result.Errors) { if (error.Code == "DuplicateUserName") { // The account currently exists, redirect to login page, note // this is to complete speaker registration. return(RedirectToPage("./Login", new { ReturnUrl = "./Manage/Index", LoginWithRegistration = "Attendee", Email = Input.Email // pass the email/username for convenience })); } ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }