Beispiel #1
0
 public IActionResult CreateTest(CreateTestViewModel vm)
 {
     if (ModelState.IsValid)
     {
         var newTest = new PruebaPsicologica
         {
             Nombre          = vm.Nombre,
             Descripcion     = vm.Descripcion,
             Preguntas       = new List <Pregunta>(),
             FechaCreado     = DateTime.Now,
             FechaModificado = DateTime.MinValue,
             Activo          = false
         };
         var result = _repository.AddTest(newTest);
         if (result != null)
         {
             var responsevm = new AddQuestionsToTestViewModel {
                 Id = result.Id, Nombre = result.Nombre
             };
             return(RedirectToAction("AddQuestionsToTest", "Admin", responsevm));
         }
         ModelState.AddModelError("", "Hubo un problema mientras se intentaba agregar el nuevo test, porfavor intente mas tarde.");
         return(View(vm));
     }
     return(View(vm));
 }
        public async Task <IActionResult> CreateTest()
        {
            CreateTestViewModel model = new CreateTestViewModel();

            model.Topics = (await _topicAppService.GetAllAsync()).ToList();
            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Create(CreateTestViewModel createTestViewModel)
        {
            if (!string.IsNullOrEmpty(createTestViewModel.Name) && !string.IsNullOrEmpty(createTestViewModel.Description))
            {
                Test test = new Test
                {
                    User                  = await _userManager.GetUserAsync(HttpContext.User),
                    CategoryId            = createTestViewModel.CategoryId,
                    ResultScaleId         = createTestViewModel.ResultScaleId,
                    Name                  = createTestViewModel.Name,
                    Description           = createTestViewModel.Description,
                    TimeRestricting       = createTestViewModel.TimeRestricting,
                    Rating                = 0,
                    CreatedDate           = System.DateTime.Now,
                    PublishedDate         = System.DateTime.Now,
                    ReadyForPassing       = createTestViewModel.ReadyForPassing,
                    ShowAnswers           = createTestViewModel.ShowAnswers,
                    SinglePassing         = createTestViewModel.SinglePassing,
                    OnlyRegisteredCanPass = createTestViewModel.OnlyRegisteredCanPass
                };

                UserContext.Tests.Add(test);
                await UserContext.SaveChangesAsync();

                return(RedirectToAction("MyTests"));
            }

            return(View());
        }
Beispiel #4
0
        public IActionResult Create(CreateTestViewModel vm)
        {
            var genres = genreRepository.getAll();

            if (!ModelState.IsValid)
            {
                return(View(genres));
            }

            if (vm.Difficulty < 0 || vm.Difficulty > 10)
            {
                ModelState.AddModelError("errors", "არასწორია სირთულის დონე");
                return(View(genres));
            }

            if (genres.Where(x => x.Id == vm.GenreId).FirstOrDefault() == null)
            {
                ModelState.AddModelError("errors", "არ არსებობს ასეთი ჟანრი");
                return(View(genres));
            }

            Test test = new Test
            {
                Title      = vm.Title,
                Difficulty = vm.Difficulty,
                GenreId    = vm.GenreId
            };

            testRepository.Add(test);

            return(RedirectToAction("Index", "Test"));
        }
 public ActionResult CreateTest(CreateTestViewModel model)
 {
     if (testService.GetOneByPredicate(u => u.Title.ToLower() == model.Title.ToLower()) != null)
     {
         ModelState.AddModelError(String.Empty, "Test with this title already registered.");
         return(View(model));
     }
     if (ModelState.IsValid)
     {
         int userId = userService.GetOneByPredicate(u => u.UserName == User.Identity.Name).Id;
         model.Questions = new List <QuestionViewModel>();
         var test = model.ToBllTest();
         test.DateCreation = DateTime.Now;
         test.UserId       = userId;
         test.TestResults  = new List <BllTestResult>();
         testService.Create(test);
         if (Request.IsAjaxRequest())
         {
             int testId = testService.GetOneByPredicate(t => t.Title == model.Title).Id;
             return(RedirectToAction("TestDetails", "Test", new { testId = testId }));
         }
         return(Redirect(Url.Action("ShowLastTests", "Test")));
     }
     return(PartialView("_CreateTest"));
 }
Beispiel #6
0
 public ActionResult CreateTest(CreateTestViewModel newTest)
 {
     if (ModelState.IsValid)
     {
         testServices.CreateNewTest(newTest);
     }
     return(View());
 }
        public void CreateNewTest(CreateTestViewModel testViewModel)
        {
            var     config = new MapperConfiguration(cfg => { cfg.CreateMap <CreateTestViewModel, Test>(); cfg.IgnoreUnmapped(); });
            IMapper mapper = config.CreateMapper();
            var     test   = mapper.Map <CreateTestViewModel, Test>(testViewModel);

            testRepository.CreateNewTest(test);
        }
Beispiel #8
0
        public IActionResult SaveEditedTest([FromBody] CreateTestViewModel testViewModel)
        {
            var testDTO = this.mapper.MapTo <TestDTO>(testViewModel);

            this.testService.EditTest(testDTO);


            return(Content("/Admin/Admin/Index"));
        }
        public async Task <ActionResult <int> > Create([FromBody] CreateTestViewModel test)
        {
            var entity = test.MapTo <Domain.Entities.Domain.Test>();

            entity.UserId = UserId;

            await _testService.CreateTestAsync(entity);

            return(entity.Id);
        }
        public int CreateNewTest(CreateTestViewModel testViewModel)
        {
            int     id;
            var     config = new MapperConfiguration(cfg => { cfg.CreateMap <CreateTestViewModel, Test>(); cfg.IgnoreUnmapped(); });
            IMapper mapper = config.CreateMapper();
            var     test   = mapper.Map <CreateTestViewModel, Test>(testViewModel);

            id = testRepository.CreateNewTest(test);
            return(id);
        }
Beispiel #11
0
 public ActionResult CreateTest(CreateTestViewModel test)
 {
     test.Creator = User.Identity.Name;
     _testService.CreateTest(test.ToBll());
     if (Request.IsAjaxRequest())
     {
         return(Json(new { message = "Test successfully created" }, JsonRequestBehavior.AllowGet));
     }
     return(View());
 }
Beispiel #12
0
        public ActionResult CreateTest(CreateTestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("CreateTest"));
            }
            var test = model.ToBllTest();

            test.Creator = User.Identity.Name;
            _testService.CreateTest(test);
            return(Redirect(Url.Action("Home", "Test")));
        }
        public IActionResult CreateNewTest(CreateTestViewModel question)
        {
            var model = this.mapper.MapTo <TestDTO>(question);

            // model.AuthorId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            model.AuthorId = userService.GetLoggedUserId(this.User);

            this.createTestService.Create(model);

            TempData["Success-Message"] = "You published a new post!";
            return(this.View()); /*this.RedirectToAction("Index", "Home");*/
        }
Beispiel #14
0
 public static TestDTO ToBllTest(this CreateTestViewModel createTestViewModel)
 {
     return(new TestDTO()
     {
         Name = createTestViewModel.Name,
         Time = createTestViewModel.Time,
         Creator = createTestViewModel.Creator,
         Description = createTestViewModel.Description,
         Questions = createTestViewModel.Questions.ToQuestionDtoCollection().ToList(),
         Answers = createTestViewModel.Answers.ToAnswerDtoCollection().ToList()
     });
 }
Beispiel #15
0
        public ActionResult SaveTest(CreateTestViewModel newTest)
        {
            newTest.UserId = Convert.ToInt32(Session["CurrentUserID"]);
            int testId = 0;

            if (ModelState.IsValid)
            {
                testId = testServices.CreateNewTest(newTest);
            }
            TempData["TestId"] = testId;
            return(RedirectToAction("CreateQuestions", "Question"));
        }
Beispiel #16
0
        public IActionResult SaveTest([FromBody] CreateTestViewModel testViewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(View("CreateTest"));
            }

            var testDTO = this.mapper.MapTo <TestDTO>(testViewModel);

            this.testService.CreateTest(testDTO);
            return(Content("/Admin/Admin/Index"));
        }
Beispiel #17
0
        public ActionResult CreateQuestion(CreateTestViewModel model)
        {
            foreach (CreateQuestionViewModel item in model.Questions)
            {
                if (!item.IsValid())
                {
                    return(View(model));
                }
            }

            _testStore.CreateTest(model.ToDataModel(), User.Identity.Name, model.QuestionsToDataModel());
            return(RedirectToAction("Index", "Admin"));
        }
        public IActionResult CreateNewTest()
        {
            //var model = new CreateTestViewModel()
            //{model

            //};
            var model = new CreateTestViewModel()
            {
                CategoryNames = this.categoriesServices.GetAllCategoriesNames().ToList()
            };

            return(View(model));
        }
 public ActionResult SaveTest(CreateTestViewModel newTest)//Create Test
 {
     if (ModelState.IsValid)
     {
         newTest.UserId      = Convert.ToInt32(Session["CurrentUserID"]);
         newTest.CreatedBy   = newTest.UserId;
         newTest.CreatedTime = DateTime.Now;
         int testId = testService.CreateNewTest(newTest);
         TempData["TestId"] = testId;
         return(RedirectToAction("UpcomingTest"));
     }
     return(View());
 }
        public IActionResult CreateNewTest(CreateTestViewModel test)
        {
            var categoryID = this.categoriesServices.GetIdByCategoryName(test.CategoryName);

            var model = this.mapper.MapTo <TestDTO>(test);

            model.CategoryId = categoryID;
            model.AuthorId   = userService.GetLoggedUserId(this.User);

            this.createTestService.Create(model);

            //TempData["Success-Message"] = "You published a new post!";
            return(this.RedirectToAction("ShowResults", "Results"));
        }
Beispiel #21
0
        public ActionResult CreateTest(CreateTestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            model.Questions = new List <CreateQuestionViewModel>();
            for (int i = 0; i < model.NumberOfQuestions; i++)
            {
                model.Questions.Add(new CreateQuestionViewModel(i + 1));
            }

            return(View("CreateQuestion", model));
        }
        public ActionResult SaveTest(CreateTestViewModel newTest)//Create Test
        {
            if (ModelState.IsValid)
            {
                newTest.UserId      = Convert.ToInt32(Session["CurrentUserID"]);
                newTest.CreatedBy   = newTest.UserId;
                newTest.CreatedTime = DateTime.Now;


                testService.CreateNewTest(newTest);
                return(RedirectToAction("DisplayAvailableTest"));
            }
            return(View());
        }
Beispiel #23
0
        public IActionResult Create()
        {
            categories   = UserContext.Сategories.ToList();
            resultScales = UserContext.ResultScales.ToList();


            CreateTestViewModel model = new CreateTestViewModel
            {
                Categories   = categories,
                ResultScales = resultScales
            };

            return(View(model));
        }
Beispiel #24
0
        public static TestEntity ToBll(this CreateTestViewModel test)
        {
            var testEntity = new TestEntity()
            {
                Time                 = test.Time,
                Creator              = test.Creator,
                Description          = test.Description,
                Name                 = test.Name,
                Questions            = test.Questions?.Select(q => q.ToBll()).ToList(),
                MinProcentToPassTest = test.MinProcentToPassTest
            };

            return(testEntity);
        }
Beispiel #25
0
        public async Task <IActionResult> CreateNewTest([FromForm] CreateTestViewModel createTestView)
        {
            TestDetails     testDetails = new TestDetails();
            TestTypeMapping typeMapping = new TestTypeMapping();
            var             Map         = _dbContext.TestType.Where(s => s.TestName == createTestView.TestType).FirstOrDefault();

            testDetails.Date = createTestView.TestDate;
            _dbContext.TestDetails.Add(testDetails);

            typeMapping.TestId     = testDetails.ID;
            typeMapping.TestTypeId = Map.ID;
            _dbContext.TestTypeMapping.Add(typeMapping);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #26
0
 public static BllTest ToBllTest(this CreateTestViewModel createTestViewModel)
 {
     if (createTestViewModel == null)
     {
         return(null);
     }
     return(new BllTest()
     {
         Title = createTestViewModel.Title,
         Description = createTestViewModel.Description,
         TimeLimit = createTestViewModel.TimeLimit,
         MinToSuccess = createTestViewModel.MinToSuccess,
         ThemeId = createTestViewModel.ThemeId,
         Questions = createTestViewModel.Questions.Select(r => r.ToBllQuestion()).ToList()
     });
 }
Beispiel #27
0
        public IActionResult CreateTest()
        {
            var createTestViewModel = new CreateTestViewModel();
            var categories          = this.categoryService.GetAllCategories().ToList();

            foreach (var category in categories)
            {
                createTestViewModel.Categories.Add
                    (new CategoryViewModel()
                {
                    Category = category.Name
                }
                    );
            }

            return(View(createTestViewModel));
        }
        public IActionResult New([FromBody] CreateTestViewModel model)
        {
            bool isValid = ValidateTestModel(model);

            if (isValid && this.ModelState.IsValid)
            {
                var dto = this.mapper.MapTo <TestDto>(model);
                dto.AuthorId   = this.userManager.GetUserId(this.HttpContext.User);
                dto.CategoryId = this.categories.GetCategoryByName(model.Category).Id;
                //dto.StatusId = this.statuses.GetStatusByName(model.Status).Id;

                //cache
                var adminIdKey = this.userManager.GetUserId(HttpContext.User);
                this.cache.Remove(adminIdKey);
                this.cache.Remove("UserResults");

                if (model.Status == "Published")
                {
                    TempData["Success-Message"] = "You successfully published a new test!";
                    this.tests.Publish(dto);
                }
                else if (model.Status == "Draft")
                {
                    TempData["Success-Message"] = "You successfully created a new test!";
                    this.tests.SaveAsDraft(dto);
                }

                return(Json(Url.Action("Index", "Dashboard", new { area = "Administration" })));
            }

            if (!cache.TryGetValue("Categories", out IEnumerable <CreateCategoryViewModel> allCategories))
            {
                var allCategoriesDto = categories.GetAllCategories();
                allCategories = mapper.ProjectTo <CreateCategoryViewModel>(allCategoriesDto).ToList();
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSlidingExpiration(TimeSpan.FromMinutes(5));

                cache.Set("Categories", allCategories, cacheEntryOptions);
            }

            ViewData["Categories"]    = allCategories;
            TempData["Error-Message"] = "Test creation failed!";

            return(Json(Url.Action("Index", "Dashboard", new { area = "Administration" })));
        }
        //[Authorize(Roles ="Coach")]
        public async Task <IActionResult> CreateTest(CreateTestViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _service.createTest(model.testType, model.testDate, model.testType);

                    return(RedirectToAction("ViewList"));//redirect to  Startpage after creating Test;
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An Error has occured, Test May Not be created");
            }

            return(View());
        }
        public IActionResult Edit([FromBody] CreateTestViewModel model, int id)
        {
            //cache
            string key = string.Format("TestId {0}", id);

            this.cache.Remove(key);
            var adminIdKey = this.userManager.GetUserId(HttpContext.User);

            cache.Remove(adminIdKey);

            model.Id = id;

            bool isValid = ValidateTestModel(model);

            if (isValid && this.ModelState.IsValid)
            {
                var dto = this.mapper.MapTo <TestDto>(model);
                dto.AuthorId   = this.userManager.GetUserId(this.HttpContext.User);
                dto.CategoryId = this.categories.GetCategoryByName(model.Category).Id;
                dto.StatusId   = this.statuses.GetStatusByName(model.Status).Id;

                TempData["Success-Message"] = "You successfully editted the test!";
                this.tests.Edit(dto);

                return(Json(Url.Action("Index", "Dashboard", new { area = "Administration" })));
            }

            if (!cache.TryGetValue("Categories", out IEnumerable <CreateCategoryViewModel> allCategories))
            {
                var allCategoriesDto = categories.GetAllCategories();
                allCategories = mapper.ProjectTo <CreateCategoryViewModel>(allCategoriesDto).ToList();
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSlidingExpiration(TimeSpan.FromMinutes(5));

                cache.Set("Categories", allCategories, cacheEntryOptions);
            }

            ViewData["Categories"]    = allCategories;
            TempData["Error-Message"] = "Test editting failed!";

            return(View(model));
        }