Exemplo n.º 1
0
        public IHttpActionResult AddMaterial(int id, MaterialModel material)
        {
            var course = this.data.Courses
                .All()
                .FirstOrDefault(c => c.Id == id);

            if (course == null)
            {
                return BadRequest("Course not exist - invalid id");
            }

            if (!this.ModelState.IsValid)
            {
                return BadRequest(this.ModelState);
            }

            course.Materials.Add(new Material
            {
                Content = material.Content
            });

            this.data.Courses.SaveChanges();

            return Ok(material);
        }
        public IHttpActionResult Change(MaterialModel materialModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var material = this.StudentSystemData.Materials.Find(materialModel.MaterialId);
            if (material == null)
            {
                return this.NotFound();
            }

            try
            {
                material.DownloadUrl = materialModel.DownloadUrl;
                material.HomeworkId = materialModel.HomeworkId;
                materialModel.Type = materialModel.Type;

                this.StudentSystemData.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!this.MaterialExists(materialModel.MaterialId))
                {
                    return this.NotFound();
                }
                else
                {
                    throw;
                }
            }

            return this.StatusCode(HttpStatusCode.NoContent);
        }