private async Task <IActionResult> LoadArticleForm(int id, FormActionEnum action)
        {
            var userId = this.userManager.GetUserId(this.User);

            if (userId == null)
            {
                this.TempData.AddErrorMessage(WebConstants.InvalidUserMsg);
                return(this.RedirectToAction(nameof(Index)));
            }

            var exists = await this.articleService.ExistsAsync(id);

            if (!exists)
            {
                this.TempData.AddInfoMessage(WebConstants.ArticleNotFoundMsg);
                return(this.RedirectToAction(nameof(Index)));
            }

            var article = await this.articleService.GetByIdToEditAsync(id, userId);

            if (article == null)
            {
                this.TempData.AddInfoMessage(WebConstants.ArticleNotFoundForAuthorMsg);
                return(this.RedirectToAction(nameof(Index)));
            }

            var model = this.mapper.Map <ArticleFormModel>(article);

            model.Action = action;

            return(this.View(ArticleFormView, model));
        }
Example #2
0
        private void AssertAdminCourseForm(CourseFormModel model, FormActionEnum expectedAction)
        {
            var expectedCourse = this.GetAdminCourse();

            Assert.NotNull(model);
            Assert.Equal(expectedAction, model.Action);
            Assert.Equal(expectedCourse.Name, model.Name);
            Assert.Equal(expectedCourse.Description, model.Description);
            Assert.Equal(expectedCourse.StartDate, model.StartDate);
            Assert.Equal(expectedCourse.EndDate, model.EndDate);
            Assert.Equal(expectedCourse.TrainerId, model.TrainerId);

            this.AssertTrainersSelectList(model.Trainers);
        }
Example #3
0
        private async Task <IActionResult> LoadCurriculumForm(int id, FormActionEnum action)
        {
            var curriculum = await this.adminCurriculumService.GetByIdAsync(id);

            if (curriculum == null)
            {
                this.TempData.AddErrorMessage(WebConstants.CurriculumNotFoundMsg);
                return(this.RedirectToAction(nameof(Index)));
            }

            var model = this.mapper.Map <CurriculumFormModel>(curriculum);

            model.Action = action;

            return(this.View(CurriculumFormView, model));
        }
        private async Task <IActionResult> LoadCourseForm(int id, FormActionEnum action)
        {
            var course = await this.adminCourseService.GetByIdAsync(id);

            if (course == null)
            {
                this.TempData.AddErrorMessage(WebConstants.CourseNotFoundMsg);
                return(this.RedirectToAction(nameof(Web.Controllers.CoursesController.Index), WebConstants.CoursesController));
            }

            var model = this.mapper.Map <CourseFormModel>(course);

            model.Trainers = await this.GetTrainersAsync();

            model.Action    = action;
            model.StartDate = model.StartDate.ToLocalTime();
            model.EndDate   = model.EndDate.ToLocalTime();

            return(this.View(CourseFormView, model));
        }
 public static string ToStyle(this FormActionEnum action)
 => action.ToString().ToStyle();