public async Task<ActionResult<string>> UserGetsSlot(int slotId, int? attendNbr) { //marks a user as getting a slot in an event if (!CheckAdmin()) { return Unauthorized(); } EventSignup eventUser = (from e in _context.EventSignup where e.Id == slotId select e).SingleOrDefault(); if (eventUser == null) { return NotFound("User signup ID not found"); } //removal functionality if (attendNbr == 0 || attendNbr == null) { attendNbr = null; } eventUser.AttendNbr = attendNbr; await _context.SaveChangesAsync(); return Ok("This user has been added to the event."); }
public async Task DeleteAsync(EventSignup signup) { using (var con = _dbConnectionFactory.Open()) { await con.DeleteAsync <EventSignup>(signup); } }
public async Task PutCheckinSendsAddEventSignupCommandAsyncWithCorrectDataWhenUsersSignedUpIsNotNullAndCheckinDateTimeIsNull() { const string userId = "userId"; var utcNow = DateTime.UtcNow; var campaignEvent = new Event(); var eventSignup = new EventSignup { User = new ApplicationUser { Id = userId } }; campaignEvent.UsersSignedUp.Add(eventSignup); var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <EventByIdQuery>())).Returns(campaignEvent); var sut = new EventApiController(mediator.Object) { DateTimeUtcNow = () => utcNow }; sut.SetFakeUser(userId); await sut.PutCheckin(It.IsAny <int>()); mediator.Verify(x => x.SendAsync(It.Is <AddEventSignupCommandAsync>(y => y.EventSignup == eventSignup))); mediator.Verify(x => x.SendAsync(It.Is <AddEventSignupCommandAsync>(y => y.EventSignup.CheckinDateTime == utcNow))); }
public async Task<ActionResult<string>> ConfirmUser(int id) { //marks a user as confirmed for an event if (!CheckAdmin()) { return Unauthorized(); } EventSignup eventUser = (from e in _context.EventSignup where e.Id == id && e.AttendNbr != null select e).SingleOrDefault(); if (eventUser == null) { return NotFound("Event timeslot ID not found"); } string returnMsg = ""; if (eventUser.ConfirmInd == false) { eventUser.ConfirmInd = true; returnMsg = "The user was confirmed for this event."; } else { eventUser.ConfirmInd = false; eventUser.AttendNbr = null; //auto-remove returnMsg = "The user was removed from this event."; } await _context.SaveChangesAsync(); return Ok(returnMsg); }
public async Task PutCheckinReturnsCorrectJsonWhenUsersSignedUpIsNotNullAndCheckinDateTimeIsNull() { const string userId = "userId"; var campaignEvent = new Event { Name = "EventName", Description = "EventDescription" }; var eventSignup = new EventSignup { User = new ApplicationUser { Id = userId } }; campaignEvent.UsersSignedUp.Add(eventSignup); var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <EventByIdQuery>())).Returns(campaignEvent); var sut = new EventApiController(mediator.Object); sut.SetFakeUser(userId); var expected = $"{{ Event = {{ Name = {campaignEvent.Name}, Description = {campaignEvent.Description} }} }}"; var result = (JsonResult)await sut.PutCheckin(It.IsAny <int>()); Assert.IsType <JsonResult>(result); Assert.Equal(expected, result.Value.ToString()); }
public async Task SaveAsync(EventSignup eventSignUp) { using (var con = _dbConnectionFactory.Open()) { con.Save(eventSignUp); } }
public ParticipantsModel(EventSignup s, int count) { Id = s.Id; UserId = s.UserId; FullName = s.User.FullName; Status = s.Status; Presence = CreateList(s.Presence, count); }
public bool TestCanEdit(Status status) { var model = new EventSignup { Status = status }; return(model.CanEdit()); }
public async Task AddUserToEvent(Event @event, IUser user) { var signUp = new EventSignup() { EventId = @event.Id, UserId = user.Id.ToString() }; await SaveAsync(signUp); }
public static SignupModel Create(EventSignup s) { return(new SignupModel { EventId = s.EventId, Title = s.Event.Title, Status = s.Status, SignedUpAt = s.SignedUpAt, Role = s.Event.SignupOptions.RoleSignup ? (DanceRole?)s.Role : null }); }
public static ClassSignupModel Create(EventSignup s) => new ClassSignupModel { Priority = s.Priority, Title = s.Event.Title, UserId = s.UserId, EventId = s.EventId, Status = s.Status, Role = s.Role, PartnerEmail = s.PartnerEmail, RoleSignup = s.Event.SignupOptions.RoleSignup, AllowPartnerSignup = s.Event.SignupOptions.AllowPartnerSignup, };
public static EventSignupModel Create(EventSignup s) => new EventSignupModel { Id = s.Id, UserId = s.UserId, FullName = s.User.FullName, Email = s.User.NormalizedEmail, Priority = s.Priority, SignedUpAt = s.SignedUpAt, Status = s.Status, Partner = PartnerSignupModel.Create(s.PartnerEmail, s.Partner), Role = s.Role, AuditLog = s.AuditLog .ToReadOnlyCollection() };
public async Task<ActionResult<string>> MoveUserSlot(int slotId, int newEventId) { //moves a user to another event - admin var returnMsg = ""; if (!CheckAdmin()) { return Unauthorized(); } EventSignup eventUser = (from e in _context.EventSignup where e.Id == slotId select e).SingleOrDefault(); if (eventUser == null) { return NotFound("User signup ID not found"); } //grab user name so it looks better for admin var slotUsername = (from u in _context.Users where u.Id == eventUser.UserId select new {u.FirstNm, u.LastNm}).SingleOrDefault(); if (slotUsername == null) { return NotFound("We could not find a user for that timeslot."); } else { returnMsg = slotUsername.FirstNm + " " + slotUsername.LastNm; } //move from old to new eventUser.TimeslotId = newEventId; //get slot number from raw sql query - to code var newSlotNbr = GetSlotNumber(newEventId); //only set if we get a value back if (newSlotNbr != null) { eventUser.AttendNbr = newSlotNbr; returnMsg += " has been moved to the new event with slot #" + newSlotNbr.ToString(); } else { returnMsg += " was moved to the new event, but no slot was available."; } await _context.SaveChangesAsync(); return Ok(returnMsg); }
public async Task<ActionResult<string>> MarkUserNoShow(int id) { //marks a user as attended an event, and updates user table with new count int eventNoShowInd; if (!CheckAdmin()) { return Unauthorized(); } EventSignup eventUser = (from e in _context.EventSignup where e.Id == id && e.AttendNbr != null select e).SingleOrDefault(); if (eventUser == null) { return NotFound("Event timeslot ID not found"); } if (eventUser.NoShowInd == false) { eventUser.NoShowInd = true; eventNoShowInd = 1; } else { eventUser.NoShowInd = false; eventNoShowInd = -1; } await _context.SaveChangesAsync(); Users existUser = (from u in _context.Users where u.Id == eventUser.UserId select u).SingleOrDefault(); if (existUser == null) { return NotFound("User ID not found"); } //increment or decrement event attend count. If <= 0, set to 0. if (existUser.NoShowCnt == null ) { existUser.NoShowCnt = 1; } else { existUser.NoShowCnt = (existUser.NoShowCnt + eventNoShowInd) <= 0 ? null : (existUser.NoShowCnt + eventNoShowInd); } await _context.SaveChangesAsync(); return Ok("The user was marked as a no-show for this event."); }
public ActionResult EventSignup(string firstName, string lastName, string email, int eventId) { HockeySignupsDb db = new HockeySignupsDb(_connectionString); Event e = db.GetEventById(eventId); EventStatus status = db.GetEventStatus(e); if (status == EventStatus.InThePast) { #region TempData TempData["Error"] = "You cannot sign up to a game in the past. Jerk."; #endregion return(RedirectToAction("Index")); } if (status == EventStatus.Full) { #region TempData TempData["Error"] = "Nice try sucker...."; #endregion return(RedirectToAction("Index")); } EventSignup s = new EventSignup { Email = email, FirstName = firstName, LastName = lastName, EventId = eventId }; HttpCookie firstNameCookie = new HttpCookie("firstName", s.FirstName); HttpCookie lastNameCookie = new HttpCookie("lastName", s.LastName); HttpCookie emailCookie = new HttpCookie("email", s.Email); Response.Cookies.Add(firstNameCookie); Response.Cookies.Add(lastNameCookie); Response.Cookies.Add(emailCookie); db.AddEventSignup(s); #region TempData TempData["Message"] = "You have succesfully signed up for this weeks game, looking forward to checking you into the boards!"; #endregion return(RedirectToAction("Index")); }
public async Task<ContentResult> UpdateSignupNote(EventSignupNote signup) { if (!CheckAdmin()) { return Content("You are not allowed to access this function."); } if (signup.Id <= 0) { return Content("A valid timeslot does not exist in this request."); } EventSignup eventSignup = await (from e in _context.EventSignup where e.Id == signup.Id select e).SingleOrDefaultAsync(); eventSignup.SignupTxt = signup.SignupTxt; await _context.SaveChangesAsync(); return Content("The signup note was modified."); }
public async Task <ActionResult <string> > UserDeleteSignup(int timeslotId, string facebookId) { EventSignup eventUser = (from e in _context.EventSignup join u in _context.Users on e.UserId equals u.Id where e.TimeslotId == timeslotId && e.AttendNbr == null && u.FbId == facebookId && !e.DeleteInd select e).SingleOrDefault(); if (eventUser == null) { return(NotFound("I'm sorry, we did not find this signup in the system.")); } eventUser.DeleteInd = true; await _context.SaveChangesAsync(); return(Ok("You have been removed from the selected event. You may now sign up for another open event.")); }
public static EventSignup AddEventSignup(this MemberUser user, Guid id, DanceRole role, string partnerEmail, bool autoAccept, int priority = 1) { var status = autoAccept ? Status.Approved : Status.Pending; var signup = new EventSignup { EventId = id, Priority = priority, Role = role, PartnerEmail = partnerEmail?.Trim().Normalize().ToUpperInvariant(), Status = status, SignedUpAt = TimeProvider.UtcNow, AuditLog = { { $"Signed up as {role}{(partnerEmail is string ? $" with partner {partnerEmail}" : "")}, status is {status}", user } } }; user.EventSignups.Add(signup); return(signup); }
public async Task <ObjectResult> SignupEvent(EventSignupCall signup) { int ourUserId; //gets lookup of users for typeahead if (!CheckAdmin()) { return(Unauthorized("You are not permitted to use this function.")); } //run query to verify user can sign up - check the ban flag var existUser = _context.Users.Where(a => a.FbId == signup.FbId).FirstOrDefault(); if (existUser == null) { return(BadRequest("I am sorry, you are not allowed to sign up for this event.")); } else { ourUserId = existUser.Id; } //we passed all the checks, now lets do this thing. We don't assign an attendee number. var newEventSignup = new EventSignup() { TimeslotId = signup.EventId, UserId = ourUserId, SignupTms = DateTime.Now, FlexibleInd = signup.FlexibleInd }; await _context.EventSignup.AddAsync(newEventSignup); await _context.SaveChangesAsync(); //update user table since these are now in the form from earlier. return(Ok("The user has been added to the event.")); }
public ActionResult EventSignup(string firstName, string lastName, string email, int eventId) { var db = new HockeySignupsDb(Properties.Settings.Default.ConStr); var e = db.GetEventById(eventId); var status = db.GetEventStatus(e); if (status == EventStatus.InThePast) { TempData["Error"] = "You cannot sign up to a game in the past!!"; return(RedirectToAction("Index")); } if (status == EventStatus.Full) { TempData["Error"] = "Nice try!"; return(RedirectToAction("Index")); } EventSignup s = new EventSignup { Email = email, FirstName = firstName, LastName = lastName, EventId = eventId }; HttpCookie firstNameCookie = new HttpCookie("firstName", s.FirstName); HttpCookie lastNameCookie = new HttpCookie("lastName", s.LastName); HttpCookie emailCookie = new HttpCookie("email", s.Email); Response.Cookies.Add(firstNameCookie); Response.Cookies.Add(lastNameCookie); Response.Cookies.Add(emailCookie); db.AddEventSignup(s); TempData["Message"] = "You have successfully signed up for this weeks game, looking forward to checking you into the boards!"; return(RedirectToAction("Index")); }
public async Task <ActionResult <string> > UserMoveSignup(int slotId, int newEventId, string facebookId) { //moves a user to another event - user EventSignup eventUser = (from e in _context.EventSignup join u in _context.Users on e.UserId equals u.Id where e.Id == slotId && u.EventCnt < 2 && u.FbId == facebookId select e).SingleOrDefault(); if (eventUser == null) { return(NotFound("I'm sorry, you are not permitted to move events.")); } //move from old to new eventUser.TimeslotId = newEventId; await _context.SaveChangesAsync(); return(Ok("You have been moved to the selected event.")); }
public SignedUpPartnerSignupModel(EventSignup signup) : base(signup.User) { Role = signup.Role; Status = signup.Status; PartnerEmail = signup.PartnerEmail?.Trim(); }
public static bool CanEdit(this EventSignup e) => e.Status == Status.Pending || e.Status == Status.Recommended;
public static ResponseModel Create(EventSignup es, QuestionAnswer a) =>
public static EventSignupModel Create(EventSignup s) => new()
private async Task SendEmail(EventSaveModel input, EventStatusModel model, User currentUser, bool statusChanged, EventSignup eventSignup) { try { await _emailService.SendCustomEmail( eventSignup.User, input.Subject, input.Message, model, input.ReplyToMe?currentUser : null); if (statusChanged) { eventSignup.AuditLog.Add($"Moved to {input.Status} and sent email\n\n---\n\n> {input.Subject}\n\n{input.Message}", currentUser); } else { eventSignup.AuditLog.Add($"Sent email\n\n---\n\n> {input.Subject}\n\n{input.Message}", currentUser); } } catch (Exception e) { // Mail sending might fail, but that should't stop us eventSignup.AuditLog.Add($"Tried to send email, but failed with message {e.Message}", currentUser); _logger.LogError(e, "Failed to send email"); } }
public async Task<ContentResult> SignupEvent(EventSignupCall signup) { int ourUserId; int? newEventId; bool autoClearInd = false; //Get auto-clear flag var autoclearSetting = _appSettings.Value; int autoClearLimit = autoclearSetting.AutoClear ?? 0; // Keyboard kid rule if (signup.Realname.ToLower().IndexOf("lewellen") >= 0) { _logger.LogInformation("Keyboard Kid rule activated"); return Content("Your name is not allowed to sign up for an event."); } // Grant rule if ((signup.Realname.ToLower() == "matthew kisha") && signup.FirstNm != "Matthew" && signup.LastNm != "Kisha") { return Content("I'm sorry Dave. Only Matthew Kisha can sign up as Matthew Kisha. This is highly irregular."); } // run query to verify user can sign up - check the ban flag var existUser = _context.Users.Where( a => a.FbId == signup.FbId && a.BanFlag == false).FirstOrDefault(); if (existUser == null) { _logger.LogInformation("Banned user signup attempted - " + signup.FbId); return Content("I am sorry, you are not allowed to sign up for this event."); } else { ourUserId = existUser.Id; if (existUser.EventCnt < autoClearLimit && existUser.EventCnt > 0) { autoClearInd = true; } } // Don't allow signup if the user has signed up for this event already var existUserEvent = await _context.EventSignup.AnyAsync(u => u.DeleteInd == false && u.TimeslotId == signup.EventId && u.UserId == ourUserId); if (existUserEvent) { return Content("It looks like you have already signed up for this event."); } //check for event count - new per Raymond. Will run as final verification. int currCount = await _context.EventSignup.Where(m => m.DeleteInd == false).CountAsync(m => m.TimeslotId == signup.EventId); var eventStats = await _context.Timeslot.Where(a => a.Id == signup.EventId) .FirstOrDefaultAsync(); // If this event is private, check the GUID to see if it matches. If not, bounce away. var eventGuid = signup.EventKey != null ? new Guid(signup.EventKey) : new Guid(); if (eventStats.EventKey != eventGuid && signup.EventKey != null && eventStats.PrivateEventInd) { return Content("I am unable to sign you up for this event."); } if (eventStats.EventClosed == true) { return Content("I am sorry, this event is full."); } if (currCount >= eventStats.SignupCnt) { //auto-close functionality eventStats.EventClosed = true; await _context.SaveChangesAsync(); return Content("I'm sorry, but this event has filled up. Please select another event."); } //auto-clear functionality if (autoClearInd) { newEventId = GetSlotNumber(signup.EventId); } else { newEventId = null; } //we passed all the checks, now lets do this thing. var newEventSignup = new EventSignup(){ TimeslotId = signup.EventId, UserId = ourUserId, SignupTms = DateTime.Now, FlexibleInd = signup.FlexibleInd, AttendNbr = newEventId }; _context.EventSignup.Add(newEventSignup); await _context.SaveChangesAsync(); //update user table since these are now in the form from earlier. existUser.CityNm = signup.CityNm; existUser.StateCd = signup.StateCd; existUser.CountryCd = signup.CountryCd; existUser.RealNm = signup.Realname; await _context.SaveChangesAsync(); return Content("We have received your signup. Since we need to verify that you can attend the sale, please check your Facebook messages and message requests for confirmation from the volunteers."); }