public IActionResult CancelAttendance(int EventID) { AttendeeRepo c = new AttendeeRepo(_context); EventRepo e = new EventRepo(_context); var claim = HttpContext.User.Claims.ElementAt(0); string email = claim.Value; var user = c.GetOneByEmail(email); try { e.CancelAttendance(EventID, user.ID); var res = new { StatusCode = "You are no longer attending this event", }; return(new ObjectResult(res)); } catch { var res = new { error = "You were not attending this event.", }; return(new ObjectResult(res)); } }
public EventController(UserManager <ApplicationUser> userManager, ApplicationDbContext context, ILogger <EventRepo> logger) { _userManager = userManager; _eventRepo = new EventRepo(context, logger); _attendeeRepo = new AttendeeRepo(context, logger); }
public void CanAddAttendee() { using (var dbContext = SqliteInMemory.GetSqliteDbContext()) { dbContext.Database.EnsureCreated(); var attendeeRepo = new AttendeeRepo <Attendee>(dbContext); } }
public async Task <IActionResult> OnPostAsync([FromBody] RegisterAttendeeVM RegisterAttendeeVM) { AttendeeRepo a = new AttendeeRepo(_context); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { if (a.isExist(RegisterAttendeeVM.Email)) { var res = new { errorMessage = "User Already Exist", StatusCode = "Invalid Register." }; return(new ObjectResult(res)); } var user = new IdentityUser { UserName = RegisterAttendeeVM.Email, Email = RegisterAttendeeVM.Email, }; var result = await _userManager.CreateAsync(user, RegisterAttendeeVM.Password); if (result.Succeeded) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var enCode = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code)); await _userManager.ConfirmEmailAsync(user, enCode); bool isNewAttendee = a.Create(RegisterAttendeeVM.LastName, RegisterAttendeeVM.FirstName, RegisterAttendeeVM.Email); if (isNewAttendee) { var tokenString = GenerateJSONWebToken(user); var jsonOK = new { tokenString = tokenString, StatusCode = "OK", currentUser = RegisterAttendeeVM.Email }; return(new ObjectResult(jsonOK)); } } } var jsonInvalid = new { tokenString = "", StatusCode = "Invalid register." }; return(new ObjectResult(jsonInvalid)); }
public IActionResult MyEvents() { EventAttendeeRepo ea = new EventAttendeeRepo(_context); AttendeeRepo c = new AttendeeRepo(_context); var claim = HttpContext.User.Claims.ElementAt(0); string email = claim.Value; var user = c.GetOneByEmail(email); var query = ea.GetCurrentAttandingEvents(user.ID); var res = new { EventArray = query, }; return(new ObjectResult(res)); }
public async Task <IActionResult> OnPostAsync([FromBody] LoginVM loginVM) { if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(loginVM.Email.ToUpper(), loginVM.Password, loginVM.RememberMe, lockoutOnFailure : true); if (result.Succeeded) { var UserManager = _serviceProvider .GetRequiredService <UserManager <IdentityUser> >(); var user = await UserManager.FindByEmailAsync(loginVM.Email); AttendeeRepo a = new AttendeeRepo(_context); var userInfo = a.GetOneByEmail(loginVM.Email); var userRoleList = _context.UserRoles.Where(ur => ur.UserId == user.Id); if (user != null) { var tokenString = GenerateJSONWebToken(user); if (userRoleList.Any()) { if (userRoleList.First().RoleId == "Admin") { var jsonOK = new { tokenString = tokenString, StatusCode = "OK", currentUser = loginVM.Email, role = userRoleList, firstName = "Admin", lastName = "Account", }; return(new ObjectResult(jsonOK)); } } else { var jsonOK = new { tokenString = tokenString, StatusCode = "OK", currentUser = loginVM.Email, role = userRoleList, firstName = userInfo.firstName, lastName = userInfo.lastName, }; return(new ObjectResult(jsonOK)); } } } else if (result.IsLockedOut) { var jsonLocked = new { tokenString = "", StatusCode = "Locked out." }; return(new ObjectResult(jsonLocked)); } } var jsonInvalid = new { tokenString = "", StatusCode = "Invalid Login." }; return(new ObjectResult(jsonInvalid)); }
public AttendeeController(AttendeeRepo repo) { this.repo = repo; }
public void CanGetWorkshopAttendees() { using (var dbContext = SqliteInMemory.GetSqliteDbContext()) { dbContext.Database.EnsureCreated(); var attendeeRepo = new AttendeeRepo <Attendee>(dbContext); var project = new Project { ProjectName = "Arkansas Disability and Health Project", Description = "Health education for people with disabilities" }; dbContext.Projects.Add(project); var employee = new Employee { FirstName = "John", LastName = "Employee" }; dbContext.Employees.Add(employee); dbContext.SaveChanges(); var workshop1 = new Workshop { WorkshopName = "Women Be Healthy", EmployeeId = employee.Id, ProjectId = project.Id, Description = "Women's health class", TrainingDate = DateTime.Now, SessionIdentifier = "WBH-4181234500000" }; var workshop2 = new Workshop { WorkshopName = "Diabetes", EmployeeId = employee.Id, ProjectId = project.Id, Description = "Diabetes health class", TrainingDate = DateTime.Now, SessionIdentifier = "DBH-4181234500000" }; dbContext.Workshops.AddRange(workshop1, workshop2); var agency = new Agency { AgencyName = "Little Rock High School" }; dbContext.Agencies.Add(agency); dbContext.SaveChanges(); var attendee1 = new Attendee { FirstName = "Sarah", LastName = "Smith", JobTitle = "Supervisor", AgencyId = agency.Id }; var attendee2 = new Attendee { FirstName = "Andy", LastName = "Pablo", JobTitle = "Manager", AgencyId = agency.Id }; dbContext.Attendees.AddRange(attendee1, attendee2); dbContext.SaveChanges(); dbContext.AttendeeHours.Add(new AttendeeHour { AttendeeId = attendee1.Id, WorkshopId = workshop1.Id, PDHours = 1 }); dbContext.AttendeeHours.Add(new AttendeeHour { AttendeeId = attendee2.Id, WorkshopId = workshop1.Id, PDHours = 1 }); dbContext.SaveChanges(); var attendees = attendeeRepo.GetByWorkshop(workshop1.Id); Assert.AreEqual(2, attendees.Count); } }