Example #1
0
        public async Task IsTestExists()
        {
            string userName = "******";
            //Configuring Application User
            ApplicationUser user = new ApplicationUser()
            {
                Email = userName, UserName = userName
            };
            await _userManager.CreateAsync(user);

            var applicationUser = await _userManager.FindByEmailAsync(user.Email);

            var category = CreateCategory("category Name");
            await _categoryRepository.AddCategoryAsync(category);

            var testCategoryAC = new List <TestCategoryAC>
            {
                new TestCategoryAC()
                {
                    CategoryId = category.Id,
                    IsSelect   = true,
                }
            };
            //Creating Test
            var test = CreateTest("English");
            await _testRepository.CreateTestAsync(test, applicationUser.Id);

            await _testRepository.GetTestByIdAsync(test.Id, applicationUser.Id);

            var result = await _testRepository.IsTestExists(test.Id);

            Assert.True(result);
        }
        public async Task GetTestInstructionsAsyncTest()
        {
            //Creating test
            var test = await CreateTestAsync();

            //Creating test category
            var category1 = CreateCategory("Mathematics");
            await _categoryRepository.AddCategoryAsync(category1);

            var category2 = CreateCategory("Computer");
            await _categoryRepository.AddCategoryAsync(category2);

            var category3 = CreateCategory("History");
            await _categoryRepository.AddCategoryAsync(category3);

            var testCategoryAC = new List <TestCategoryAC>
            {
                new TestCategoryAC()
                {
                    CategoryId = category1.Id,
                    IsSelect   = true
                },
                new TestCategoryAC()
                {
                    CategoryId = category1.Id,
                    IsSelect   = false
                }, new TestCategoryAC()
                {
                    CategoryId = category2.Id,
                    IsSelect   = true
                }
            };

            await _testRepository.AddTestCategoriesAsync(test.Id, testCategoryAC);

            //Creating test questions
            var questionList = new List <QuestionAC>
            {
                CreateQuestionAC(true, "Category1 type question", category1.Id, 1),
                CreateQuestionAC(false, "Category1 type question", category1.Id, 2),
                CreateQuestionAC(true, "Category3 type question", category3.Id, 3),
                CreateQuestionAC(true, "Category3 type question", category3.Id, 4),
            };
            var testQuestionList = new List <TestQuestionAC>();

            questionList.ForEach(x =>
            {
                var testQuestion        = new TestQuestionAC();
                testQuestion.CategoryID = x.Question.CategoryID;
                testQuestion.Id         = x.Question.Id;
                testQuestion.IsSelect   = x.Question.IsSelect;
                testQuestionList.Add(testQuestion);
            });
            await _testRepository.AddTestQuestionsAsync(testQuestionList, test.Id);

            var testInstruction = await _testConductRepository.GetTestInstructionsAsync(_stringConstants.MagicString);

            Assert.NotNull(testInstruction);
        }
        public async Task <int> AddCategoryAsync(CategoryDTO categoryDTO)
        {
            var category = _mapper.Map <Category>(categoryDTO);
            await _repository.AddCategoryAsync(category);

            return(category.Id);
        }
        public async Task <IActionResult> AddCategoryAsync(AddCategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                Category category = new Category
                {
                    CategoryName = model.CategoryName,
                    Description  = model.Description
                };

                var existingCategory = _categoryRepository.Categories.FirstOrDefault(p => p.CategoryName == category.CategoryName);

                if (existingCategory == null)
                {
                    await _categoryRepository.AddCategoryAsync(category);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "The Category already exists");
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> AddCategory([FromBody] NewCategoryDto newCategory)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (await _categoryRepository.IsDuplicateCategoryAsync(newCategory))
                {
                    ModelState.AddModelError("category", "Category already exists");
                    return(BadRequest(ModelState));
                }

                var categoryId = await _categoryRepository.AddCategoryAsync(newCategory);

                if (categoryId > 0)
                {
                    return(Ok(categoryId));
                }

                return(StatusCode(500, "An error ocurred in server"));
            }
            catch (Exception e)
            {
                _logger.LogCritical($"POST {Route} - {e.GetType().Name} - {e.Message} - {e.StackTrace}");
                return(StatusCode(500, "An error ocurred in server"));
            }
        }
        public async Task <IActionResult> Add(CategoryDTO category)
        {
            var entity = Mapper.Map(category);
            await categoryRepository.AddCategoryAsync(entity);

            await unitOfWork.CompleteAsync();

            return(Accepted());
        }
        public async Task <IActionResult> Create([Bind("IdCategory,Name,PlaceDescription,Description,UpToDate,IdRegion")] Category category)
        {
            if (ModelState.IsValid)
            {
                await _categoryRepository.AddCategoryAsync(category);

                return(RedirectToAction(nameof(Index)));
            }


            return(View(category));
        }
Example #8
0
        public async Task <IActionResult> AddCategory(Category model)
        {
            if (ModelState.IsValid)
            {
                var result = await _repo.AddCategoryAsync(model);

                if (result != null)
                {
                    return(Ok());
                }
            }
            return(BadRequest());
        }
        public async Task <IActionResult> Post([FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var createdItem = await _categoryRepo.AddCategoryAsync(category);

            return(CreatedAtAction(
                       actionName: nameof(Get),
                       routeValues: new { id = createdItem.CategoryId },
                       value: createdItem));
        }
Example #10
0
        public async Task GetAllCategoriesTest()
        {
            var category = CreateCategory();
            await _categoryRepository.AddCategoryAsync(category);

            var result = await _categoryRepository.GetAllCategoriesAsync();

            Assert.True(result.Count() == 1);
        }
        private void SeedDatabase()
        {
            var categories = new List <CategoryEntity>
            {
                new CategoryEntity {
                    Name   = "Programming",
                    Quizes = new List <QuizEntity>
                    {
                        new QuizEntity
                        {
                            Name  = "Basic",
                            Words = new List <WordEntity>
                            {
                                new WordEntity
                                {
                                    Name = "Spreadsheet"
                                },
                                new WordEntity
                                {
                                    Name = "Excel"
                                }
                            }
                        },
                        new QuizEntity
                        {
                            Name  = "Intermediate",
                            Words = new List <WordEntity>
                            {
                            }
                        },
                        new QuizEntity
                        {
                            Name  = "Advanced",
                            Words = new List <WordEntity>
                            {
                            }
                        }
                    }
                },
                new CategoryEntity("Office"),
                new CategoryEntity("Graphics")
            };

            foreach (var item in categories)
            {
                _categoryRepository.AddCategoryAsync(item);
            }
            _unitOfWork.CompleteAsync();
        }
Example #12
0
        public async Task <IActionResult> AddCategoryAsync([FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (await _categoryRepository.IsCategoryExistAsync(category.CategoryName, category.Id))
            {
                ModelState.AddModelError(_stringConstants.ErrorKey, _stringConstants.CategoryNameExistsError);
                return(BadRequest(ModelState));
            }
            await _categoryRepository.AddCategoryAsync(category);

            return(Ok(category));
        }
Example #13
0
        public async Task <IActionResult> Create([Bind("Id,Name,ImageFile")] Category category)
        {
            if (ModelState.IsValid)
            {
                category.Id            = Guid.NewGuid();
                category.CategoryImage = await fileManager.UploadImage(category.ImageFile);

                await _repository.AddCategoryAsync(category);

                await _repository.SaveAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <ActionResult> CreateCategoryAsync(CategoryDto category)
        {
            if (category == null)
            {
                return(BadRequest());
            }
            var categoryModel = _mapper.Map <Category>(category);
            await _categoryRepository.AddCategoryAsync(categoryModel);

            if (await _categoryRepository.SaveChangesAsync() != false)
            {
                var categoryDto = _mapper.Map <CategoryDto>(categoryModel);
                return(CreatedAtRoute("GetCategory", new { categoryId = categoryDto.CategoryId }, categoryDto));
            }
            return(BadRequest());
        }
Example #15
0
        public async Task <CategoryResponse> AddCategoryAsync(Category category)
        {
            try
            {
                await categoryRepository.AddCategoryAsync(category);

                await unitOfWork.CompleteAsync();

                return(new CategoryResponse(category));
            }
            catch (Exception ex)
            {
                return(new CategoryResponse("Category Eklenirken Hata Alındı : Hata " + ex.Message.ToString()));

                throw;
            }
        }
Example #16
0
        public async Task <ActionResult> Post([FromBody] CategoryCreationDTO categoryCreationDTO)
        {
            try
            {
                var category = mapper.Map <CategoryEntity>(categoryCreationDTO);

                category.Status = 1;

                await repository.AddCategoryAsync(category);

                var categoryDTO = mapper.Map <CategoryDTO>(category);

                return(new CreatedAtRouteResult("getCategory", new { id = category.CategoryId }, categoryDTO));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
Example #17
0
        public async Task AddCategoryAsync(CategoryDTO category)
        {
            await Task.Run(async() =>
            {
                if (category == null)
                {
                    throw new ArgumentNullException(nameof(category));
                }

                _categoryRepository.Configure();

                var categoryDAL = new Category {
                    Id = Guid.NewGuid()
                };
                categoryDAL.InjectFrom(category);

                await _categoryRepository.AddCategoryAsync(categoryDAL);
            });
        }
Example #18
0
        /// <summary>
        /// Creates Coding Question
        /// </summary>
        /// <returns>Created CodingQuestion object</returns>
        private async Task <QuestionAC> CreateCodingQuestion()
        {
            var categoryToCreate = CreateCategory();
            await _categoryRepository.AddCategoryAsync(categoryToCreate);

            QuestionAC codingQuestion = new QuestionAC
            {
                Question = new QuestionDetailAC
                {
                    QuestionDetail  = "<h1>Write a program to add two number</h1>",
                    CategoryID      = categoryToCreate.Id,
                    DifficultyLevel = DifficultyLevel.Easy,
                    QuestionType    = QuestionType.Programming
                },
                CodeSnippetQuestion = new CodeSnippetQuestionAC
                {
                    CheckCodeComplexity          = true,
                    CheckTimeComplexity          = true,
                    RunBasicTestCase             = true,
                    RunCornerTestCase            = false,
                    RunNecessaryTestCase         = false,
                    LanguageList                 = new String[] { "Java", "C" },
                    CodeSnippetQuestionTestCases = new List <CodeSnippetQuestionTestCases>()
                    {
                        new CodeSnippetQuestionTestCases()
                        {
                            TestCaseTitle       = "Necessary check",
                            TestCaseDescription = "This case must be successfuly passed",
                            TestCaseMarks       = 10.00,
                            TestCaseType        = TestCaseType.Necessary,
                            TestCaseInput       = "2+2",
                            TestCaseOutput      = "4",
                        }
                    }
                },
                SingleMultipleAnswerQuestion = null
            };

            return(codingQuestion);
        }
Example #19
0
        public async Task <ActionResult> AddCategory(CategoryAddDto categoryAddDto)
        {
            var category = _mapper.Map <Category>(categoryAddDto);

            try
            {
                if (categoryAddDto == null)
                {
                    return(BadRequest());
                }

                var createdCategory = await _categoryRepository.AddCategoryAsync(category);

                return(CreatedAtAction(nameof(GetCategory), new { Id = createdCategory.Id },
                                       createdCategory));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Erorr adding data to the database"));
            }
        }
Example #20
0
        public async Task <CategoryResponseObject> AddCategoryAsync(CategoryRequestObject category)
        {
            var date   = DateTimeOffset.Now;
            var subCat = _mapper.Map <List <SubCategory> >(category.SubCategories);

            subCat.ForEach(s => s.CreatedBy = category.CreatedBy);
            var cat = _mapper.Map <Category>(category);

            cat.TimeStampCreated = date;
            cat.SubCategories    = subCat;

            var res = await _catRepo.AddCategoryAsync(cat);

            if (res == null)
            {
                return(null);
            }

            var result = _mapper.Map <CategoryResponseObject>(res);

            return(result);
        }
        public async Task <IActionResult> AddCategory([FromBody] CategoryResource categoryResource)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var category = mapper.Map <CategoryResource, Category>(categoryResource);
                category.LastUpdate = DateTime.Now;
                categoriesRepository.AddCategoryAsync(category);
                await unitOfWork.CompleteAsync();

                var newCategory = await categoriesRepository.GetCategoryByIdAsync(category.Id);

                return(Ok(mapper.Map <Category, CategoryResource>(newCategory)));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #22
0
 public async Task <Category> SaveCategoryAsync(string category, string parentCategory = null)
 {
     return(await _categoryRepository.AddCategoryAsync(category, parentCategory));
 }
        public async Task <Unit> Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
        {
            await _categoryRepository.AddCategoryAsync(Category.CreateCategory(request.CategoryName, request.Description));

            return(Unit.Value);;
        }
 public async Task AddCategoryAsync(Category category)
 {
     await categoryRepository.AddCategoryAsync(category, ApiUrl.BASEURL);
 }
Example #25
0
 public async Task <IResponseModel> AddCategoryAsync(ICategoryModel model) => await _categoryRepo.AddCategoryAsync(model);
Example #26
0
 public async Task AddCategoryAsync(Guid id, string name, string description)
 {
     await _repository.AddCategoryAsync(new Category(id, name, description));
 }
Example #27
0
        public async Task GetAllAttendeeMarksDetailsAsyncTest()
        {
            //create test
            var createTest = await CreateTestAsync();

            //create category
            var category = CreateCategory("History");
            await _categoryRepository.AddCategoryAsync(category);

            //create question
            var question1 = CreateQuestionAc(true, "first Question", category.Id, 1, QuestionType.Multiple);
            var question2 = CreateCodingQuestionAc(true, category.Id, 2, QuestionType.Programming);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question1, createTest.CreatedByUserId);

            await _questionRepository.AddCodeSnippetQuestionAsync(question2, createTest.CreatedByUserId);

            var questionId1 = (await _trappistDbContext.Question.SingleAsync(x => x.QuestionDetail == question1.Question.QuestionDetail)).Id;
            var questionId2 = (await _trappistDbContext.Question.SingleAsync(x => x.QuestionDetail == question2.Question.QuestionDetail)).Id;
            //add test category
            var categoryList = new List <DomainModel.Models.Category.Category>();

            categoryList.Add(category);
            var testCategoryList = new List <TestCategoryAC>
            {
                new TestCategoryAC
                {
                    CategoryId = category.Id,
                    IsSelect   = true,
                }
            };

            await _testRepository.AddTestCategoriesAsync(createTest.Id, testCategoryList);

            //add test Question
            var questionList = new List <TestQuestionAC>
            {
                new TestQuestionAC()
                {
                    Id         = question1.Question.Id,
                    CategoryID = question1.Question.CategoryID,
                    IsSelect   = question1.Question.IsSelect
                },
                new TestQuestionAC()
                {
                    Id         = question2.Question.Id,
                    IsSelect   = question2.Question.IsSelect,
                    CategoryID = question2.Question.CategoryID
                }
            };
            await _testRepository.AddTestQuestionsAsync(questionList, createTest.Id);

            //create test attednee
            var testAttendee = CreateTestAttendee(createTest.Id);
            await _testConductRepository.RegisterTestAttendeesAsync(testAttendee);

            //AddTestAnswer
            var answer1 = CreateAnswerAc(questionId1);
            await _testConductRepository.AddAnswerAsync(testAttendee.Id, answer1, 0.0);

            var answer2 = new TestAnswerAC()
            {
                OptionChoice = new List <int>(),
                QuestionId   = questionId2,
                Code         = new Code()
                {
                    Input    = "input",
                    Source   = "source",
                    Language = ProgrammingLanguage.C
                },
                QuestionStatus = QuestionStatus.answered
            };
            await _testConductRepository.AddAnswerAsync(testAttendee.Id, answer2, 0.0);

            //create test conduct
            var testConduct1 = new DomainModel.Models.TestConduct.TestConduct()
            {
                Id             = 1,
                QuestionId     = answer1.QuestionId,
                QuestionStatus = answer1.QuestionStatus,
                TestAttendeeId = testAttendee.Id
            };
            var testConduct2 = new DomainModel.Models.TestConduct.TestConduct()
            {
                Id             = 2,
                QuestionId     = answer2.QuestionId,
                QuestionStatus = answer2.QuestionStatus,
                TestAttendeeId = testAttendee.Id
            };
            await _trappistDbContext.TestConduct.AddAsync(testConduct1);

            await _trappistDbContext.TestConduct.AddAsync(testConduct2);

            await _trappistDbContext.SaveChangesAsync();

            AddTestAnswer(answer1, testConduct1.Id);
            AddTestAnswer(answer2, testConduct2.Id);
            //add test code solution
            var codeSolution1 = new TestCodeSolution()
            {
                TestAttendeeId = testAttendee.Id,
                QuestionId     = questionId2,
                Solution       = answer2.Code.Source,
                Language       = answer2.Code.Language,
                Score          = 1
            };
            var codeSolution2 = new TestCodeSolution()
            {
                TestAttendeeId = testAttendee.Id,
                QuestionId     = questionId2,
                Solution       = answer2.Code.Source,
                Language       = answer2.Code.Language,
                Score          = 0
            };
            await _trappistDbContext.TestCodeSolution.AddAsync(codeSolution1);

            await _trappistDbContext.TestCodeSolution.AddAsync(codeSolution2);

            await _trappistDbContext.SaveChangesAsync();

            var allAttendeeMarksDetails = await _reportRepository.GetAllAttendeeMarksDetailsAsync(createTest.Id);

            var totalQuestionAttempted = allAttendeeMarksDetails.First().NoOfQuestionAttempted;
            var easyQuestionAttempted  = allAttendeeMarksDetails.First().EasyQuestionAttempted;

            Assert.Equal(2, easyQuestionAttempted);
            Assert.Equal(2, totalQuestionAttempted);
        }
 public async Task <ActionResult <CategoryDto> > AddCategory(CategoryDto categoryDto)
 {
     return(await _categoryRepository.AddCategoryAsync(categoryDto));
 }
Example #29
0
        public async Task <CategoryViewModel> AddCategoryAsync(Category category)
        {
            await ClearGetAllKeysAsync();

            return(await _categoryRepository.AddCategoryAsync(category));
        }
Example #30
0
 public async Task AddCategory(Category category)
 {
     await _categoryRepository.AddCategoryAsync(category);
 }