Example #1
0
        public async Task <IHttpActionResult> Post(CourseViewModel course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var _course = new Course
            {
                CourseID = course.CourseID
            };

            db.Courses.Add(_course);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CourseExists(_course.CourseID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = _course.CourseID }, _course));
        }
Example #2
0
        public async Task <ActionResult> Create(Course course)
        {
            if (ModelState.IsValid)
            {
                course.CourseID = Guid.NewGuid();
                db.Courses.Add(course);
                await db.SaveChangesAsync();

                return(RedirectToAction(INDEX_PAGE));
            }

            return(View(course));
        }
Example #3
0
        public async Task <ActionResult> Create([Bind(Include = "ScheduleID,StartTime,EndTime,TeacherID,MinPeople,MaxPeople,CourseID,CourseName,Note,Initiator,CreatedDate,ModifiedBy,ModifiedDate")] Schedule schedule)
        {
            if (ModelState.IsValid)
            {
                db.Schedules.Add(schedule);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CourseID  = new SelectList(db.Courses, "CourseID", "Name", schedule.CourseID);
            ViewBag.TeacherID = new SelectList(db.Teachers, "TeacherID", "Name", schedule.TeacherID);
            return(View(schedule));
        }