Exemplo n.º 1
0
        public async Task <string> CreateAsync(CourseCreateBindingModel course)
        {
            var newCourse = Mapper.Map <Course>(course);

            await this.coursesRepository.AddAsync(newCourse);

            await this.coursesRepository.SaveChangesAsync();

            return(newCourse.Id);
        }
        public async Task <IActionResult> Create(CourseCreateBindingModel bindingModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(bindingModel));
            }

            var user = this.users.GetUser(this.User.Identity.Name);

            var createIsSuccessful = await this.courses.Create(user.Id, bindingModel);

            if (!createIsSuccessful)
            {
                this.ModelState.AddModelError(string.Empty, "There is such course already!");

                return(this.View(bindingModel));
            }

            return(this.RedirectToAction("Index", "Courses", new { area = "Education" }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(CourseCreateBindingModel course)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(course));
            }

            if (this.courseService.AnyCourse(course.Name, course.Semester, course.Year, course.Major))
            {
                TempData["Error"] +=
                    "Error: Course with the same name, semester, year and major already in database.";

                return(this.View(course));
            }

            var couresId = await this.courseService.CreateAsync(course);

            //TODO - clear the form with JS?
            return(RedirectToAction("All", "Courses", new { Area = "Admin" }));
        }