Ejemplo n.º 1
0
        public IHttpActionResult Update(int id, HomeworkModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            var existingHw = this.data
                .Homeworks
                .All()
                .FirstOrDefault(h => h.Id == id);

            if (existingHw == null)
            {
                return this.BadRequest("No such homework found!");
            }

            existingHw.FileUrl = homework.FileUrl;
            existingHw.Student.FirstName = homework.StudentFirstName;
            existingHw.Student.LastName = homework.StudentLastName;

            this.data.SaveChanges();

            homework.Id = existingHw.StudentIdentification;
            return this.Ok(homework);
        }
Ejemplo n.º 2
0
        public IHttpActionResult Create(HomeworkModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            var newHw = new Homework()
            {
                FileUrl = homework.FileUrl,
                Student = new Student() { FirstName = homework.StudentFirstName, LastName = homework.StudentLastName },
                TimeSent = DateTime.Now,
                CourseId = homework.CourseId,
            };

            this.data.Homeworks.Add(newHw);
            this.data.SaveChanges();

            homework.Id = newHw.StudentIdentification;
            return Ok(homework);
        }
        public IHttpActionResult Create(HomeworkModel homework)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newHomework = new Homework
            {
                FileUrl = homework.FileUrl,
                TimeSent = homework.TimeSent,
                StudentIdentification = homework.StudentIdentification,
                CourseId = homework.CourseId
            };

            this.db.Homeworks.Add(newHomework);
            this.db.SaveChanges();

            homework.HomeworkId = newHomework.Id;

            return Ok(newHomework);
        }