public IHttpActionResult Post(HomeworkRequestModel model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

            var db = new StudentSystemDbContext();
            var homeworsRepo = new GenericRepository<Homework>(db);
            var coursesRepo = new GenericRepository<Course>(db);
            var studentsRepo = new GenericRepository<Student>(db);
            Course defaultCourse = coursesRepo.All().ToList().FirstOrDefault();
            Student defaultStudent = studentsRepo.All().ToList().FirstOrDefault();
            var homeworkToAdd = new Homework
            {
                FileUrl = model.FileUrl,
                TimeSent = new DateTime(model.TimeSentTicks),
                Course = defaultCourse,
                CourseId = defaultCourse.Id,
                Student = defaultStudent,
                StudentIdentification = defaultStudent.StudentIdentification
            };

            homeworsRepo.Add(homeworkToAdd);
            homeworsRepo.SaveChanges();
            return this.Ok();
        }
        public IHttpActionResult Get(int id)
        {
            if (id < 1)
            {
                return(this.BadRequest("Homework id cannot be 0 or negative"));
            }

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

            if (result == null)
            {
                return(this.NotFound());
            }

            var homeworkModel = new HomeworkRequestModel
            {
                StudentIdentification = result.StudentIdentification,
                CourseId = result.CourseId,
                FileUrl  = result.FileUrl,
                TimeSent = result.TimeSent
            };

            return(this.Ok(homeworkModel));
        }
        public IHttpActionResult Update(int id, HomeworkRequestModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            var homeworkInDb = this.data.Homeworks
                               .All()
                               .FirstOrDefault(c => c.Id == id);

            homeworkInDb.FileUrl = homework.FileUrl;

            this.data.Homeworks.SaveChanges();

            return(Ok(homeworkInDb));
        }
Esempio n. 4
0
        public IHttpActionResult Post(HomeworkRequestModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var homework = new Homework
            {
                Content  = model.Content,
                Deadline = model.Deadline
            };

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

            return(this.Ok(homework));
        }
        public IHttpActionResult Get(int id)
        {
            var homework = this.data.Homework.SearchFor(h => h.Id == id).FirstOrDefault();
            if (homework == null)
            {
                return this.NotFound();
            }

            var homeworkModel = new HomeworkRequestModel
            {
                StudentId = homework.StudentIdentification,
                CourseId = homework.CourseId,
                FileUrl = homework.FileUrl,
                TimeSent = homework.TimeSent
            };

            return this.Ok(homeworkModel);
        }
        public IHttpActionResult Create(HomeworkRequestModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbCourseId = this.data
                .Courses
                .All()
                .Where(c => c.Id == homework.CourseId)
                .Select(cour => cour.Id)
                .FirstOrDefault();
            if (dbCourseId == 0)
            {
                return BadRequest("Such course ID does not exist!");
            }

            var dbStudentId = this.data
                .Students
                .All()
                .Where(s => s.Id == homework.StudentId)
                .Select(st => st.Id)
                .FirstOrDefault();
            if (dbStudentId == 0)
            {
                return BadRequest("Such student ID does not exist!");
            }

            var newHomework = new Homework
            {
                Content = homework.Content,
                TimeSent = homework.TimeSent,
                CourseId = dbCourseId,
                StudentId = dbStudentId
            };

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

            homework.Id = newHomework.Id;

            return Ok(homework);
        }
Esempio n. 7
0
        public IHttpActionResult Post(HomeworkRequestModel homework)
        {
            if (homework == null)
            {
                return(this.BadRequest("Homework must be set."));
            }
            var h = new Homework
            {
                CourseId = homework.CourseId,
                StudentIdentification = homework.StudentId,
                FileUrl  = homework.FileUrl,
                TimeSent = DateTime.Now
            };

            this.data.Homework.Add(h);
            this.data.SaveChanges();

            return(this.Ok(h.Id));
        }
        public IHttpActionResult Post(HomeworkRequestModel homework)
        {
            if (homework == null)
            {
                return this.BadRequest("Homework must be set.");
            }
            var h = new Homework
            {
                CourseId = homework.CourseId,
                StudentIdentification = homework.StudentId,
                FileUrl = homework.FileUrl,
                TimeSent = DateTime.Now
            };

            this.data.Homework.Add(h);
            this.data.SaveChanges();

            return this.Ok(h.Id);
        }
        public IHttpActionResult Post(HomeworkRequestModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var homeworkToPost = new Homework()
            {
                StudentIdentification = homework.StudentId,
                CourseId = homework.CourseId,
                TimeSent = homework.TimeSent
            };

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

            return this.Ok(homework);
        }
Esempio n. 10
0
        public IHttpActionResult Post(HomeworkRequestModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            this.homeworks.Add(new Homework()
            {
                Content   = model.Content,
                CourseId  = model.CourseId,
                TimeSent  = DateTime.Now,
                StudentId = model.StudentId
            });

            this.homeworks.SaveChanges();

            return(this.Ok());
        }
Esempio n. 11
0
        public IHttpActionResult Get(int id)
        {
            var homework = this.data.Homework.SearchFor(h => h.Id == id).FirstOrDefault();

            if (homework == null)
            {
                return(this.NotFound());
            }

            var homeworkModel = new HomeworkRequestModel
            {
                StudentId = homework.StudentIdentification,
                CourseId  = homework.CourseId,
                FileUrl   = homework.FileUrl,
                TimeSent  = homework.TimeSent
            };

            return(this.Ok(homeworkModel));
        }
        public IHttpActionResult Post(HomeworkRequestModel model)
        {
            var courseInDb = this.courses.GetById(model.CourseId);
            if (courseInDb == null)
            {
                return this.NotFound();
            }

            var homeworkToAdd = new Homework
            {
                CourseId = model.CourseId,
                StudentIdentification = model.StudentIdentification,
                FileUrl = model.FileUrl,
                TimeSent = DateTime.Now
            };

            this.homeworks.Add(homeworkToAdd);
            return this.Ok("Homework added successfully!");
        }
Esempio n. 13
0
        public IHttpActionResult Put(HomeworkRequestModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            this.data.Homework.Update(new Homework
            {
                Id       = homework.Id,
                CourseId = homework.CourseId,
                StudentIdentification = homework.Id,
                FileUrl  = homework.FileUrl,
                TimeSent = DateTime.Now
            });

            this.data.SaveChanges();

            return(this.Ok());
        }
        public IHttpActionResult Post(HomeworkRequestModel model)
        {
            if (model == null)
            {
                return(this.BadRequest("Homework is not set to un instance of object"));
            }

            var newHomework = new Homework()
            {
                FileUrl  = model.FileUrl,
                TimeSent = DateTime.Now,
                StudentIdentification = model.StudentIdentification,
                CourseId = model.CourseId
            };

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

            return(this.Ok(newHomework.Id));
        }
Esempio n. 15
0
        public IHttpActionResult Post(HomeworkRequestModel model)
        {
            var courseInDb = this.courses.GetById(model.CourseId);

            if (courseInDb == null)
            {
                return(this.NotFound());
            }

            var homeworkToAdd = new Homework
            {
                CourseId = model.CourseId,
                StudentIdentification = model.StudentIdentification,
                FileUrl  = model.FileUrl,
                TimeSent = DateTime.Now
            };

            this.homeworks.Add(homeworkToAdd);
            return(this.Ok("Homework added successfully!"));
        }
        public IHttpActionResult Create(HomeworkRequestModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            this.data
            .Homeworks
            .Add(new Homework
            {
                FileUrl = homework.FileUrl,
                // StudentIdentification = homework.StudentIdentification,
                // CourseId = homework.CourseId
            });

            this.data.Homeworks.SaveChanges();

            return(Ok(homework));
        }
        public IHttpActionResult Update(HomeworkRequestModel model)
        {
            var courseInDb = this.courses.GetById(model.CourseId);
            if (courseInDb == null)
            {
                return this.NotFound();
            }

            var homeworkToUpdate = new Homework
            {
                Id = model.Id,
                CourseId = model.CourseId,
                StudentIdentification = model.StudentIdentification,
                FileUrl = model.FileUrl,
                TimeSent = DateTime.Now
            };

            this.homeworks.Update(homeworkToUpdate);
            this.homeworks.SaveChanges();
            return this.Ok("Homework updated successfully!");
        }
Esempio n. 18
0
        public IHttpActionResult Update(HomeworkRequestModel model)
        {
            var courseInDb = this.courses.GetById(model.CourseId);

            if (courseInDb == null)
            {
                return(this.NotFound());
            }

            var homeworkToUpdate = new Homework
            {
                Id       = model.Id,
                CourseId = model.CourseId,
                StudentIdentification = model.StudentIdentification,
                FileUrl  = model.FileUrl,
                TimeSent = DateTime.Now
            };

            this.homeworks.Update(homeworkToUpdate);
            this.homeworks.SaveChanges();
            return(this.Ok("Homework updated successfully!"));
        }
Esempio n. 19
0
        public IHttpActionResult Put(int id, HomeworkRequestModel model)
        {
            var homeworkToUpdate = this.homeworks
                                   .All()
                                   .FirstOrDefault(c => c.Id == id);

            if (homeworkToUpdate == null)
            {
                return(this.NotFound());
            }

            if (!this.ModelState.IsValid || model == null)
            {
                return(this.BadRequest(this.ModelState));
            }

            homeworkToUpdate.Content   = model.Content;
            homeworkToUpdate.CourseId  = model.CourseId;
            homeworkToUpdate.StudentId = model.StudentId;

            this.homeworks.SaveChanges();
            return(this.Ok());
        }
        public IHttpActionResult ById(int id)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbHomework = this.data
                .Homeworks
                .All()
                .FirstOrDefault(h => h.Id == id);
            if (dbHomework == null)
            {
                return BadRequest("Such homework does not exist in database!");
            }

            var homework = new HomeworkRequestModel
            {
                Content = dbHomework.Content,
                TimeSent = dbHomework.TimeSent
            };

            return Ok(homework);
        }
Esempio n. 21
0
        public IHttpActionResult Put(int id, HomeworkRequestModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

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

            if (homework == null)
            {
                return(this.BadRequest("Homework with id " + id + " does not exist!"));
            }

            homework.Content  = model.Content;
            homework.Deadline = model.Deadline;

            this.data.Homeworks.Update(homework);
            this.data.Homeworks.SaveChanges();

            return(this.Ok(model));
        }
        public IHttpActionResult Put(HomeworkRequestModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var homeworkForUpdate = this.data.Homeworks
                                    .SearchFor(h => h.StudentIdentification == model.StudentIdentification && h.CourseId == model.CourseId)
                                    .FirstOrDefault();

            if (homeworkForUpdate == null)
            {
                return(this.NotFound());
            }

            homeworkForUpdate.FileUrl  = model.FileUrl;
            homeworkForUpdate.TimeSent = DateTime.Now;

            this.data.Homeworks.Update(homeworkForUpdate);
            this.data.SaveChanges();

            return(this.Ok(homeworkForUpdate));
        }
        public IHttpActionResult Put(int id, HomeworkRequestModel homework)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var homeworkToUpdate =
                this.db
                .Homeworks
                .All()
                .FirstOrDefault(h => h.Id == id);

            homeworkToUpdate.StudentIdentification = homework.StudentId;
            homeworkToUpdate.CourseId = homework.CourseId;
            homeworkToUpdate.TimeSent = homework.TimeSent;

            this.db.SaveChanges();

            return this.Ok();
        }
        public IHttpActionResult Put(int id, HomeworkRequestModel model)
        {
            var homeworkToUpdate = this.homeworks
               .All()
               .FirstOrDefault(c => c.Id == id);

            if (homeworkToUpdate == null)
            {
                return this.NotFound();
            }

            if (!this.ModelState.IsValid || model == null)
            {
                return this.BadRequest(this.ModelState);
            }

            homeworkToUpdate.Content = model.Content;
            homeworkToUpdate.CourseId = model.CourseId;
            homeworkToUpdate.StudentId = model.StudentId;

            this.homeworks.SaveChanges();
            return this.Ok();
        }
        public IHttpActionResult Update(int id, HomeworkRequestModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbHomework = this.data
                .Homeworks.All()
                .FirstOrDefault(h => h.Id == id);
            if (dbHomework == null)
            {
                return BadRequest("Such homework does not exist in database!");
            }

            dbHomework.Content = homework.Content;
            dbHomework.TimeSent = homework.TimeSent;
            this.data.SaveChanges();

            homework.Id = id;
            return Ok(homework);
        }
        public IHttpActionResult Post(HomeworkRequestModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            this.homeworks.Add(new Homework()
            {
                Content = model.Content,
                CourseId = model.CourseId,
                TimeSent = DateTime.Now,
                StudentId = model.StudentId
            });

            this.homeworks.SaveChanges();

            return this.Ok();
        }
        public IHttpActionResult Put(HomeworkRequestModel homework)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            this.data.Homework.Update(new Homework
            {
                Id = homework.Id,
                CourseId = homework.CourseId,
                StudentIdentification = homework.Id,
                FileUrl = homework.FileUrl,
                TimeSent = DateTime.Now
            });

            this.data.SaveChanges();

            return this.Ok();
        }