コード例 #1
0
        public async Task <IActionResult> CreateAsync(AdminTestViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                //model.Categories = await this.GetCategoriesAsync();
                return(View("Create", model));
            }

            var test = this.testsServices.ExistsByNameAsync(model.Name);

            if (!(await test))
            {
                var dto = new TestDTO
                {
                    Name          = model.Name,
                    RequestedTime = model.RequestedTime,
                    AuthorId      = model.AuthorId = this.userManager.GetUserId(this.HttpContext.User), // TODO required??
                    Category      = model.Category,
                    Questions     = model.Questions
                };

                await this.testsServices.CreateAsync(dto);
            }

            this.toastr.AddSuccessToastMessage($"Test {model.Name} created successfully!");

            return(this.Redirect("/admin/"));
        }
コード例 #2
0
        public ViewResult Admin(Admin admin)
        {
            var tests = context.Tests.Where(a => !a.IsDel).ToList();
            var obg   = new AdminTestViewModel()
            {
                Admin = admin, Tests = tests, ImgEdit = "/img/Edit.jpg", ImgDel = "/img/Delete.jpg"
            };

            return(View(obg));
        }
コード例 #3
0
        public async Task <IActionResult> PublishAsync(AdminTestViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(View(model));
            }

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

            dto.AuthorId = this.userManager.GetUserId(this.HttpContext.User);

            await this.testsServices.PublishAsync(dto);

            this.toastr.AddSuccessToastMessage($"Test {model.Name} published successfully!");
            return(this.Redirect("/admin/"));
        }