Exemple #1
0
        public async Task <IActionResult> Create(InstancesCreationBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            //var instance = this.mapper.Map<CourseInstance>(model);
            //this.contex.CourseInstances.Add(instance);
            //this.contex.SaveChanges();
            //// TODO
            //// return RedirectToAction("Details", new { id = instance.Id );
            //return View();

            if (!ModelState.IsValid)
            {
                return(View());
            }

            int instanceId = await this.courseInstancesService.CreateInstance(model);

            this.TempData.Put("__Message", new MessageModel()
            {
                Type    = MessageType.Success,
                Message = "Course instance created succesfully."
            });

            return(RedirectToAction("Details", new { id = instanceId }));
        }
        public async Task <int> CreateInstance(InstancesCreationBindingModel model)
        {
            var instance = this.Mapper.Map <CourseInstance>(model);

            await this.DbContext.CourseInstances.AddAsync(instance);

            await this.DbContext.SaveChangesAsync();

            return(instance.Id);
        }
        public async Task <InstancesCreationBindingModel> PrepareInstanceForCreation(int courseId)
        {
            var course = await this.DbContext.Courses.FindAsync(courseId);

            if (course == null)
            {
                return(null);
            }

            var model = new InstancesCreationBindingModel()
            {
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now.AddMonths(1),
                CourseId  = course.Id,
                Name      = course.Name
            };

            return(model);
        }