public async Task <IActionResult> Index() { var model = new CoursesViewModel(); var availableCourses = await this.courseService.GetAllAvailableCourses(); Guard.WhenArgument(availableCourses, "Available Courses can not be null!").IsNull().Throw(); var availableCoursesModel = mapper.ProjectTo <CourseDto, CourseViewModel>(availableCourses).ToList(); Guard.WhenArgument(availableCoursesModel, "Available Courses can not be null!").IsNull().Throw(); var studentId = this.userManager.GetUserId(this.HttpContext.User); var registeredCourses = await studentService.GetAllRegisteredCourses(studentId); Guard.WhenArgument(registeredCourses, "Registered Courses can not be null!").IsNull().Throw(); foreach (var course in registeredCourses) { for (int i = 0; i < availableCoursesModel.Count(); i++) { if (course.Id == availableCoursesModel[i].Id) { availableCoursesModel[i].IsRegistered = true; } } } model.Courses = availableCoursesModel; return(this.View(model)); }
public IEnumerable <CategoryDto> GetAllCategories() { var allCategories = categories.All ?? throw new ArgumentNullException("Collection of answers can not be Null."); return(mapper.ProjectTo <CategoryDto>(allCategories)); }
public IEnumerable <UserTestsDTO> GetAllUserTests() { var allUserTests = userTests.All. Include(t => t.Test). Include(u => u.User); return(mapper.ProjectTo <UserTestsDTO>(allUserTests)); }
public IEnumerable <TestDTO> GetAllTests() {//Why the f**k you called it GetAllTest and add object Category //.Include(test => test.Questions) // .ThenInclude(q => q.Answers) var allTests = tests.All.AsNoTracking() .Include(test => test.Category).AsNoTracking(); return(mapper.ProjectTo <TestDTO>(allTests)); }
public IEnumerable <TestDto> GetTestsByAuthor(string id) { Guard.WhenArgument(id, "Author's Id").IsNullOrEmpty().Throw(); var authorTests = tests.All.Where(t => t.AuthorId == id).Include(c => c.Category); var dto = mapper.ProjectTo <TestDto>(authorTests); return(dto); }
public IActionResult New() { if (!cache.TryGetValue("Categories", out IEnumerable <CreateCategoryViewModel> allCategories)) { var allCategoriesDto = categories.GetAllCategories(); allCategories = mapper.ProjectTo <CreateCategoryViewModel>(allCategoriesDto).ToList(); var cacheEntryOptions = new MemoryCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromSeconds(300)); cache.Set("Categories", allCategories, cacheEntryOptions); } ViewData["Categories"] = allCategories; return(View()); }
public IActionResult Index() { var activeTestCategory = this.userTestService.CheckIfUserHasActiveTest(); if (activeTestCategory != null) { return(RedirectToAction("Index", "Test", new { category = activeTestCategory.Category.Name })); } var model = new CategoryCollectionViewModel(); var collection = categoryService.GetAllCategories(); model.Categories = mappingProvider.ProjectTo <TestCategoryViewModel>(collection).ToList(); foreach (var category in model.Categories) { if (userTestService.CheckIfUserHasAssignedTest(category.Name)) { category.IsTestTaken = true; } else { category.IsTestTaken = false; } } return(View(model)); }
public ICollection <OrderModel> GetAllById(int userId) { var allOrders = this.orders.All; var userOrders = allOrders.Where(x => x.UserId == userId).AsQueryable(); var mapped = mapper.ProjectTo <Order, OrderModel>(userOrders); return(mapped.ToList()); }
public async Task <IActionResult> Index(int id) { //Cache string key = string.Format("TestId {0}", id); if (!cache.TryGetValue(key, out TestDto test)) { test = this.tests.GetById(id); var cacheEntryOptions = new MemoryCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromMinutes(5)); cache.Set(key, test, cacheEntryOptions); } // var test = this.tests.GetById(id); var user = await this.userManager.GetUserAsync(HttpContext.User); var userId = user.Id; var takenTest = resultService.GetStartedTest(userId, id); if (takenTest != null) { if (takenTest.SubmittedOn != null) { return(this.RedirectToAction("All", "Dashboard")); } if (takenTest.TimeExpire < DateTime.Now) { return(this.RedirectToAction("All", "Dashboard")); } } else if (takenTest == null) { takenTest = new UserTestDto() { UserId = userId, TestId = test.Id, StartOn = DateTime.Now, TimeExpire = DateTime.Now.AddMinutes(test.RequiredTime).AddSeconds(5) }; resultService.Add(takenTest); } var model = new IndexViewModel() { StartedOn = takenTest.StartOn, UserId = user.Id, TestId = test.Id, TestName = test.Title, Duration = TimeSpan.FromMinutes(test.RequiredTime), CategoryName = test.Category.Name, TimeLeft = TimeSpan.FromMinutes(test.RequiredTime) - (DateTime.Now.Subtract(takenTest.StartOn)), Questions = mapper.ProjectTo <QuestionViewModel>(test.Questions.AsQueryable()).ToList(), }; return(View(model)); }
public IEnumerable <UserTestDto> GetSubmitedTestsByUser(string id) { Guard.WhenArgument(id, "User id").IsNullOrEmpty().Throw(); var tests = userTests.All.Where(t => t.UserId == id); var dto = mapper.ProjectTo <UserTestDto>(tests); return(dto); }
public IActionResult ShowResults() { var model = new ResultBagViewModel(); var userTests = this.userTestsService.GetAllUserTests(); model.ResultBag = mapper.ProjectTo <ResultsViewModel>(userTests.AsQueryable()); return(View(model)); }
public IActionResult ShowResults() { var modelTests = new TestRealBagViewModel(); var firstUserTests = this.testService.GetAllTestsWithOutStuffInIttEditDTO(); modelTests.ResultBag = mapper.ProjectTo <TestEditDTO>(firstUserTests.AsQueryable()); var modelResults = new ResultBagViewModel(); var secondUserTests = this.userTestsService.GetAllUserTests(); modelResults.ResultBag = mapper.ProjectTo <ResultsViewModel>(secondUserTests.AsQueryable()); var model = new TestResultBag(); model.Test = modelTests; model.Results = modelResults; return(View(model)); }
public IQueryable <AnswerDTO> GetAnswersForQuestion(string questionId) { var questionAnswers = this.questionRepository .All .Include(q => q.Answers) .Where(q => q.Id.ToString() == questionId) .SelectMany(q => q.Answers); var answers = mapper.ProjectTo <AnswerDTO>(questionAnswers); return(answers); }
public IEnumerable <CollectionDTO> GetUserCollections(string userId) { if (userId.IsNullOrWhitespace()) { throw new InvalidUserIdException(); } var collections = this.collections .All .Where(x => x.UserId == userId) .OrderBy(x => x); return(mapper.ProjectTo <CollectionDTO>(collections)); }
public IEnumerable <AnswerDto> GetAnswersForQuestion(string questionId) { if (string.IsNullOrEmpty(questionId)) { throw new ArgumentNullException("cannot be null!"); } var answersForQuestion = this.questionRepo.All. Include(q => q.Answers) .Where(q => q.Id.ToString() == questionId) .SelectMany(q => q.Answers); var answersDto = mapper.ProjectTo <AnswerDto>(answersForQuestion); return(answersDto.ToList()); }
public async Task <IActionResult> Index(string id) { var user = await this.userManager.GetUserAsync(HttpContext.User); StatusType check = resultService.CheckForTakenTest(user.Id, id); TestDto testDto = null; var startTime = DateTime.Now; if (check == StatusType.TestSubmitted) { return(RedirectToAction("Index", "Dashboard")); } if (check == StatusType.TestNotSubmitted) { testDto = this.resultService.GetTestFromCategory(user.Id, id); startTime = (DateTime)resultService.GetUserTest(user.Id, testDto.Id).StartTime; } else { testDto = this.testService.GetRandomTestByCategory(id); } var questions = mapper.ProjectTo <QuestionViewModel>(testDto.Questions.AsQueryable()).ToList(); var model = new IndexViewModel() { UserId = user.Id, TestId = testDto.Id, TestName = testDto.TestName, Duration = testDto.Duration, CategoryName = id, Questions = questions, StartedOn = startTime }; if (check == StatusType.TestNotStarted) // move to service { var resultDto = mapper.MapTo <UserTestDto>(model); resultDto.Id = Guid.NewGuid(); resultService.AddResult(resultDto); this.saver.SaveChanges(); } return(View(model)); }
public IEnumerable <CategoryDTO> GetAllCategories() { var categories = this.categories.All.Include(x => x.Tests); var categoriesDto = mapper.ProjectTo <CategoryDTO>(categories).ToList(); foreach (var item in categoriesDto) { if (item.Tests.Count > 0 && item.Tests.Any(t => t.Status == TestStatus.Published && !t.IsDeleted)) { item.CategoryState = UserTestState.Start; } else { item.CategoryState = UserTestState.CategoryEmpty; } } return(categoriesDto); }
public IActionResult ShowCategories() { var model = new CategoriesViewModel(); var categories = this.categoriesService.GetAllCategories(); var categoriesViewModel = this.mapper.ProjectTo <CategoryViewModel>(categories.AsQueryable()).ToHashSet(); var allStartedUserTests = userTestsService.GetCurrentUserTests(userService.GetLoggedUserId(User)); var allStartedCategoriesView = mapper.ProjectTo <CategoryViewModel>(allStartedUserTests.AsQueryable()).ToHashSet(); foreach (var item in categoriesViewModel) { if (!allStartedCategoriesView.Any(x => x.Category == item.Category)) { allStartedCategoriesView.Add(item); } } model.AllCategories = allStartedCategoriesView.OrderBy(x => (int)(x.CategoryState)); return(View(model)); }
public IEnumerable <IUserModel> GetAllUsers() { return(mapper.ProjectTo <User, UserModel>(this.users.All)); }
public IEnumerable <ProductModel> GetAll() { return(mapper.ProjectTo <Product, ProductModel>(this.products.All)); }