예제 #1
0
        public async Task<IHttpActionResult> PostClass(CreateClassBindingModel classvm)
        {
            if(!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var @class = await _classManager.CreateClass(classvm);
            if(@class == null)
            {
                return BadRequest(ModelState);
            }
            return CreatedAtRoute("DefaultApi", new { id = @class.Id }, new ClassViewModel(@class));
        }
예제 #2
0
        /// <summary>
        /// Creates a new class from the given binding model
        /// </summary>
        /// <param name="classBindingModel">Model containing the details of the class
        /// to create</param>
        /// <returns>Null if teacher could not be found. Otherwise, returns the 
        /// created class</returns>
        public async Task<Class> CreateClass(CreateClassBindingModel classBindingModel)
        {
            var teacher = await _userManager.FindByNameAsync(classBindingModel.TeacherUserName);

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

            Class @class = new Class
            {
                Title = classBindingModel.Title,
                Prefix = classBindingModel.Prefix,
                CourseNumber = classBindingModel.CourseNumber,
                Section = classBindingModel.Section,
                Teacher = teacher,
                GradeDistribution = classBindingModel.GradeDistribution
            };

            _db.Classes.Add(@class);
            await _db.SaveChangesAsync();
            return @class;
        }