public async Task <LiteratureModel> Get() { var literature = await literatureRepository.GetQuery() .FirstOrDefaultAsync(); return(LiteratureMap.Map(literature)); }
public async Task <DeleteTestModel> Delete(DeleteTestModel model) { var template = await testTemplateRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == model.Id); template.IsActive = false; await dataContext.SaveChangesAsync(); return(model); }
public async Task <List <UserViewModel> > GetAsync() { var users = await usersRepository .GetQuery() .ToListAsync(); return(users .Select(MapUser) .ToList()); }
public async Task <UserProfileModel> AddRole(Guid userId, Role role) { var user = await usersRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == userId); if (user != null && !user.UserRoles.Any(x => x.Role == role)) { user.UserRoles.Add(new UserRole { Role = role }); await dataContext.SaveChangesAsync(); } return(UserProfileMap.Map(user)); }
public async Task CreateUsersWithAllAchievementsAsync() { var user = new User() { FirstName = "Vadim", LastName = "Prokopchuk" }; var newUser = new User() { FirstName = "New", LastName = "User" }; usersRepository.Add(user); usersRepository.Add(newUser); await dataContext.SaveChangesAsync(); var achievements = await achievementRepository.GetQuery().ToListAsync(); foreach (var achievement in achievements) { var userAchievement = new UserAchievement() { CreatedAt = DateTime.Now, UserId = user.Id, AchievementId = achievement.Id }; userAchievementRepository.Add(userAchievement); } await dataContext.SaveChangesAsync(); }
public async Task <List <GroupModel> > GetAllSimple() { var groups = await groupsRepository.GetQuery().ToListAsync(); return(groups .Select(x => new GroupModel { Id = x.Id, Name = x.Name, CreatedAt = x.CreatedAt, ModifiedAt = x.ModifiedAt, Users = x.Users.Select(UserMap.Map) .OrderBy(x => x.LastName) .ThenBy(x => x.FirstName) .ToList() }) .ToList()); }
public async Task <List <KnowledgeTestResultModel> > Results(Guid id, Guid userId) { var results = await knowledgeTestRepository .GetQuery() .Where(x => x.TestTemplateId == id && x.UserId == userId) .OrderByDescending(x => x.CreatedAt) .ToListAsync(); return(results.Select(knowledgeTestResultService.GetResult).ToList()); }
public async Task <List <CardTestTemplateModel> > GetCardTemplates() { var templates = await testTemplateRepository .GetQuery() .Where(x => x.IsActive) .ToListAsync(); var user = await currentUser.GetCurrentUserAsync(); var userTests = (await Queryable.Where(knowledgeTestRepository .GetQuery(), x => x.UserId == user.Id) .ToListAsync()) .GroupBy(x => x.TestTemplateId); var templateCards = templates .Select(x => new CardTestTemplateModel { Id = x.Id, Name = x.Name, Description = x.Description, CreatedAt = x.CreatedAt, CountOfQuestions = x.CountOfQuestions, }) .ToList(); foreach (var userTestGroup in userTests) { var lastTest = userTestGroup.OrderByDescending(f => f.ModifiedAt).First(); var card = templateCards.FirstOrDefault(x => x.Id == userTestGroup.Key); if (card != null) { card.LastResult = lastTest.Questions.Count(x => x.IsProvidedCorrectAnswer); card.Attempts = userTestGroup.Count(); } } return(templateCards); }
public async Task PrintAllAsync() { foreach (var user in await usersRepository.GetQuery().ToListAsync()) { Console.WriteLine("User: "******" Id: {0}", user.Id); Console.WriteLine(" Full Name: {0} {1}", user.FirstName, user.LastName); Console.WriteLine(" Achievements: "); foreach (var userAchievement in user.UserAchievements) { Console.WriteLine(" - Achievement: {0} ({1})", userAchievement.Achievement.Name, userAchievement.CreatedAt); } Console.WriteLine(); } }
private async Task LoadUser() { if (currentUser == null) { var userId = contextService.GetCurrentUserId(); if (userId != null) { currentUser = await usersRepository .GetQuery() .Include(x => x.UserRoles) .Include(x => x.Group) .FirstOrDefaultAsync(x => x.Id == userId.Value); currentUser.ActiveAt = DateTime.Now; await dataContext.SaveChangesAsync(); } } }
public async Task Update(UpdateGroupModel model) { var group = await groupsRepository.GetQuery().FirstAsync(x => x.Id == model.Id); if (group != null) { group.Name = model.Name; foreach (var user in await usersRepository.GetQuery().ToListAsync()) { user.GroupId = null; if (model.Users != null && model.Users.Contains(user.Id)) { user.GroupId = group.Id; } } await dataContext.SaveChangesAsync(); } }
public async Task <List <LectureModel> > GetAsync() { var lectures = await lectureRepository.GetQuery().ToListAsync(); return(lectures.Select(LectureMap.Map).ToList()); }
public async Task <User> GetByEmailAsync(string email) { return(await usersRepository.GetQuery().FirstOrDefaultAsync(x => x.Email == email)); }
public async Task <List <TagModel> > GetAsync() { var tags = await tagRepository.GetQuery().ToListAsync(); return(tags.Select(TagMap.Map).ToList()); }