public void NewProject(int defaultPage) { ProjectViewModel projectViewModel = new ProjectViewModel(_context); SetupViewModel setupViewModel = new SetupViewModel(_appModel.NewSetupModel(), _context); ParticipantsViewModel participantsViewModel = new ParticipantsViewModel(_appModel.NewParticipantsModel(), _context); PreferencesViewModel preferencesViewModel = new PreferencesViewModel(_appModel.NewPreferencesModel(), _context); AlgorithmViewModel algorithmViewModel = new AlgorithmViewModel(_appModel.NewAlgorithmModel(), _context); RunViewModel runViewModel = new RunViewModel(_appModel.NewRunModel(), _context); runViewModel.CheckSolution += new EventHandler <int>(OnNewResultWindow); _pages.Clear(); _pages.Add(projectViewModel); _pages.Add(setupViewModel); _pages.Add(participantsViewModel); _pages.Add(preferencesViewModel); _pages.Add(algorithmViewModel); _pages.Add(runViewModel); foreach (IPageTurn page in _pages) { page.NextPage += new EventHandler(Context_NextPage); page.PreviousPage += new EventHandler(Context_PreviousPage); } //_context.ReadyChanged += new EventHandler(Context_ReadyChanged); CurrentPage = _pages[defaultPage]; }
public ActionResult Edit(ParticipantsViewModel participant) { var isAdmin = EntityFetcher.FetchUserAdminStatus(Methods.GetUsernameFromCookie(HttpContext)); ViewBag.isAdmin = isAdmin; if (isAdmin == true) { if (ModelState.IsValid) { try { EntityModifier.EditParticipant(participant); } catch { ModelState.AddModelError("Name", "Can't modify the participant."); } return(RedirectToAction("Index")); } return(View(participant)); } return(RedirectToAction("Login", "Home")); }
public ActionResult Reminders(int id, [Bind(Include = "Reminder, emailNotificationOn, SMSNotificationOn, EventStartDate, PhoneNumber")] RemindersViewModel remindersViewModel) { if (id <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { ParticipantQuery pq = new ParticipantQuery(); ParticipantDTO pDTO = new ParticipantDTO(); ParticipantDTO pdt = pq.FindParticipant(id); ParticipantsViewModel pvm = new ParticipantsViewModel(); EventQuery eq = new EventQuery(); EventDTO edto = eq.FindEvent(pdt.eventId); pDTO.Reminder = remindersViewModel.Reminder; pDTO.emailNotificationOn = remindersViewModel.emailNotificationOn; pDTO.SMSNotificationOn = remindersViewModel.SMSNotificationOn; pDTO.Id = id; pDTO.Phone = remindersViewModel.PhoneNumber; pq.UpdateParticipantReminders(pDTO); return(RedirectToAction("ReminderConfirmation", "Participants")); } return(View(remindersViewModel)); }
public ActionResult Payment(int id) { ParticipantsViewModel participantsViewModel = new ParticipantsViewModel(); if ((TempData.ContainsKey("Reminder")) && (TempData["Reminder"] != null)) { participantsViewModel.Reminder = DateTime.Parse(TempData["Reminder"].ToString()); } if (TempData.ContainsKey("NumberOfTickets")) { participantsViewModel.NumberOfTicket = int.Parse(TempData["NumberOfTickets"].ToString()); } if (TempData.ContainsKey("TicketPrice")) { participantsViewModel.TicketPrice = double.Parse(TempData["TicketPrice"].ToString()); } if (TempData.ContainsKey("Subtotal")) { participantsViewModel.Subtotal = double.Parse(TempData["Subtotal"].ToString()); } TempData.Keep("Reminder"); TempData.Keep("NumberOfTickets"); TempData.Keep("TicketPrice"); TempData.Keep("Subtotal"); return(View(participantsViewModel)); }
public ViewModelLocator() { _main = new MainViewModel(); // Use Repository pattern or similar here instead!! _participants = new ParticipantsViewModel(new Wincubate.Module14.Data.Participants()); }
public ActionResult RegistrationConfirmationPrint(int id) { ParticipantQuery participantQuery = new ParticipantQuery(); ParticipantDTO participantDTO = new ParticipantDTO(); EventQuery eventQuery = new EventQuery(); EventDTO eventDTO = new EventDTO(); UserDTO userDTO = new UserDTO(); UserQuery userQuery = new UserQuery(); ParticipantsViewModel vm = new ParticipantsViewModel(); participantDTO = participantQuery.FindParticipant(id); eventDTO = eventQuery.FindEvent(participantDTO.eventId); userDTO = userQuery.FindCurrentUser(); vm.EventName = eventDTO.Name; vm.NumberOfTicket = participantDTO.NumberOfTicket; vm.EventStartDate = eventDTO.TimeStart; ViewBag.NumberOfTickets = participantDTO.NumberOfTicket; ViewBag.Username = userDTO.Username.Replace("@", "").Replace(".com", ""); ViewBag.UserId = userDTO.Id; ViewBag.EventName = eventDTO.Name; ViewBag.EventId = eventDTO.Id; return(View(vm)); }
public ViewModelLocator() { _navigationService = new NavigationService(); _repository = new ApiRepository(); EventsViewModel = new EventsViewModel(_navigationService, _repository); ParticipantsViewModel = new ParticipantsViewModel(_navigationService, _repository); EventDetailViewModel = new EventDetailViewModel(_navigationService, _repository); NewEventViewModel = new NewEventViewModel(_navigationService, _repository); }
public IActionResult ParticipantsView() { var data = new ParticipantsViewModel { Race = _context.Race.ToList(), Registrant = _context.Registrant.ToList() }; return(View(data)); }
private void NewViewModel() { _context = new ModelContext(); _model = new ParticipantsModel(_context); _viewModel = new ParticipantsViewModel(_model, _context); SetupModel setupModel = new SetupModel(_context); setupModel.Initialize(); _viewModel.RefreshPage(); }
public ActionResult Create(int id) { ParticipantsViewModel vm = new ParticipantsViewModel(); EventQuery eventQuery = new EventQuery(); EventDTO eventDto = new EventDTO(); eventDto = eventQuery.FindEvent(id); vm.TicketsAvailable = eventQuery.GetRemainingTickets(eventDto.Id); vm.TicketPrice = eventDto.TicketPrice; return(View(vm)); }
public ActionResult allEvents(int?id) { { EventQuery Equery = new EventQuery(); ParticipantQuery Pquery = new ParticipantQuery(); allEventsViewModel UserEventsCreatedList = new allEventsViewModel(); List <EventsViewModel> events = new List <EventsViewModel>(); List <EventDTO> dtoUserEventsCreated = Equery.QueryUserEventsCreated(); foreach (EventDTO Edto in dtoUserEventsCreated) { EventsViewModel vm = new EventsViewModel(); vm.Id = Edto.Id; vm.Name = Edto.Name; vm.TimeStart = Edto.TimeStart; vm.Description = Edto.Description; vm.isRegistered = Pquery.IsRegistered(Edto.Id); if (vm.isRegistered) { vm.participantId = Pquery.FindParticipantByEventAndUser(Edto.Id); } events.Add(vm); } List <ParticipantsViewModel> Pevents = new List <ParticipantsViewModel>(); List <ParticipantDTO> ParticipantDTO = Pquery.QueryUserEventsAttending(); foreach (ParticipantDTO Pdto in ParticipantDTO) { ParticipantsViewModel vm = new ParticipantsViewModel(); vm.id = Equery.FindEvent(Pdto.eventId).Id; vm.parId = Pdto.Id; vm.EventName = Equery.FindEvent(Pdto.eventId).Name; vm.EventStartDate = Equery.FindEvent(Pdto.eventId).TimeStart; vm.Description = Equery.FindEvent(Pdto.eventId).Description; Pevents.Add(vm); } UserEventsCreatedList.EventsAttend = Pevents; UserEventsCreatedList.EventsCreated = events; return(View(UserEventsCreatedList)); } }
public async Task <IActionResult> AddParticipants(ParticipantsViewModel participants) { var participantsDB = await _repo.AddParticipants(participants); if (participantsDB == null) { return(BadRequest()); } var participantsToReturn = _mapper.Map <IList <UsersToReturnDTO> >(participantsDB); return(Ok(participantsToReturn)); }
public static void CreateParticipant(ParticipantsViewModel participant) { using (var db = new SchedulerEntities()) { var dbPerson = new Persons { Name = participant.Name, Username = participant.Username, Password = participant.Password, IsAdmin = participant.IsAdmin }; db.Persons.Add(dbPerson); db.SaveChanges(); } }
public static void DeleteParticipant(ParticipantsViewModel participant) { using (var db = new SchedulerEntities()) { var dbPerson = db.Persons.Find(participant.PersonId); if (dbPerson == null) { throw new DataException( "The table Course does not contain an entry corresponding to the provided primary key"); } db.Persons.Remove(dbPerson); db.SaveChanges(); } }
public PartialViewResult _EventsCreatedPartial() { { EventQuery Equery = new EventQuery(); ParticipantQuery Pquery = new ParticipantQuery(); allEventsViewModel UserEventsCreatedList = new allEventsViewModel(); List <EventsViewModel> events = new List <EventsViewModel>(); List <EventDTO> dtoUserEventsCreated = Equery.QueryUserEventsCreated(); foreach (EventDTO Edto in dtoUserEventsCreated) { EventsViewModel vm = new EventsViewModel(); vm.Id = Edto.Id; vm.Name = Edto.Name; vm.TimeStart = Edto.TimeStart; vm.Description = Edto.Description; events.Add(vm); } List <ParticipantsViewModel> Pevents = new List <ParticipantsViewModel>(); List <ParticipantDTO> ParticipantDTO = Pquery.QueryUserEventsAttending(); foreach (ParticipantDTO Pdto in ParticipantDTO) { ParticipantsViewModel vm = new ParticipantsViewModel(); vm.id = Equery.FindEvent(Pdto.eventId).Id; vm.EventName = Equery.FindEvent(Pdto.eventId).Name; vm.EventStartDate = Equery.FindEvent(Pdto.eventId).TimeStart; vm.Description = Equery.FindEvent(Pdto.eventId).Description; Pevents.Add(vm); } UserEventsCreatedList.EventsAttend = Pevents; UserEventsCreatedList.EventsCreated = events; return(PartialView(UserEventsCreatedList)); } }
public ActionResult RegistrationConfirmation(int id) { ParticipantQuery participantQuery = new ParticipantQuery(); ParticipantDTO participantDTO = new ParticipantDTO(); EventQuery eventQuery = new EventQuery(); EventDTO eventDTO = new EventDTO(); ParticipantsViewModel vm = new ParticipantsViewModel(); //Gary added to give payment confirmation string confirmCode = ""; if (TempData.ContainsKey("ConfirmationCode")) { confirmCode = TempData["ConfirmationCode"].ToString(); } if (confirmCode == "") { ViewBag.Confirmation = ""; } else { ViewBag.Confirmation = "The payment processed successfully. " + "Your confirmation number is " + confirmCode; } participantDTO = participantQuery.FindParticipant(id); eventDTO = eventQuery.FindEvent(participantDTO.eventId); vm.EventName = eventDTO.Name; vm.NumberOfTicket = participantDTO.NumberOfTicket; vm.EventStartDate = eventDTO.TimeStart; vm.Barcodes = participantDTO.Barcodes; vm.Address = eventDTO.Address; vm.City = eventDTO.City; vm.State = eventDTO.State; vm.Zip = eventDTO.Zip; ViewBag.EventId = eventDTO.Id; ViewBag.Location = ($"{vm.Address}, {vm.City}, {vm.State} {vm.Zip}"); return(View(vm)); }
public ActionResult Login(ParticipantsViewModel person) { if (ModelState["Username"] != null && ModelState["Password"] != null) { try { EntityFetcher.FetchLoginUser(person.Username, person.Password); ViewBag.Message = "Hello" + person?.Username; FormsAuthentication.SetAuthCookie(person.Username, false); return(RedirectToAction("Index", "Home")); } catch { ModelState.AddModelError("", "Invalid Username or Password"); } } return(View()); }
public ActionResult Application(int eventid) { var db = new EstiemPortalContext(); //var pvm = (from m in db.EVENTS_Participants // join User in db.PORTAL_ESTIEMUser on m.UserId equals User.UserId // join lg in db.ESTIEM_LocalGroup on User.LocalGroupId equals lg.Id // where m.EventID == eventid // select new ParticipantsViewModel() // { // UserId = User.UserId, // Name = User.FirstNameEnglish + " " + User.LastNameEnglish, // LocalGroup = lg.Name, // RegistrationStatus = m.RegistrationStatus, // ApplicationDate = m.RegistrationDate, // MotivationText = m.MotivationText, // EventName = m.EVENTS_Events.Name // }).FirstOrDefault(); var pvm = new ParticipantsViewModel(); var evrepo = new EventRepository(); pvm = (from m in db.EVENTS_Events where m.Id == eventid select new ParticipantsViewModel() { Vegetarian = null, EatPork = null, RequireVisa = null }).FirstOrDefault(); pvm.UserId = Int32.Parse(User.Identity.GetUserId()); pvm.Event = evrepo.GetEventById(eventid); // If registration is not open currently, or registrationmode is not open to public // redirect to the events page if (pvm.Event.ApplicationEndDate < DateTime.Now || pvm.Event.RegistrationMode != 0) { Response.Redirect("~/Events/Index"); } return(View(pvm)); }
public async Task <IActionResult> TeamDashboard(Guid?teamId) { var urlParams = new Dictionary <string, string> { { "ownerOnly", "false" } }; var teams = (await _communicationService.GetAsync <IEnumerable <TeamApiModel> >("user/teams", urlParams, FormHeaders(JsonType), "teamapi")).ToList(); if (teams.Count == 0) { return(View(new ParticipantsViewModel())); } var teamViewModels = Mapper.Map <IList <TeamViewModel> >(teams); var team = teamViewModels.FirstOrDefault(); if (teamId != null) { team = teamViewModels.FirstOrDefault(t => t.Id == teamId); } var model = new ParticipantsViewModel { SelectedTeam = team, Teams = teamViewModels }; if (User.GetUserId() == team.Owner.Id) { var participants = await _communicationService.GetAsync <IEnumerable <UserApiModel> >( $"user/teams/{team.Id}/participants", null, FormHeaders(JsonType), "teamapi"); model.Participants = _mapper.Map <IEnumerable <UserViewModel> >(participants); } return(View(model)); }
public ParticipantsViewModel Participants(Guid meetingId) { List <ParticipantViewModel> participants = new List <ParticipantViewModel>(); Meeting meeting = this.bunchOfMeetings.Get(meetingId); if (meeting is null) { throw new ArgumentException($"Meeting with id {@meetingId} does not exis"); } participants.AddRange(meeting.Leaders.Select(x => new LeaderViewModel(x.Name, x.Id))); participants.AddRange(meeting.Members.Select(x => new MemberViewModel(x.Name, x.Id))); ParticipantsViewModel viewModel = new ParticipantsViewModel(meeting.Name, meeting.Id); viewModel.Participants = participants; viewModel.Teams = meeting.Teams.Select(x => TeamViewModel.FromTeam(x)).ToList(); return(viewModel); }
public async Task <ActionResult> Application(ParticipantsViewModel pvm) { // Add the application to the database var db = new EstiemPortalContext(); var evp = new EVENTS_Participants { UserId = pvm.UserId, EventID = pvm.EventId, RegistrationDate = DateTime.Now, RegistrationStatus = 1, // RegistrationStatus 1 means waiting, which is default when applying. Comments = "", CmStatus = 0, MotivationText = pvm.MotivationText, Vegetarian = pvm.Vegetarian, NoPork = pvm.EatPork, VisaRequired = pvm.RequireVisa }; db.EVENTS_Participants.Add(evp); db.SaveChanges(); Response.Redirect("~/Events/Index"); // Post application info to Slack string urlWithAccessToken = "https://hooks.slack.com/services/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"; Slack slack = new Slack(urlWithAccessToken); var evrepo = new EventRepository(); Event ev = evrepo.GetEventById(pvm.EventId); var usrrepo = new UserRepository(); User usr = usrrepo.GetUserById(pvm.UserId); //slack.PostMessage(username: "******", // text: usr.UserName + " applied for " + ev.Name, // channel: "#estiem-mobile"); // Slack invite to channel // Invite applying user to the group of the event // Should this be applying or after registration? string parameters = "?token=" + System.Configuration.ConfigurationManager.AppSettings["SlackToken"] + "?name=" + pvm.Event.Name; var resp = await slack.PostToSlack("groups.invite", parameters); return(View()); }
public async Task <IActionResult> AddParticipant([FromForm] ParticipantsViewModel model) { if (ModelState.IsValid) { Participant participant = new Participant() { Id = model.Id, FullName = model.FullName, EMail = model.EMail, PhoneNumber = model.PhoneNumber, TourTypeId = IdTour }; _context.Add(participant); var tourType = await _context.TourTypes.FindAsync(IdTour); tourType.Amount++; await _context.SaveChangesAsync().ConfigureAwait(true); return(RedirectToAction(nameof(GetParticipants))); } return(View(model)); }
public ActionResult Payment([Bind(Include = "NumberOfTicket, Reminder")] ParticipantsViewModel participantsViewModel, int id) { ParticipantDTO participantDto = new ParticipantDTO(); ParticipantQuery participantQuery = new ParticipantQuery(); UserQuery userQuery = new UserQuery(); EPay ePay = new EPay(); if ((TempData.ContainsKey("Reminder")) && (TempData["Reminder"] != null)) { participantsViewModel.Reminder = DateTime.Parse(TempData["Reminder"].ToString()); } //participantsViewModel.NumberOfTicket = int.Parse(TempData["Reminder"].ToString()); if (TempData.ContainsKey("NumberOfTickets")) { participantsViewModel.Subtotal = int.Parse(TempData["NumberOfTickets"].ToString()); } if (TempData.ContainsKey("Subtotal")) { participantsViewModel.Subtotal = double.Parse(TempData["Subtotal"].ToString()); } double purchAmt = participantsViewModel.Subtotal * 100; string purchEmail = userQuery.FindCurrentUser().Username; if (ModelState.IsValid) { //Web Api call to Stripe Credit Card Payment Service string apiResp = ePay.MakeStripeApiRequest(purchAmt, purchEmail); string confirmCode = apiResp.Substring(0, apiResp.IndexOf(',')); string statusCode = apiResp.Substring(apiResp.IndexOf(',') + 1, apiResp.Length - (apiResp.IndexOf(',') + 1)); if (statusCode.ToUpper() == "OK") { TempData["ConfirmationCode"] = confirmCode; TempData.Keep("ConfirmationCode"); ViewBag.Confirmation = "The payment processed successfully. " + "Your confirmation number is " + confirmCode; participantDto.NumberOfTicket = participantsViewModel.NumberOfTicket; participantDto.Reminder = participantsViewModel.Reminder; participantDto.eventId = id; participantDto.Barcodes = new List <Guid>(); for (int i = 0; i < participantDto.NumberOfTicket; i++) { Guid barcode = Guid.NewGuid(); participantDto.Barcodes.Add(barcode); } int participantID = participantQuery.CreateParticipant(participantDto); EventDTO eventDTO = new EventDTO(); EventQuery eventQuery = new EventQuery(); eventDTO.TicketPrice = eventQuery.FindEvent(id).TicketPrice; ParticipantsViewModel vm = new ParticipantsViewModel(); UserDTO userDTO = new UserDTO(); userDTO = userQuery.FindCurrentUser(); eventDTO = eventQuery.FindEvent(participantDto.eventId); double totalCharge = participantDto.NumberOfTicket * eventDTO.TicketPrice; string content = System.IO.File.ReadAllText(Server.MapPath("~/views/Shared/confirmMailPurchase.cshtml")); content = content.Replace("{{Name}}", eventDTO.Name); content = content.Replace("{{Address}}", eventDTO.Address); content = content.Replace("{{City}}", eventDTO.City); content = content.Replace("{{State}}", eventDTO.State); content = content.Replace("{{Zip}}", eventDTO.Zip.ToString()); content = content.Replace("{{TimeStart}}", eventDTO.TimeStart.ToString()); content = content.Replace("{{Price}}", eventDTO.TicketPrice.ToString()); content = content.Replace("{{Ticket}}", participantDto.NumberOfTicket.ToString()); content = content.Replace("{{Total}}", totalCharge.ToString()); content = content.Replace("{{eventID}}", eventDTO.Id.ToString()); content = content.Replace("{{RegistrationConfirmation}}", confirmCode); var toEmail = userDTO.Username.ToString(); new EmailNotification().SendEmail(toEmail, content, "Confirmation : You have purchased tickets to an event"); return(RedirectToAction("RegistrationConfirmation/" + participantID, "Participants")); } else { ViewBag.Confirmation = "The payment failed. Please try again."; } } return(View(participantsViewModel)); }
public ActionResult Create([Bind(Include = "NumberOfTicket, Reminder, RemainingTickets")] ParticipantsViewModel participantsViewModel, int id) { ParticipantDTO participantDto = new ParticipantDTO(); ParticipantQuery participantQuery = new ParticipantQuery(); //Gary added to find ticket price EventDTO eventDTO = new EventDTO(); EventQuery eventQuery = new EventQuery(); eventDTO.TicketPrice = eventQuery.FindEvent(id).TicketPrice; int remainingTickets = eventQuery.GetRemainingTickets(id); if (ModelState.IsValid && remainingTickets >= participantsViewModel.NumberOfTicket) { //Gary added if statement for payment screen if ((participantsViewModel.NumberOfTicket > 0) && (eventDTO.TicketPrice > 0)) { TempData["Reminder"] = participantsViewModel.Reminder; TempData["NumberOfTickets"] = participantsViewModel.NumberOfTicket; TempData["TicketPrice"] = eventDTO.TicketPrice; TempData["Subtotal"] = Convert.ToInt32(participantsViewModel.NumberOfTicket) * Convert.ToInt32(eventDTO.TicketPrice); return(RedirectToAction("Payment/" + id, "Participants")); } else { participantDto.NumberOfTicket = participantsViewModel.NumberOfTicket; participantDto.Reminder = participantsViewModel.Reminder; participantDto.eventId = id; participantDto.Barcodes = new List <Guid>(); for (int i = 0; i < participantDto.NumberOfTicket; i++) { Guid barcode = Guid.NewGuid(); participantDto.Barcodes.Add(barcode); } int participantID = participantQuery.CreateParticipant(participantDto); //EventDTO eventDTO = new EventDTO(); ParticipantsViewModel vm = new ParticipantsViewModel(); //EventQuery eventQuery = new EventQuery(); UserDTO userDTO = new UserDTO(); UserQuery userQuery = new UserQuery(); userDTO = userQuery.FindCurrentUser(); eventDTO = eventQuery.FindEvent(participantDto.eventId); double totalCharge = participantDto.NumberOfTicket * eventDTO.TicketPrice; string content = System.IO.File.ReadAllText(Server.MapPath("~/views/Shared/ConfirmMail.cshtml")); content = content.Replace("{{Name}}", eventDTO.Name); content = content.Replace("{{Address}}", eventDTO.Address); content = content.Replace("{{City}}", eventDTO.City); content = content.Replace("{{State}}", eventDTO.State); content = content.Replace("{{Zip}}", eventDTO.Zip.ToString()); content = content.Replace("{{TimeStart}}", eventDTO.TimeStart.ToString()); content = content.Replace("{{Price}}", eventDTO.TicketPrice.ToString()); content = content.Replace("{{Ticket}}", participantDto.NumberOfTicket.ToString()); content = content.Replace("{{Total}}", totalCharge.ToString()); content = content.Replace("{{eventID}}", eventDTO.Id.ToString()); var toEmail = userDTO.Username.ToString(); new EmailNotification().SendEmail(toEmail, content, "Confirmation : You have registered for an event"); return(RedirectToAction("RegistrationConfirmation/" + participantID, "Participants")); } } if (remainingTickets < participantsViewModel.NumberOfTicket && remainingTickets > 0) { ViewBag.RemainingTicketsError1 = "Oops! The number of remaining tickets is less than what you ordered."; } else if (remainingTickets == 0) { ViewBag.RemainingTicketsError2 = "Sorry, there are no tickets left"; } participantsViewModel.TicketsAvailable = eventQuery.GetRemainingTickets(id); return(View(participantsViewModel)); }
public ParticipantsPage() { InitializeComponent(); BindingContext = viewModel = new ParticipantsViewModel(); }
public ActionResult Participants(int id, int? page) { var loggedUserId = this.User.Identity.GetUserId(); var contestOwnerId = this.Data.Contests.All() .Where(c => c.Id == id) .Select(c => c.OwnerId) .FirstOrDefault(); if (contestOwnerId == null) { HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.NotFound); message.Content = new StringContent(Messages.ContestNotFound); throw new System.Web.Http.HttpResponseException(message); } var participants = this.Data.Contests.All() .Where(c => c.Id == id) .Select(c => c.Participants) .FirstOrDefault() .ToPagedList(page ?? GlobalConstants.DefaultStartPage, GlobalConstants.DefaultPageSize); var pagedParticipants = Mapper.Map<IPagedList<User>, IPagedList<BasicUserInfoViewModel>>(participants); var participantsViewModel = new ParticipantsViewModel { ContestId = id, Participants = pagedParticipants }; if (loggedUserId == contestOwnerId || this.User.IsInRole("Administrator")) { participantsViewModel.IsContestOwner = true; } else { participantsViewModel.IsContestOwner = false; } return this.View(participantsViewModel); }
public async Task <IList <User> > AddParticipants(ParticipantsViewModel participants) { var userEvent = new UserEvent(); IList <User> participantsToReturn = new List <User>(); var eventDB = await _context.Events.FirstOrDefaultAsync(x => x.Id == participants.EventId); foreach (var participant in participants.Participants) { var userDB = _context.Users.FirstOrDefault(x => x.Email == participant.Email); if (userDB == null) { userDB = new User() { Email = participant.Email, UserName = participant.Name, IsActive = true }; var password = Password.PasswordGenerator(); byte[] passwordSalt, passwordHash; Password.CreateHashPassword(password, out passwordSalt, out passwordHash); userDB.PasswordHash = passwordHash; userDB.PasswordSalt = passwordSalt; _context.Users.Add(userDB); _context.SaveChanges(); var claims = new[] { new Claim(ClaimTypes.NameIdentifier, userDB.Id.ToString()), new Claim(ClaimTypes.Name, participant.Email), }; var token = _jwtToken.GenerateJwtToken(claims, 336); _sendEmail.CreatingNewUser(participant.Email, eventDB.EventName, token); } //Check to see where a user was already added and then removed from event bool wasAlreadyAdded = false; userEvent = _context.UserEvent.FirstOrDefault(x => x.EventId == eventDB.Id && x.UserId == userDB.Id); if (!(userEvent == null)) { userEvent.Participats = true; wasAlreadyAdded = true; } else { userEvent = new UserEvent() { UserId = userDB.Id, User = userDB, EventId = eventDB.Id, Event = eventDB, Participats = true }; } if (eventDB.CreatedBy == userDB.Id) { userEvent.RoleId = Roles.AdminRole(); } else if (participant.SemiAdmin == true) { userEvent.RoleId = Roles.SemiAdminRole(); } else { userEvent.RoleId = Roles.UserRole(); } _sendEmail.UserAddToEvent(userDB.Email, userDB.UserName); if (wasAlreadyAdded == false) { _context.UserEvent.Add(userEvent); } participantsToReturn.Add(userDB); } _context.SaveChanges(); return(participantsToReturn); }