public async Task UpdateMindfight_Test() { await CreateDemoUser(); // Act await UsingDbContextAsync(async context => { var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash"); johnNashUser.ShouldNotBeNull(); using (AbpSession.Use(null, johnNashUser.Id)) { await CreateDemoMindfight(); var createdMindfight = await GetDemoMindfight(); var updatedMindfightDto = new MindfightDto() { Title = "Hello", Description = createdMindfight.Description, StartTime = createdMindfight.StartTime, TeamsLimit = createdMindfight.TeamsLimit, Id = createdMindfight.Id }; await _mindfightService.UpdateMindfight(updatedMindfightDto); var mindfight = await _mindfightService .GetMindfight(createdMindfight.Id); mindfight.ShouldNotBeNull(); mindfight.Title.ShouldBe("Hello"); } }); }
public async Task UpdateMindfight(MindfightDto mindfight) { var currentMindfight = await _mindfightRepository.FirstOrDefaultAsync(x => x.Id == mindfight.Id); if (currentMindfight == null) { throw new UserFriendlyException("Protmūšis su nurodytu id neegzistuoja!"); } var user = await _userManager.Users.IgnoreQueryFilters().FirstOrDefaultAsync(u => u.Id == _userManager.AbpSession.UserId); if (user == null) { throw new UserFriendlyException("Vartotojas neegzsituoja!"); } if (!(currentMindfight.CreatorId == _userManager.AbpSession.UserId || _permissionChecker.IsGranted("ManageMindfights"))) { throw new AbpAuthorizationException("Jūs neturite teisės redaguoti šį protmūšį!"); } currentMindfight.Title = mindfight.Title; currentMindfight.Description = mindfight.Description; currentMindfight.StartTime = mindfight.StartTime; currentMindfight.PrepareTime = mindfight.PrepareTime; currentMindfight.TeamsLimit = mindfight.TeamsLimit; mindfight.UsersAllowedToEvaluate = mindfight.UsersAllowedToEvaluate ?? new List <string>(); await UpdateEvaluators(currentMindfight.Id, mindfight.UsersAllowedToEvaluate); await _mindfightRepository.UpdateAsync(currentMindfight); }
public async Task <MindfightDto> GetMindfight(long mindfightId) { var currentMindfight = await _mindfightRepository .GetAll() .Include(x => x.Tours) .Include(x => x.Registrations).ThenInclude(x => x.Team) .Include(x => x.Evaluators).ThenInclude(x => x.User) .FirstOrDefaultAsync(x => x.Id == mindfightId); if (currentMindfight == null) { throw new UserFriendlyException("Protmūšis su tokiu id neegzistuoja!"); } var user = _userManager.Users.IgnoreQueryFilters().FirstOrDefault(u => u.Id == _userManager.AbpSession.UserId); if (user == null) { throw new UserFriendlyException("Vartotojas neegzistuoja!"); } var creator = await _userManager.Users.IgnoreQueryFilters().FirstOrDefaultAsync(u => u.Id == currentMindfight.CreatorId); if (creator == null) { throw new UserFriendlyException("Protmūšio kūrėjas neegzistoja!"); } var mindfight = new MindfightDto { Id = currentMindfight.Id, Title = currentMindfight.Title, Description = currentMindfight.Description, StartTime = currentMindfight.StartTime, TeamsLimit = currentMindfight.TeamsLimit, IsActive = currentMindfight.IsActive, IsFinished = currentMindfight.IsFinished, CreatorId = creator.Id, CreatorEmail = creator.EmailAddress, PrepareTime = currentMindfight.PrepareTime, ToursCount = currentMindfight.Tours.Count, RegisteredTeamsCount = currentMindfight.Registrations.Count, TeamsAllowedToParticipate = new List <string>(), UsersAllowedToEvaluate = new List <string>() }; foreach (var team in currentMindfight.Registrations.Where(x => x.IsConfirmed)) { mindfight.TeamsAllowedToParticipate.Add(team.Team.Name); } foreach (var allowedUser in currentMindfight.Evaluators) { mindfight.UsersAllowedToEvaluate.Add(allowedUser.User.EmailAddress); } return(mindfight); }
public async Task GetAllowedToEvaluateMindfights_Test() { await CreateDemoUser(); await CreateDemoUser2(); // Act await UsingDbContextAsync(async context => { var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash"); johnNashUser.ShouldNotBeNull(); var johnNash2User = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.nash2"); johnNashUser.ShouldNotBeNull(); using (AbpSession.Use(null, johnNashUser.Id)) { await CreateDemoMindfight(); var createdMindfight = await GetDemoMindfight(); var updatedMindfightDto = new MindfightDto() { Title = createdMindfight.Title, Description = createdMindfight.Description, StartTime = createdMindfight.StartTime, TeamsLimit = createdMindfight.TeamsLimit, Id = createdMindfight.Id, UsersAllowedToEvaluate = new List <string> { johnNash2User.EmailAddress } }; await _mindfightService.UpdateMindfight(updatedMindfightDto); } using (AbpSession.Use(null, johnNash2User.Id)) { var evaluatingMindfights = await _mindfightService .GetAllowedToEvaluateMindfights(); evaluatingMindfights.Count.ShouldBeGreaterThanOrEqualTo(1); } }); }