public async Task <ActionResult <Attending> > PostAttending(Attending attending) { _context.Attendings.Add(attending); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAttending", new { id = attending.Id }, attending)); }
public async Task <IActionResult> PutAttending(long id, Attending attending) { if (id != attending.Id) { return(BadRequest()); } _context.Entry(attending).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AttendingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
/// <summary> /// Removes a player from the raid group. /// </summary> /// <param name="player">Player to remove.</param> /// <returns>List of players invited by the player.</returns> public List <SocketGuildUser> RemovePlayer(SocketGuildUser player) { if (Attending.ContainsKey(player)) { Attending.Remove(player); } else if (Ready.ContainsKey(player)) { Ready.Remove(player); } else if (Invited.ContainsKey(player)) { Invited.Remove(player); return(new List <SocketGuildUser>()); } List <SocketGuildUser> playerInvited = new List <SocketGuildUser>(); foreach (KeyValuePair <SocketGuildUser, SocketGuildUser> invite in Invited.Where(x => x.Value.Equals(player))) { playerInvited.Add(invite.Key); } foreach (SocketGuildUser invite in playerInvited) { Invited.Remove(invite); } return(playerInvited); }
/// <summary> /// Removes all players with a party size of 0. /// </summary> /// <returns>Dictionary of all users invited by removed players.</returns> public Dictionary <SocketGuildUser, List <SocketGuildUser> > ClearEmptyPlayers() { Dictionary <SocketGuildUser, List <SocketGuildUser> > empty = new Dictionary <SocketGuildUser, List <SocketGuildUser> >(); foreach (KeyValuePair <SocketGuildUser, int> user in Attending.Where(user => user.Value == 0)) { empty.Add(user.Key, new List <SocketGuildUser>()); empty[user.Key].AddRange(Invited.Where(x => x.Value.Equals(user.Key)).Select(invite => invite.Key)); } foreach (KeyValuePair <SocketGuildUser, int> user in Ready.Where(user => user.Value == 0)) { empty.Add(user.Key, new List <SocketGuildUser>()); empty[user.Key].AddRange(Invited.Where(x => x.Value.Equals(user.Key)).Select(invite => invite.Key)); } foreach (SocketGuildUser user in empty.Keys) { if (Attending.ContainsKey(user)) { Attending.Remove(user); } else if (Ready.ContainsKey(user)) { Ready.Remove(user); } } foreach (SocketGuildUser user in empty.SelectMany(group => group.Value)) { Invited.Remove(user); } return(empty); }
public IActionResult Leaving(HomeViewModel model) { System.Console.WriteLine("*************** AttendingID to be removed:" + model.Attending.UserId + "**************************"); Attending leaving = DbContext.Attendings.FirstOrDefault(a => a.EventId == model.Attending.EventId && a.UserId == model.Attending.UserId); DbContext.Remove(leaving); DbContext.SaveChanges(); return(RedirectToAction("Home")); }
public IActionResult leave(int id) { Attending toremove = _context.attending.SingleOrDefault(detail => detail.eventplanid == id); _context.attending.Remove(toremove); _context.SaveChanges(); // Other code return(RedirectToAction("activity", "activity")); }
/// <summary> /// Marks a player as ready. /// </summary> /// <param name="player">Player to mark ready.</param> public bool MarkPlayerReady(SocketGuildUser player) { if (Attending.ContainsKey(player)) { Ready.Add(player, Attending[player]); Attending.Remove(player); return(true); } return(false); }
public IActionResult UnattendWedding(int weddingID) { int? UserId = ActiveUser.UserId; int? WeddingId = weddingID; Attending unattending = dbContext.Attendees .FirstOrDefault(a => a.WeddingId == weddingID && a.UserId == UserId); dbContext.Attendees.Remove(unattending); dbContext.SaveChanges(); return(RedirectToAction("Index")); }
public void Attending_Create_Success() { var eventId = 1; var userId = "123456-12345-12345-12345-12345"; var attending = new Attending { EventId = eventId, UserId = userId }; Assert.Equal(eventId, attending.EventId); Assert.Equal(userId, attending.UserId); }
public IActionResult AttendWedding(int weddingID) { Attending attending = new Attending { UserId = ActiveUser.UserId, WeddingId = weddingID }; dbContext.Attendees.Add(attending); dbContext.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult AddGuest(int eventId) { int?activeId = HttpContext.Session.GetInt32("activeUser"); if (activeId != null) { var attending = false; List <Event> joinedEvent = _context.events.Where(e => e.EventId == eventId).Include(e => e.Attendees).ToList(); if (joinedEvent.Count == 1) { foreach (var user in joinedEvent[0].Attendees) { if (user.AttendingUserId == (int)activeId) { attending = true; break; } } if (!attending) { DateTime JoiningStartTime = joinedEvent[0].StartTime; TimeSpan addedMinutes = new TimeSpan(0, joinedEvent[0].DurationInMinutes, 0); DateTime JoiningEndTime = joinedEvent[0].StartTime.Add(addedMinutes); var user = _context.users.Include(u => u.Attending).ThenInclude(a => a.Event).Single(u => u.UserId == activeId); bool CanAttend = true; foreach (var each in user.Attending) { TimeSpan EachAddedMinutes = new TimeSpan(0, each.Event.DurationInMinutes, 0); DateTime EachEndTime = each.Event.StartTime.Add(addedMinutes); int compare1 = DateTime.Compare(JoiningStartTime, EachEndTime); //Will be neg if new event starts before other ends int compare2 = DateTime.Compare(each.Event.StartTime, JoiningEndTime); //will be neg if new event ends after other starts if (compare1 < 0 && compare2 < 0) { CanAttend = false; break; } } if (CanAttend) { Attending newAttendee = new Attending { AttendingEventId = eventId, AttendingUserId = (int)activeId }; _context.Add(newAttendee); _context.SaveChanges(); } } } return(RedirectToAction("Home")); } return(RedirectToAction("Index", "Login")); }
/// <summary> /// Attempts to split the raid group. /// </summary> /// <returns>A new raid group if the raid can be split, else null.</returns> public RaidGroup SplitGroup() { RaidGroup newGroup = new RaidGroup(PlayerLimit, InviteLimit); foreach (KeyValuePair <SocketGuildUser, int> player in Attending) { if ((newGroup.TotalPlayers() + player.Value) <= PlayerLimit / 2) { newGroup.Attending.Add(player.Key, player.Value); foreach (KeyValuePair <SocketGuildUser, SocketGuildUser> invite in Invited) { if (invite.Value.Equals(player.Key)) { newGroup.InvitePlayer(invite.Key, invite.Value); } } } } if (newGroup.TotalPlayers() < PlayerLimit / 2) { foreach (KeyValuePair <SocketGuildUser, int> player in Ready) { if (newGroup.TotalPlayers() < PlayerLimit / 2) { newGroup.Ready.Add(player.Key, player.Value); foreach (KeyValuePair <SocketGuildUser, SocketGuildUser> invite in Invited) { if (invite.Value.Equals(player.Key)) { newGroup.InvitePlayer(invite.Key, invite.Value); } } } } } foreach (SocketGuildUser player in newGroup.Attending.Keys) { Attending.Remove(player); } foreach (SocketGuildUser player in newGroup.Ready.Keys) { Ready.Remove(player); } foreach (SocketGuildUser player in newGroup.Invited.Keys) { Invited.Remove(player); } return(newGroup); }
public void SetAnglerAttendance(bool isAttending) { if (isAttending) { NotAttending.Remove(App.User); Attending.Add(App.User); } else { Attending.Remove(App.User); NotAttending.Add(App.User); } }
public IActionResult RemoveGuest(int eventId) { int?activeId = HttpContext.Session.GetInt32("activeUser"); if (activeId != null) { Attending canceledAttendee = _context.attending.SingleOrDefault(g => g.AttendingEventId == eventId && g.AttendingUserId == (int)activeId); _context.attending.Remove(canceledAttendee); _context.SaveChanges(); return(RedirectToAction("Home")); } return(RedirectToAction("Index", "Login")); }
/// <summary> /// Merges this group and another group. /// </summary> /// <param name="group">Group to merge with this group.</param> public void MergeGroup(RaidGroup group) { if (!group.Equals(this) && group.TotalPlayers() != 0 && TotalPlayers() != 0 && (group.TotalPlayers() + TotalPlayers()) <= PlayerLimit) { Attending = Attending.Union(group.Attending).ToDictionary(k => k.Key, v => v.Value); Ready = Ready.Union(group.Ready).ToDictionary(k => k.Key, v => v.Value); Invited = Invited.Union(group.Invited).ToDictionary(k => k.Key, v => v.Value); group.Attending.Clear(); group.Ready.Clear(); group.Invited.Clear(); } }
public IActionResult join(int id) { int? uid = HttpContext.Session.GetInt32("userId"); Attending nw = new Attending { userid = (int)uid, eventplanid = id, }; _context.Add(nw); _context.SaveChanges(); // Other code return(RedirectToAction("activity", "activity")); }
public RedirectToActionResult RSVP(int weddingId) { if (HttpContext.Session.GetString("Email") == null) { return(RedirectToAction("LoginReg", "User")); } int userId = dbContext.Users.FirstOrDefault(u => u.Email == HttpContext.Session.GetString("Email")).UserId; Attending attending = new Attending(); attending.UserId = userId; attending.WeddingId = weddingId; dbContext.Add(attending); dbContext.SaveChanges(); return(RedirectToAction("Dashboard")); }
public void RsvpToParty(int partyId, int personId, Attending attending) { using (SQLiteConnection dbConnection = new SQLiteConnection("Data Source=" + dbLocation + ";Version=3;")) { dbConnection.Open(); var sql = "update rsvp set attending = @Attending where partyId = @PartyId and personId = @PersonId"; using (SQLiteCommand command = new SQLiteCommand(sql, dbConnection)) { command.Parameters.Add("@Attending", System.Data.DbType.Int64).Value = (int)attending; command.Parameters.Add("@PartyId", System.Data.DbType.Int64).Value = partyId; command.Parameters.Add("@PersonId", System.Data.DbType.Int64).Value = personId; command.ExecuteNonQuery(); } } }
public IActionResult LeaveEvent(int EventId) { int? userId = HttpContext.Session.GetInt32("UserId"); User thisUser = _context.Users.SingleOrDefault(u => u.UserId == userId); if (thisUser == null) { return(RedirectToAction("Index")); } Event thisEvent = _context.Events.SingleOrDefault(e => e.EventId == EventId); Attending thisAttending = _context.Attendings.SingleOrDefault(a => a.UserId == userId && a.EventId == EventId); _context.Remove(thisAttending); _context.SaveChanges(); return(RedirectToAction("Dashboard")); }
public IActionResult UnJoin(int id) { if (InSession == null) { return(RedirectToAction("Index", "LogReg")); } Attending att = dbContext.Attendings.FirstOrDefault(a => a.UserId == (int)InSession && a.HappeningId == id); if (att != null) { dbContext.Attendings.Remove(att); dbContext.SaveChanges(); return(RedirectToAction("Happening", new { id = id })); } return(RedirectToAction("Dashboard")); }
public IActionResult Leave(int id) { int?userSessionId = HttpContext.Session.GetInt32("user_id"); if (userSessionId == null) { System.Console.WriteLine("session id is null"); return(View("Register")); } else { Attending attToRemove = dbContext.attendees.Where(a => a.ThisUserId == userSessionId) .FirstOrDefault(a => a.ThisActId == id); dbContext.attendees.Remove(attToRemove); dbContext.SaveChanges(); return(RedirectToAction("Index")); } }
public RedirectToActionResult UNRSVP(int weddingId) { if (HttpContext.Session.GetString("Email") == null) { return(RedirectToAction("LoginReg", "User")); } User currentUser = dbContext.Users.FirstOrDefault(u => u.Email == HttpContext.Session.GetString("Email")); Attending weddingAtt = dbContext.Attending.FirstOrDefault(a => a.UserId == currentUser.UserId && a.WeddingId == weddingId); if (currentUser == null | weddingAtt == null) { return(RedirectToAction("Dashboard")); } dbContext.Remove(weddingAtt); dbContext.SaveChanges(); return(RedirectToAction("Dashboard")); }
public async Task Create_Attending_DatabaseShouldSaveIt() { var userId = "NotReal"; var eventId = 42; var attendingId = -1; Attending attending = new Attending { EventId = eventId, UserId = userId }; using var appDbContext = new AppDbContext(Options, null); appDbContext.Attendees.Add(attending); await appDbContext.SaveChangesAsync(); attendingId = attending.Id; using var assertDbContext = new AppDbContext(Options, null); Attending attendFromDb = await assertDbContext.Attendees.SingleOrDefaultAsync(a => a.Id == attendingId); Assert.Equal(userId, attendFromDb.UserId); Assert.Equal(eventId, attendFromDb.EventId); }
public IActionResult JoinEvent(int EventId) { int? userId = HttpContext.Session.GetInt32("UserId"); User thisUser = _context.Users.SingleOrDefault(u => u.UserId == userId); if (thisUser == null) { return(RedirectToAction("Index")); } Event thisEvent = _context.Events.SingleOrDefault(e => e.EventId == EventId); List <Attending> commitments = _context.Attendings.Include(a => a.Event).Where(a => a.UserId == thisUser.UserId).ToList(); bool free = true; for (int i = 0; i < commitments.Count; i++) { if (thisEvent.StartingTime > commitments[i].Event.StartingTime && thisEvent.StartingTime <commitments[i].Event.EndingTime || thisEvent.EndingTime> commitments[i].Event.StartingTime && thisEvent.EndingTime < commitments[i].Event.EndingTime) { free = false; } } if (free == true) { Attending newAttending = new Attending { UserId = thisUser.UserId, User = thisUser, EventId = thisEvent.EventId, Event = thisEvent }; thisUser.AttendingEvents.Add(newAttending); thisEvent.AttendingUsers.Add(newAttending); _context.SaveChanges(); } else { TempData["error"] = "That event conflicts with another event you are already attending"; } return(RedirectToAction("Dashboard")); }
public IActionResult Join(int id) { if (InSession == null) { return(RedirectToAction("Index", "LogReg")); } if (dbContext.Attendings.Any(a => a.UserId == (int)InSession && a.HappeningId == id)) { return(RedirectToAction("Happening", new { id = id })); } Attending newA = new Attending(); newA.UserId = (int)InSession; newA.HappeningId = id; if (ModelState.IsValid) { dbContext.Attendings.Add(newA); dbContext.SaveChanges(); return(RedirectToAction("Happening", new { id = id })); } return(RedirectToAction("Dashboard")); }
/// <summary> /// Adds a player to the raid group. /// If the user is already in the raid group, their party size is updated. /// Will update attend size or remote size, not both /// </summary> /// <param name="player">Player to add.</param> /// <param name="attendSize">Number of accounts attending in person.</param> /// <param name="remoteSize">Number of accounts attending via remote.</param> public void AddPlayer(SocketGuildUser player, int attendSize, int remoteSize) { if (!Invited.ContainsKey(player)) { if (Attending.ContainsKey(player)) { if (remoteSize == Global.NO_ADD_VALUE) { Attending[player] = SetValue(attendSize, GetRemote(Attending[player])); } else if (attendSize == Global.NO_ADD_VALUE) { Attending[player] = SetValue(GetAttending(Attending[player]), remoteSize); } } else if (Ready.ContainsKey(player)) { if (remoteSize == Global.NO_ADD_VALUE) { Ready[player] = SetValue(attendSize, GetRemote(Ready[player])); } else if (attendSize == Global.NO_ADD_VALUE) { Ready[player] = SetValue(GetAttending(Ready[player]), remoteSize); } } else { int attend = (attendSize == Global.NO_ADD_VALUE) ? 0 : attendSize; int remote = (remoteSize == Global.NO_ADD_VALUE) ? 0 : remoteSize; int partySize = (remote << Global.REMOTE_SHIFT) | attend; if (partySize != 0) { Attending.Add(player, partySize); } } } }
public IActionResult Join(int id) { int?userSessionId = HttpContext.Session.GetInt32("user_id"); if (userSessionId == null) { System.Console.WriteLine("session id is null"); return(View("Register")); } else { System.Console.WriteLine(id); User curruser = dbContext.users.FirstOrDefault(u => u.UserId == userSessionId); Attending newAtt = new Attending(); newAtt.ThisActId = id; newAtt.ThisUserId = (int)userSessionId; System.Console.WriteLine("***********************"); System.Console.WriteLine((int)userSessionId); dbContext.Add(newAtt); dbContext.SaveChanges(); return(RedirectToAction("Index")); } }
public async static Task Initialize(IServiceProvider serviceProvider) { var context = serviceProvider.GetService <ApplicationDbContext>(); var userManager = serviceProvider.GetService <UserManager <ApplicationUser> >(); // Ensure Darryn (IsAdmin) var darryn = await userManager.FindByNameAsync("*****@*****.**"); if (darryn == null) { // create user darryn = new ApplicationUser { UserName = "******", Email = "*****@*****.**", ResidentName = "Darryn" }; await userManager.CreateAsync(darryn, "Darryn123!"); // add claims await userManager.AddClaimAsync(darryn, new Claim("IsAdmin", "true")); } var lynda = await userManager.FindByNameAsync("*****@*****.**"); if (lynda == null) { // create user lynda = new ApplicationUser { UserName = "******", Email = "*****@*****.**", ResidentName = "Lynda" }; await userManager.CreateAsync(lynda, "Lynda123!"); } // Ensure Mike (not IsAdmin) var dennis = await userManager.FindByNameAsync("*****@*****.**"); if (dennis == null) { // create user dennis = new ApplicationUser { UserName = "******", Email = "*****@*****.**", ResidentName = "Dennis" }; await userManager.CreateAsync(dennis, "Dennis123!"); } //Create Attending Physician var drkutter = new Attending { AttendingName = "Dr Ima Kutter MD" }; var drfelgood = new Attending { AttendingName = "Dr I Felgood MD" }; if (!context.Attendings.Any()) { context.Attendings.AddRange(drkutter, drfelgood); } //Create Clinic var surgery = new Clinic { Specialty = "Surgery", Attending = drkutter, Shift = "Morning", Insurance = "BlueCross", Doctor = lynda }; var internalmedicine = new Clinic { Specialty = "Internal Medicine", Attending = drfelgood, Shift = "Day", Insurance = "Medicare", Doctor = dennis }; if (!context.Clinics.Any()) { context.Clinics.AddRange(surgery, internalmedicine); context.SaveChanges(); } if (!context.DoctorClinics.Any()) { context.DoctorClinics.AddRange( new DoctorClinic { DoctorId = lynda.Id, ClinicId = surgery.Id }, new DoctorClinic { DoctorId = dennis.Id, ClinicId = internalmedicine.Id } ); context.SaveChanges(); } }
/// <summary> /// Gets all invited players where the inviter is attending. /// </summary> /// <returns>Immutable dictionary of invited players.</returns> public ImmutableDictionary <SocketGuildUser, SocketGuildUser> GetReadonlyInvitedAttending() { return(Invited.Where(invite => Attending.ContainsKey(invite.Value)).ToImmutableDictionary(k => k.Key, v => v.Value)); }
/// <summary> /// Gets all attending players. /// </summary> /// <returns>Immutable dictionary of attending players.</returns> public ImmutableDictionary <SocketGuildUser, int> GetReadonlyAttending() { return(Attending.ToImmutableDictionary(k => k.Key, v => v.Value)); }