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/")); }
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)); }
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/")); }