예제 #1
0
 public int AddInstructor(InstructorPerson IPerson)
 {
     using (TransactionScope tran = new TransactionScope()) {
         Persons.Add(IPerson.Person); // this person is tracked and in context
         // then we can add as instructor by setting the navigation property.
         //person.Instructor = new Instructor() {
         //    Id = person.Id
         //};
         IPerson.Instructor.Id = IPerson.Person.Id;
         Instructors.Add(IPerson.Instructor);
         //   Complete();
         tran.Complete();
         return(IPerson.Person.Id);
     }
 }
예제 #2
0
        public ActionResult Create(InstructorPerson IPerson)
        {
            try {
                // TODO: Add insert logic here
                //Department dept = new Department() {
                //    Name = DepartmentName,
                //    Budget = Budget
                //};

                _instructorService.AddInstructor(IPerson);
                return(RedirectToAction("Index"));
            }
            catch {
                return(View());
            }
        }
예제 #3
0
        public HttpResponseMessage Post([FromBody] InstructorPerson Instructor)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Instructor data is invalid."));
            }

            try {
                _Instructorservice.AddInstructor(Instructor);
                var message = Request.CreateResponse(HttpStatusCode.Created, Instructor);
                message.Headers.Location = new Uri(Url.Link("GetInstructorById", new { id = Instructor.Person.Id }));
                return(message);
            }
            catch (Exception ex) {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Some internal error occurs..."));
            }
        }
예제 #4
0
 public HttpResponseMessage Put([FromUri] int id, [FromBody] InstructorPerson instructor)
 {
     if (!ModelState.IsValid)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Instructor data is invalid."));
     }
     try {
         Instructor ins = _Instructorservice.GetInstructorById(id);
         if (ins == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "Instructor with Id " + id.ToString() + " not found to update"));
         }
         _Instructorservice.UpdateInstructor(instructor);
         return(Request.CreateResponse(HttpStatusCode.OK, instructor));
     }
     catch (Exception ex) {// should log ex ourselves, should not return to the user
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Some internal error occurs..."));
     }
 }
예제 #5
0
 public void UpdateInstructor(InstructorPerson instructor)
 {
     Persons.Update(instructor.Person);
     Instructors.Update(instructor.Instructor);
 }