public UpdateResult Update(ObjectId id, SimpleStudentDTO student)
    {
        List <ObjectId> courseIds = new List <ObjectId>();

        foreach (var oId in student.CourseIds)
        {
            courseIds.Add(ObjectId.Parse(oId));
        }

        var filter = Builders <Student> .Filter.Eq("_id", id);

        var update = Builders <Student> .Update.Set("Name", student.Name)
                     .Set("RollNo", student.RollNo)
                     .Set("EnrollmentNo", student.EnrollmentNo)
                     .Set("CourseIds", courseIds);

        return(_collection.UpdateOne(filter, update));
    }
    public Student AddWithCourseIds(SimpleStudentDTO studentDTO)
    {
        List <ObjectId> courseIds = new List <ObjectId>();

        foreach (var oId in studentDTO.CourseIds)
        {
            courseIds.Add(ObjectId.Parse(oId));
        }
        Student newStudent = new Student
        {
            Id           = ObjectId.GenerateNewId(),
            Name         = studentDTO.Name,
            RollNo       = studentDTO.RollNo,
            EnrollmentNo = studentDTO.EnrollmentNo,
            CourseIds    = courseIds
        };

        this.Add(newStudent);
        return(newStudent);
    }
示例#3
0
        public ActionResult <UpdateResult> Put(string id, [FromBody] SimpleStudentDTO student)
        {
            var OId = ObjectId.Parse(id);

            return(this._studentRepository.Update(OId, student));
        }
示例#4
0
 public ActionResult <Student> Post([FromBody] SimpleStudentDTO student)
 {
     return(_studentRepository.AddWithCourseIds(student));
 }