private BookingRecord CreateBookingRecord( DateTime date, Guid organizationId, Guid tournamentId, Product product, Decimal quantity, Decimal value, Boolean credit, User user) { BookingRecord record = CreateBookingRecord( date, organizationId, tournamentId, value, credit, null, user ); record.Product = product; record.ProductId = product.Id; record.ProductName = product.Name; record.Price = product.Price; record.VatRate = product.VatRate; record.Quantity = quantity; return record; }
public async Task DeleteOrganizationAsync(Guid organizationId, User user) { // Check permissions if (!userManager.HasOrganizationRole(user.Id, organizationId, OrganizationRole.Delegate)) { throw new UnauthorizedAccessException(UserNotAuthorizedMessage); } // Set deleted flags var organization = GetOrganization(organizationId); foreach (var linkedOrganization in organization.LinkedOrganizations) { linkedOrganization.LinkedOrganization = null; linkedOrganization.Deleted = true; linkedOrganization.UpdateTrackingData(user); await unitOfWork.SaveAsync(); } organization.LinkedOrganization = null; organization.Deleted = true; organization.UpdateTrackingData(user); await unitOfWork.SaveAsync(); }
public TournamentOrganizationRegistration AddRegistration(Guid tournamentId, Guid organizationId, Guid billedOrganizationId, int teamsWanted, int adjudicatorsWanted, String notes, User user) { if (tournamentId != Guid.Empty && organizationId != Guid.Empty && billedOrganizationId != Guid.Empty && (teamsWanted > 0 || adjudicatorsWanted > 0)) { TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration { TournamentId = tournamentId, OrganizationId = organizationId, BilledOrganizationId = billedOrganizationId, TeamsWanted = teamsWanted, AdjudicatorsWanted = adjudicatorsWanted, TeamsGranted = 0, TeamsPaid = 0, AdjudicatorsGranted = 0, AdjudicatorsPaid = 0, LockAutoAssign = false, OrganizationStatusDraft = true, Notes = notes }; registration.UpdateTrackingData(user); SetBookingCode(registration); unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration); unitOfWork.Save(); return registration; } return null; }
public DebReg.Models.BookingRecord AddBooking( DateTime date, Guid organizationId, Guid tournamentId, Product product, Decimal quantity, Boolean credit, DateTime? paymentsDueDate, User user) { Decimal value = quantity * product.Price; BookingRecord record = CreateBookingRecord( date, organizationId, tournamentId, product, quantity, value, credit, user); record.PaymentsDueDate = paymentsDueDate; unitOfWork.GetRepository<BookingRecord>().Insert(record); unitOfWork.Save(); return record; }
public virtual async Task SetUserTournamentPropertyValueAsync(User user, UserProperty property, Tournament tournament, String value) { var repository = unitOfWork.GetRepository<UserTournamentPropertyValue>(); if (user != null && property != null && tournament != null) { var userTournamentPropertyValue = repository.GetById(user.Id, property.Id, tournament.Id); if (userTournamentPropertyValue == null) { userTournamentPropertyValue = new UserTournamentPropertyValue { User = user, Tournament = tournament, UserProperty = property, Value = value }; repository.Insert(userTournamentPropertyValue); } else { userTournamentPropertyValue.Value = value; repository.Update(userTournamentPropertyValue); } await unitOfWork.SaveAsync(); } }
public void UserRegisteredForTournament(User user, TournamentOrganizationRegistration registration, Boolean adjudicator, string personalDataLink) { var role = adjudicator ? Resources.Strings.Adjudicator : Resources.Strings.Speaker; var message = CreateEMailMessage(new List<String> { user.NewEMail }); message.Subject = String.Format ( Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentSubject, role ); message.Body = String.Format ( Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentBody, user.FirstName, registration.Organization.Name, role, registration.Tournament.Name, personalDataLink ); message.HTMLBody = String.Format ( Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentBodyHTML, user.FirstName, registration.Organization.Name, role, registration.Tournament.Name, personalDataLink ); mailService.SendCompleted += mailService_SendCompleted; mailService.Send(message); }
public void AddBooking_WithNote_ShouldCreateBooking() { // Arrange Random rand = new Random(); DateTime date = DateTime.Now; Guid organizationId = Guid.NewGuid(); Guid tournamentId = Guid.NewGuid(); Decimal value = rand.Next(10, 1000); Boolean credit = false; String note = "Testnote"; User user = new User { Id = Guid.NewGuid().ToString() }; // Act var record = bookingManager.AddBooking( date, organizationId, tournamentId, value, credit, note, user ); var id = record.Id; // Assert record = null; record = bookingManager.GetBookings(organizationId, tournamentId) .FirstOrDefault(r => r.Id == id); Assert.AreEqual(note, record.Note); }
private IEnumerable<SlotAssignmentViewModel> GetSlotAssignmentViewModels(Guid tournamentId, User user) { // Build wait list var waitList = tournamentRegistrationsManager.GetRegistrationsSortedByRank(tournamentId, user); // Get latest version var latestVersion = slotAssignmentManager.GetLatestVersion(tournamentId); if (latestVersion == null) { latestVersion = slotAssignmentManager.CreateVersion(tournamentId); } // Get assignments var assignments = slotManager.GetSlotAssignments(tournamentId, latestVersion, user); // Build view model List<SlotAssignmentViewModel> assignmentsViewModel = new List<SlotAssignmentViewModel>(); foreach (var registration in waitList) { var assignment = assignments.FirstOrDefault( a => a.OrganizationId == registration.OrganizationId); if (assignment == null) { assignment = new SlotAssignment(); } assignmentsViewModel.Add(new SlotAssignmentViewModel { Assignment = assignment, Registration = registration }); } return assignmentsViewModel; }
public IEnumerable<TournamentOrganizationRegistration> GetRegistrationsSortedByRank(Guid tournamentId, User user) { // Get registrations, where either the status is approved and not draft, // or slots have been assigned or paid var registrations = unitOfWork.GetRepository<TournamentOrganizationRegistration>().Get( r => (r.TournamentId == tournamentId && ( ( r.OrganizationStatus == OrganizationStatus.Approved && !r.OrganizationStatusDraft ) || r.TeamsGranted > 0 || r.TeamsPaid > 0 || r.AdjudicatorsGranted > 0 || r.AdjudicatorsPaid > 0 ) ) ); // Create seed for random Random rand = new Random(); // Build a random ranking, if needed Boolean duplicateRandomRanks; do { duplicateRandomRanks = false; // Get groups of equal random rank var groupedByRandomRank = from r in registrations group r by r.RandomRank into grp select grp; foreach (var registrationsGroup in groupedByRandomRank) { // if there is more than one registration in a group, randomize group if (registrationsGroup.Count() > 1) { foreach (var registration in registrationsGroup) { SetRandomRank(registration.TournamentId, registration.OrganizationId, rand.Next(), user); } duplicateRandomRanks = true; } } } while (duplicateRandomRanks); var result = registrations.OrderByDescending(r => r.Rank).ThenBy(r => r.RandomRank); return result; }
public void UserRegistered(User user, String resetUrl) { var message = CreateEMailMessage(new List<String> { user.Email }); message.Subject = Resources.DebRegCommunication.SendMail.Strings.UserRegisteredSubject; message.Body = String.Format(Resources.DebRegCommunication.SendMail.Strings.UserRegisteredBody, user.FirstName, resetUrl); message.HTMLBody = String.Format(Resources.DebRegCommunication.SendMail.Strings.UserRegisteredBodyHTML, user.FirstName, resetUrl); mailService.SendCompleted += mailService_SendCompleted; mailService.Send(message); }
public async Task LoginAsync(User user) { ClaimsIdentity ident = await userManager.CreateIdentityAsync(user, CookieAuthenticationDefaults.AuthenticationType); // Sign in authManager.SignOut(); authManager.SignIn(new AuthenticationProperties { IsPersistent = false }, ident); }
public UserViewModel(User user) : this() { User = user; if (user != null) { foreach (var value in user.PropertyValues) { UserProperties.Add(new UserPropertyValueViewModel(value)); } } }
public UserViewModel(User user, Guid tournamentId) : this(user) { if (User != null) { var tournamentPropertyValues = user.TournamentPropertyValues.Where(v => v.TournamentId == tournamentId); foreach (var value in tournamentPropertyValues) { UserProperties.Add(new UserPropertyValueViewModel(value.ToUserPropertyValue())); } } }
public void ConfirmSlots(Guid tournamentId, Guid organizationId, int paidTeams, int paidAdjudicators, String paymentPageUrl, User user) { var registration = registrationsManager.SetTeamsAndAdjudicatorsPaid(tournamentId, organizationId, paidTeams, paidAdjudicators, user); if (registration != null && registration.Tournament != null && registration.Tournament.HostingOrganization != null && registration.Tournament.HostingOrganization.SMTPHostConfiguration != null) { if (lastTournamentId != tournamentId) { while (sentMessages.Count > 0) { // wait for messages to be sent } ConfigureMailService(registration.Tournament.HostingOrganization.SMTPHostConfiguration); } paymentPageUrl = String.Format(paymentPageUrl, registration.TournamentId, registration.OrganizationId); SendAssignmentNotification(registration, paymentPageUrl, user); } }
public void UpdateTrackingData(User user) { if (Created == null) { Created = DateTime.UtcNow; } if (CreatedBy == null) { CreatedBy = user; } if (String.IsNullOrWhiteSpace(CreatedById)) { CreatedById = CreatedBy.Id; } Modified = DateTime.UtcNow; ModifiedBy = user; if (user != null) { ModifiedById = user.Id; } }
public void ConfirmEMailAddress(User user, string confirmUrl) { var message = CreateEMailMessage(new List<String> { user.NewEMail }); message.Subject = Resources.DebRegCommunication.SendMail.Strings.ConfirmEMailSubject; message.Body = String.Format ( Resources.DebRegCommunication.SendMail.Strings.ConfirmEMailBody, user.FirstName, user.NewEMail, confirmUrl ); message.HTMLBody = String.Format ( Resources.DebRegCommunication.SendMail.Strings.ConfirmEMailBodyHTML, user.FirstName, user.NewEMail, confirmUrl ); mailService.SendCompleted += mailService_SendCompleted; mailService.Send(message); }
public void Register_WithOrganizationIdAndAuthorizedUser_ShouldReturnViewWithOrganization() { // Arrange User user = new User { Id = Guid.NewGuid().ToString(), UserName = "******" }; var task = userManager.CreateAsync(user); if (!task.IsCompleted) { task.Wait(); } Guid organizationId = Guid.NewGuid(); Organization organization = new Organization { Id = organizationId }; unitOfWork.GetRepository<Organization>().Insert(organization); unitOfWork.Save(); unitOfWork.GetRepository<OrganizationUser>().Insert(new OrganizationUser { OrganizationId = organization.Id, UserId = user.Id, Role = OrganizationRole.Delegate }); unitOfWork.Save(); httpMocks.UserId = user.Id; httpMocks.UserName = user.UserName; // Act ViewResult result = (ViewResult)organizationController.Register(organization.Id); // Assert organization = (Organization)result.Model; Assert.AreEqual(organizationId, organization.Id); }
public void AddBooking_ShouldCreateBooking() { // Arrange Random rand = new Random(); DateTime date = DateTime.Now; Guid organizationId = Guid.NewGuid(); Guid tournamentId = Guid.NewGuid(); Decimal value = rand.Next(10, 1000); Boolean credit = false; User user = new User { Id = Guid.NewGuid().ToString() }; // Act var record = bookingManager.AddBooking( date, organizationId, tournamentId, value, credit, user ); var id = record.Id; // Assert record = null; record = bookingManager.GetBookings(organizationId, tournamentId) .FirstOrDefault(r => r.Id == id); Assert.AreEqual(date, record.Date); Assert.AreEqual(organizationId, record.OrganizationId); Assert.AreEqual(tournamentId, record.TournamentId); Assert.AreEqual(value, record.Value); Assert.AreEqual(credit, record.Credit); Assert.AreEqual(user.Id, record.CreatedById); Assert.AreEqual(user.Id, record.ModifiedById); Assert.IsNotNull(record.Created); Assert.IsNotNull(record.Modified); }
private BookingRecord CreateBookingRecord( DateTime date, Guid organizationId, Guid tournamentId, Decimal value, Boolean credit, String note, User user) { BookingRecord record = new BookingRecord { Id = Guid.NewGuid(), Date = date, OrganizationId = organizationId, TournamentId = tournamentId, Value = value, Credit = credit, Note = note }; record.UpdateTrackingData(user); return record; }
public void PublishAssignments_WithInvalidTournamentId_ShouldDoNothing() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); // Create new draft version CreateDraftVersion(user); // Act var oldBookingsCount = bookingManager.GetBookings(tournament.Id).Count; slotManager.PublishAssignments(Guid.Empty, paymentsDueDate, null, user); // Assert var latestVersion = slotAssignmentManager.GetLatestVersion(tournament.Id); Assert.AreEqual(VersionStatus.Draft, latestVersion.Status); var newBookingsCount = bookingManager.GetBookings(tournament.Id).Count; Assert.AreEqual(oldBookingsCount, newBookingsCount); }
public void PublishAssignments_WithNewDraftVersion_ShouldInvalidateOldPublishedVersion() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); { // Create first published version CreateDraftVersion(user); slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); } var latestVersionOld = slotAssignmentManager.GetLatestVersion(tournament.Id); Dictionary<Guid, Decimal> expectedBalances = new Dictionary<Guid, Decimal>(); slotAssignmentManager.CreateVersion(tournament.Id); foreach (var assignment in slotAssignmentManager.GetSlotAssignments(tournament.Id, latestVersionOld.Id)) { var teamsGranted = assignment.TeamsGranted; if (assignment.TeamsGranted > 2) { teamsGranted--; } if (assignment.TeamsGranted < 2) { teamsGranted++; } var adjudicatorsGranted = assignment.AdjucatorsGranted; if (assignment.AdjucatorsGranted > 2) { adjudicatorsGranted--; } if (assignment.AdjucatorsGranted < 2) { adjudicatorsGranted++; } slotAssignmentManager.AssignSlots(assignment.TournamentId, assignment.OrganizationId, teamsGranted, adjudicatorsGranted, user); var oldBalance = bookingManager.GetBalance(assignment.OrganizationId, assignment.TournamentId); var expectedBalance = oldBalance + (assignment.TeamsGranted - teamsGranted) * tournament.TeamProduct.Price + (assignment.AdjucatorsGranted - adjudicatorsGranted) * tournament.AdjudicatorProduct.Price; expectedBalances.Add(assignment.OrganizationId, expectedBalance); } // Act slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); // Assert Assert.AreEqual(VersionStatus.Outdated, latestVersionOld.Status); var latestVersionNew = slotAssignmentManager.GetLatestVersion(tournament.Id); Assert.AreEqual(VersionStatus.Public, latestVersionNew.Status); foreach (var assignment in slotAssignmentManager.GetSlotAssignments(tournament.Id, latestVersionNew.Id)) { Decimal expectedBalance; expectedBalances.TryGetValue(assignment.OrganizationId, out expectedBalance); var actualBalance = bookingManager.GetBalance(assignment.OrganizationId, assignment.TournamentId); Assert.AreEqual(expectedBalance, actualBalance); } }
public void PublishAssignments_WithSMTPHostConfiguration() { // Arrange tournament.HostingOrganization.SMTPHostConfiguration = new SMTPHostConfiguration(); tournament.HostingOrganization.SMTPHostConfiguration.Password = "******"; User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); CreateDraftVersion(user); // Act slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); // Assert }
public void PublishAssignments_WithAlreadyPublishedVersion_ShouldDoNothing() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); { // Create first published version CreateDraftVersion(user); slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); } var latestVersionOld = slotAssignmentManager.GetLatestVersion(tournament.Id); var bookingsCountOld = bookingManager.GetBookings(tournament.Id).Count; // Act slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); // Assert var latestVersionNew = slotAssignmentManager.GetLatestVersion(tournament.Id); Assert.AreEqual(latestVersionOld.Id, latestVersionNew.Id); Assert.AreEqual(bookingsCountOld, bookingManager.GetBookings(tournament.Id).Count); }
public void PublishAssignments_WithNoVersion_ShouldDoNothing() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); var bookingsCountOld = bookingManager.GetBookings(tournament.Id).Count; // Act slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); // Assert var latestVersion = slotAssignmentManager.GetLatestVersion(tournament.Id); Assert.IsNull(latestVersion); Assert.AreEqual(bookingsCountOld, bookingManager.GetBookings(tournament.Id).Count); }
public void PublishAssignments_WithMissingProductLinks_ShouldPublishAssignedSlotsWithNoBookings() { // Arrange #region ARRANGE // Basic parameters and objects User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); // Create new draft version CreateDraftVersion(user); // Remove Product Links var teamProduct = tournament.TeamProduct; var adjudicatorProduct = tournament.AdjudicatorProduct; tournament.TeamProduct = null; tournament.AdjudicatorProduct = null; #endregion // Act var oldBookingsCount = bookingManager.GetBookings(tournament.Id).Count; slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); // Restore product links tournament.TeamProduct = teamProduct; tournament.AdjudicatorProduct = adjudicatorProduct; // Assert var latestVersion = slotAssignmentManager.GetLatestVersion(tournament.Id); Assert.AreEqual(latestVersion.Status, VersionStatus.Public); foreach (var registration in tournamentRegistrationsManager.GetApprovedRegistrations(tournament.Id)) { var assignment = slotAssignmentManager.GetSlotAssignment(tournament.Id, registration.OrganizationId); Assert.AreEqual(registration.AdjudicatorsGranted, assignment.AdjucatorsGranted); Assert.AreEqual(registration.TeamsGranted, assignment.TeamsGranted); } var newbookingsCount = bookingManager.GetBookings(tournament.Id).Count; Assert.AreEqual(oldBookingsCount, newbookingsCount); #region ASSERT #endregion }
public void PublishAssignments_WithEmptySMTPConfiguration() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); // Create new draft version CreateDraftVersion(user); // Act var oldBookingsCount = bookingManager.GetBookings(tournament.Id).Count; slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); // Assert }
public void PublishAssignments_WithFewerSlotsThanPaid_ShouldDecreaseSlotsPaid() { // Arrange User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); { // Create first published version CreateDraftVersion(user); slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); } var latestVersionOld = slotAssignmentManager.GetLatestVersion(tournament.Id); Dictionary<Guid, Decimal> expectedBalances = new Dictionary<Guid, Decimal>(); slotAssignmentManager.CreateVersion(tournament.Id); foreach (var assignment in slotAssignmentManager.GetSlotAssignments(tournament.Id, latestVersionOld.Id)) { var registration = tournamentRegistrationsManager.GetRegistration(tournament.Id, assignment.OrganizationId); registration.TeamsPaid = registration.TeamsGranted; registration.AdjudicatorsPaid = registration.AdjudicatorsWanted; var teamsGranted = assignment.TeamsGranted; if (assignment.TeamsGranted > 1) { teamsGranted--; } if (assignment.TeamsGranted < 2) { teamsGranted++; } var adjudicatorsGranted = assignment.AdjucatorsGranted; if (assignment.AdjucatorsGranted > 1) { adjudicatorsGranted--; } if (assignment.AdjucatorsGranted < 2) { adjudicatorsGranted++; } slotAssignmentManager.AssignSlots(assignment.TournamentId, assignment.OrganizationId, teamsGranted, adjudicatorsGranted, user); var oldBalance = bookingManager.GetBalance(assignment.OrganizationId, assignment.TournamentId); var expectedBalance = oldBalance + (assignment.TeamsGranted - teamsGranted) * tournament.TeamProduct.Price + (assignment.AdjucatorsGranted - adjudicatorsGranted) * tournament.AdjudicatorProduct.Price; expectedBalances.Add(assignment.OrganizationId, expectedBalance); } // Act slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); // Assert var latestVersionNew = slotAssignmentManager.GetLatestVersion(tournament.Id); foreach (var registration in tournamentRegistrationsManager.GetApprovedRegistrations(tournament.Id)) { Assert.IsTrue(registration.TeamsPaid <= registration.TeamsGranted); } }
private Dictionary<Guid, Decimal> CreateDraftVersion(User user) { Dictionary<Guid, Decimal> expectedBalances = new Dictionary<Guid, Decimal>(); DebReg.Models.Version version = slotAssignmentManager.CreateVersion(tournament.Id); foreach (var registration in tournamentRegistrationsManager.GetApprovedRegistrations(tournament.Id)) { int teamsGranted = registration.TeamsWanted; int adjudicatorsGranted = registration.AdjudicatorsWanted; slotAssignmentManager.AssignSlots( registration.TournamentId, registration.OrganizationId, teamsGranted, adjudicatorsGranted, user ); var oldBalance = bookingManager.GetBalance(registration.OrganizationId, registration.TournamentId); var expectedBalance = (registration.TeamsGranted - teamsGranted) * tournament.TeamProduct.Price + (registration.AdjudicatorsGranted - adjudicatorsGranted) * tournament.AdjudicatorProduct.Price; expectedBalances.Add(registration.OrganizationId, expectedBalance); } return expectedBalances; }
private User CreateUserWithOrganizationRole(Organization organization, OrganizationRole role) { User user = new User { Id = Guid.NewGuid().ToString() }; user.OrganizationAssociations.Add(new OrganizationUser { User = user, UserId = user.Id, Organization = organization, OrganizationId = organization.Id, Role = role }); var task = userManager.CreateAsync(user); while (!task.IsCompleted) { } return user; }
public void PublishAssignments_FirstVersion_ShouldPublishAssignedSlots() { // Arrange #region ARRANGE // Basic parameters and objects User user = new User { Id = Guid.NewGuid().ToString() }; DateTime paymentsDueDate = DateTime.Today.AddDays(14); Dictionary<Guid, Decimal> expectedBalances; // Create new draft version expectedBalances = CreateDraftVersion(user); #endregion // Act slotManager.PublishAssignments(tournament.Id, paymentsDueDate, null, user); // Assert var latestVersion = slotAssignmentManager.GetLatestVersion(tournament.Id); Assert.AreEqual(latestVersion.Status, VersionStatus.Public); foreach (var registration in tournamentRegistrationsManager.GetApprovedRegistrations(tournament.Id)) { var assignment = slotAssignmentManager.GetSlotAssignment(tournament.Id, registration.OrganizationId); Assert.AreEqual(registration.AdjudicatorsGranted, assignment.AdjucatorsGranted); Assert.AreEqual(registration.TeamsGranted, assignment.TeamsGranted); Decimal expectedBalance; expectedBalances.TryGetValue(registration.OrganizationId, out expectedBalance); Decimal actualBalance = bookingManager.GetBalance(registration.OrganizationId, tournament.Id); Assert.AreEqual(expectedBalance, actualBalance); } #region ASSERT #endregion }