コード例 #1
0
ファイル: ClassesController.cs プロジェクト: frankibem/RGSWeb
        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
ファイル: ClassManager.cs プロジェクト: frankibem/RGSWeb
        /// <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;
        }