Пример #1
0
        public async Task <IActionResult> New(CourseViewModel course)
        {
            try{
                ViewBag.ListParrent = await Task.Factory.StartNew(() => GetAllCourseParrent());

                if (ModelState.IsValid)
                {
                    if (!_courseRepo.CheckAlias(course.Alias))
                    {
                        var coursemodel = new CourseModel {
                            Name             = course.Name,
                            Alias            = course.Alias,
                            Image            = course.Image,
                            Status           = course.Status,
                            ShortDesciptions = course.ShortDescription,
                            Content          = course.Content,
                            Activated        = course.Activated,
                            Price            = course.Price,
                            Orders           = course.Orders,
                            CourseId         = course.CourseId
                        };
                        await Task.Factory.StartNew(() => _courseRepo.Insert(coursemodel));

                        return(RedirectToAction("New"));
                    }
                    ModelState.AddModelError("", "hãy thử tên khác hoặc kiểm tra lại định danh");
                }
                return(View());
            }catch (Exception ex) {
                ModelState.AddModelError("", ex.Message);
                return(View());
            }
        }