コード例 #1
0
        public IHttpActionResult Put(Int32 id, [FromBody] StudentModel model)
        {
            //Update
            try
            {
                if (id == 0 || model == null)
                {
                    return(BadRequest());
                }

                model.Id = id;
                var student = StudentModelToStudent.Transform(model);

                if (student.Id == 0)
                {
                    StudentRepository.Evict(student);
                    return(NotFound());
                }

                StudentRepository.Update(student);

                model = StudentToStudentModel.Transform(student);
                return(Ok(model));
            }
            catch (Exception ex)
            {
                //TODO: Log Errors...

                return(InternalServerError());
            }
        }
コード例 #2
0
        public IHttpActionResult Patch(Int32 id, [FromBody] Delta <StudentModel> delta)
        {
            #region Json Payload Example

            /*
             * {
             *  "FirstName":"Bob",
             *  "LastName":"Smith"
             * }
             */
            #endregion
            try
            {
                if (id == 0)
                {
                    return(BadRequest());
                }

                var student = StudentRepository.Get(id);

                if (student == null)
                {
                    return(NotFound());
                }

                var model = StudentToStudentModel.Transform(student);
                delta.Patch(model);

                student = StudentModelToStudent.Transform(model, student);

                StudentRepository.Update(student);

                return(Ok(model));
            }
            catch (Exception ex)
            {
                //TODO: Log Errors...

                return(InternalServerError());
            }
        }
コード例 #3
0
        public IHttpActionResult Get(Int32 id, String fields = null)
        {
            try
            {
                if (id == default(Int32))
                {
                    return(NotFound());
                }

                var student = StudentRepository.Get(id, eagerLoading: true);
                var model   = StudentToStudentModel.Transform(student)
                              .ApplyFieldFiltering(fields);

                return(Ok(model));
            }
            catch (Exception ex)
            {
                //TODO: Log Errors...

                return(InternalServerError());
            }
        }