public PlayerViewModel(PlayerInTimeSlot user, bool isSteamGame, Guid?currentUserProfileId = null) { ProfileId = user.ProfileId; PlayerName = isSteamGame ? db.ProfileSteamName.Where(x => x.ProfileId == user.ProfileId).OrderByDescending(x => x.FirstUsedDate).FirstOrDefault().SteamName : db.PlayersInTimeSlot.FirstOrDefault(x => x.ProfileId == user.ProfileId && x.TimeSlotId == user.TimeSlotId).NonSteamName; if (currentUserProfileId.HasValue) { MatchesLoggedInUser = currentUserProfileId.Value == user.ProfileId; } }
public string AttemptPlayerBooking(Guid timeSlotId, string nonSteamName) { var timeSlot = db.TimeSlot.FirstOrDefault(x => x.TimeSlotId == timeSlotId); var timeSlotBookings = db.PlayersInTimeSlot.Where(x => x.TimeSlotId == timeSlotId).ToList(); if (UserProfileId().HasValue) { var profileId = UserProfileId().Value; if (!db.Profile.FirstOrDefault(x => x.ProfileId == profileId).Banned) { if (timeSlotBookings.Count < timeSlot.NumberOfPlayers) { if (!db.PlayersInTimeSlot.Any(x => x.ProfileId == profileId && x.TimeSlot.RosterId == timeSlot.RosterId)) { if (timeSlot.Roster.Date.AddMinutes(timeSlot.Offset) >= DateTime.Now) { if (timeSlot.IsSteamGame || (!timeSlot.IsSteamGame && !string.IsNullOrWhiteSpace(nonSteamName))) { var booking = new PlayerInTimeSlot() { ProfileId = profileId, SignUpTime = DateTime.Now, TimeSlotId = timeSlotId, NonSteamName = nonSteamName, }; db.PlayersInTimeSlot.Add(booking); var overLappingReserveBooking = db.ReservesInTimeSlot.FirstOrDefault(x => x.TimeSlotId == timeSlotId && x.ProfileId == profileId); if (overLappingReserveBooking != null) { db.Entry(overLappingReserveBooking).State = EntityState.Deleted; } db.SaveChanges(); return("success"); } else { return("Please provide your Player name for this game."); } } else { return("This time slot has already started."); } } else { return("Only one Player booking per stream is allowed. You can however book as a Reserve for as many time slots as you wish. If the player slots aren't filled, or someone doesn't pitch, you may be upgraded to a Player for that time slot."); } } else { return("Sorry. All remaining timeslots have since been booked."); } } else { return("Your profile has been banned."); } } else { return("You must be signed in to make a booking."); } }