Exemple #1
0
 public HttpResponseMessage AddCourse(CourseModel courseModel)
 {
     try
     {
         HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.Created)
         {
             Content = new StringContent(JsonConvert.SerializeObject(courseRepository.AddCourse(courseModel)))
         };
         return(hrm);
     }
     catch (Exception ex)
     {
         Errors errors          = ErrorsHelper.GetErrors(ex);
         HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content = new StringContent(errors.ToString())
         };
         return(hr);
     }
 }
Exemple #2
0
 public HttpResponseMessage GetOneApprovalTypeByCode(string approvalCode)
 {
     try
     {
         HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
         {
             Content = new StringContent(JsonConvert.SerializeObject(approvalTypesRepository.GetOneApprovalTypeByCode(approvalCode)))
         };
         return(hrm);
     }
     catch (Exception ex)
     {
         Errors errors          = ErrorsHelper.GetErrors(ex);
         HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content = new StringContent(errors.ToString())
         };
         return(hr);
     }
 }
 public HttpResponseMessage GetAllPersonsId()
 {
     try
     {
         HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
         {
             Content = new StringContent(JsonConvert.SerializeObject(personRepository.GetAllPersonsId()))
         };
         return(hrm);
     }
     catch (Exception ex)
     {
         Errors errors          = ErrorsHelper.GetErrors(ex);
         HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content = new StringContent(errors.ToString())
         };
         return(hr);
     }
 }
Exemple #4
0
 public HttpResponseMessage GetOnePersonById(string personId)
 {
     try
     {
         PersonModel personModel = studentRepository.GetOneStudentById(personId);
         if (personModel == null)
         {
             personModel = teacherRepository.GetOneTeacherById(personId);
         }
         if (personModel == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "The person record couldn't be found."));
         }
         return(Request.CreateResponse(HttpStatusCode.OK, personModel));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
     }
 }
        public HttpResponseMessage UpdateCellphone(string beforeCellphone, CellphoneModel cellphoneModel)
        {
            try
            {
                cellphoneModel.beforeCellphone = beforeCellphone;

                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(cellphoneRepository.UpdateCellphone(cellphoneModel)))
                };
                return(hrm);
            }
            catch (Exception ex)
            {
                Errors errors          = ErrorsHelper.GetErrors(ex);
                HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errors.ToString())
                };
                return(hr);
            }
        }
Exemple #6
0
        public HttpResponseMessage UpdateVehicle(string updateByNumber, VehicleModel vehicleModel)
        {
            try
            {
                vehicleModel.vehicleNumber = updateByNumber;

                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(vehicleRepository.UpdateVehicle(vehicleModel)))
                };
                return(hrm);
            }
            catch (Exception ex)
            {
                Errors errors          = ErrorsHelper.GetErrors(ex);
                HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errors.ToString())
                };
                return(hr);
            }
        }
Exemple #7
0
        public HttpResponseMessage AddFaculty(FacultyModel facultyModel)
        {
            try
            {
                if (facultyModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                FacultyModel addedFaculty = facultyRepository.AddFaculty(facultyModel);
                return(Request.CreateResponse(HttpStatusCode.Created, addedFaculty));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
        public HttpResponseMessage AddApprovalType(ApprovalTypeModel approvalTypeModel)
        {
            try
            {
                if (approvalTypeModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                ApprovalTypeModel addedApprovalType = approvalTypesRepository.AddApprovalType(approvalTypeModel);
                return(Request.CreateResponse(HttpStatusCode.Created, addedApprovalType));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
        public HttpResponseMessage UpdateStudent(string updateById, StudentModel studentModel)
        {
            try
            {
                studentModel.studentId = updateById;
                StudentModel updatedStudent = studentRepository.UpdateStudent(studentModel);

                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(updatedStudent))
                };
                return(hrm);
            }
            catch (Exception ex)
            {
                Errors errors          = ErrorsHelper.GetErrors(ex);
                HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errors.ToString())
                };
                return(hr);
            }
        }
Exemple #10
0
        public HttpResponseMessage UpdateTeacher(string updateById, TeacherModel teacherModel)
        {
            try
            {
                teacherModel.teacherId = updateById;
                TeacherModel updatedTeacher = teacherRepository.UpdateTeacher(teacherModel);

                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(updatedTeacher))
                };
                return(hrm);
            }
            catch (Exception ex)
            {
                Errors errors          = ErrorsHelper.GetErrors(ex);
                HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errors.ToString())
                };
                return(hr);
            }
        }
Exemple #11
0
        public HttpResponseMessage AddStudent(StudentModel studentModel)
        {
            try
            {
                if (studentModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                StudentModel addedStudent = studentRepository.AddStudent(studentModel);
                return(Request.CreateResponse(HttpStatusCode.Created, addedStudent));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
Exemple #12
0
        public HttpResponseMessage UpdateFaculty(string updateByCode, FacultyModel facultyModel)
        {
            try
            {
                facultyModel.facultyCode = updateByCode;
                FacultyModel updatedFaculty = facultyRepository.UpdateFaculty(facultyModel);

                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(updatedFaculty))
                };
                return(hrm);
            }
            catch (Exception ex)
            {
                Errors errors          = ErrorsHelper.GetErrors(ex);
                HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errors.ToString())
                };
                return(hr);
            }
        }
Exemple #13
0
        public HttpResponseMessage AddTeacher(TeacherModel teacherModel)
        {
            try
            {
                if (teacherModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                TeacherModel addedTeacher = teacherRepository.AddTeacher(teacherModel);
                return(Request.CreateResponse(HttpStatusCode.Created, addedTeacher));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
Exemple #14
0
        public HttpResponseMessage AddVehicle(VehicleModel vehicleModel)
        {
            try
            {
                if (vehicleModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                VehicleModel addedVehicle = vehicleRepository.AddVehicle(vehicleModel);
                return(Request.CreateResponse(HttpStatusCode.Created, addedVehicle));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
Exemple #15
0
        public HttpResponseMessage UpdateCourse(string updateByCourseCode, CourseModel courseModel)
        {
            try
            {
                courseModel.courseCode = updateByCourseCode;
                CourseModel updatedCourse = courseRepository.UpdateCourse(courseModel);

                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(updatedCourse))
                };
                return(hrm);
            }
            catch (Exception ex)
            {
                Errors errors          = ErrorsHelper.GetErrors(ex);
                HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errors.ToString())
                };
                return(hr);
            }
        }
        public HttpResponseMessage UpdateApproval(string updateByCode, ApprovalModel approvalModel)
        {
            try
            {
                approvalModel.approvalCode = updateByCode;
                ApprovalModel updatedApproval = approvalRepository.UpdateApproval(approvalModel);

                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(updatedApproval))
                };
                return(hrm);
            }
            catch (Exception ex)
            {
                Errors errors          = ErrorsHelper.GetErrors(ex);
                HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errors.ToString())
                };
                return(hr);
            }
        }
Exemple #17
0
        public HttpResponseMessage UpdateVehicle(string vehicleNumber, VehicleModel vehicleModel)
        {
            try
            {
                if (vehicleModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                vehicleModel.vehicleNumber = vehicleNumber;
                VehicleModel updatedVehicle = vehicleRepository.UpdateVehicle(vehicleModel);
                return(Request.CreateResponse(HttpStatusCode.OK, updatedVehicle));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
        public HttpResponseMessage UpdateThreeObjects(string updateByPersonId, ThreeObjectsModel threeObjectsModel)
        {
            try
            {
                threeObjectsModel.personModel.personId           = updateByPersonId;
                threeObjectsModel.approvalModel.approvalPersonId = updateByPersonId;
                threeObjectsModel.vehicleModel.vehicleOwnerId    = updateByPersonId;

                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(threeObjectsRepository.UpdateThreeObjects(threeObjectsModel)))
                };
                return(hrm);
            }
            catch (Exception ex)
            {
                Errors errors          = ErrorsHelper.GetErrors(ex);
                HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errors.ToString())
                };
                return(hr);
            }
        }
        public HttpResponseMessage UpdateApproval(int approvalNumber, ApprovalModel approvalModel)
        {
            try
            {
                if (approvalModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                approvalModel.approvalNumber = approvalNumber;
                ApprovalModel updatedApproval = approvalRepository.UpdateApproval(approvalModel);
                return(Request.CreateResponse(HttpStatusCode.OK, updatedApproval));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
Exemple #20
0
        public HttpResponseMessage UpdateTeacher(string teacherId, TeacherModel teacherModel)
        {
            try
            {
                if (teacherModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                teacherModel.teacherId = teacherId;
                TeacherModel updatedTeacher = teacherRepository.UpdateTeacher(teacherModel);
                return(Request.CreateResponse(HttpStatusCode.OK, updatedTeacher));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
Exemple #21
0
        public HttpResponseMessage UpdateCellphone(string beforeCellphone, CellphoneModel cellphoneModel)
        {
            try
            {
                if (cellphoneModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                cellphoneModel.beforeCellphone = beforeCellphone;
                CellphoneModel updatedCellphone = cellphoneRepository.UpdateCellphone(cellphoneModel);
                return(Request.CreateResponse(HttpStatusCode.OK, updatedCellphone));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
Exemple #22
0
        public HttpResponseMessage AddThreeObjects(ThreeObjectsModel threeObjectsModel)
        {
            try
            {
                if (threeObjectsModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                ThreeObjectsModel addedThreeObjects = threeObjectsRepository.AddThreeObjects(threeObjectsModel);
                return(Request.CreateResponse(HttpStatusCode.Created, addedThreeObjects));
            }
            catch (Exception ex)
            {
                threeObjectsRepository.DeleteThreeObjects(threeObjectsModel.personModel.personId);
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
Exemple #23
0
        public HttpResponseMessage UpdateStudent(string studentId, StudentModel studentModel)
        {
            try
            {
                if (studentModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                studentModel.studentId = studentId;
                StudentModel updatedStudent = studentRepository.UpdateStudent(studentModel);
                return(Request.CreateResponse(HttpStatusCode.OK, updatedStudent));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
Exemple #24
0
        public HttpResponseMessage UpdateFaculty(string facultyCode, FacultyModel facultyModel)
        {
            try
            {
                if (facultyModel == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                facultyModel.facultyCode = facultyCode;
                FacultyModel updatedFaculty = facultyRepository.UpdateFaculty(facultyModel);
                return(Request.CreateResponse(HttpStatusCode.OK, updatedFaculty));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }