コード例 #1
0
        public ThreeObjectsModel GetAllThreeObjectsByVehicleNumber(string vehicleNumber)
        {
            ThreeObjectsModel threeObjects = new ThreeObjectsModel();


            VehicleModel vehicleModel = vehicleRepository.GetOneVehicleByNumber(vehicleNumber);
            PersonModel  personModel;

            if (studentRepository.GetOneStudentById(vehicleModel.vehicleOwnerId) != null)
            {
                personModel = studentRepository.GetOneStudentById(vehicleModel.vehicleOwnerId);
            }
            else
            {
                personModel = teacherRepository.GetOneTeacherById(vehicleModel.vehicleOwnerId);
            }

            ApprovalModel approvalModel = approvalRepository.GetOneApprovalByPersonId(vehicleModel.vehicleOwnerId);

            threeObjects.personModel   = personModel;
            threeObjects.vehicleModel  = vehicleModel;
            threeObjects.approvalModel = approvalModel;

            return(threeObjects);
        }
コード例 #2
0
 public HttpResponseMessage UpdateThreeObjects(string personId, 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.personModel.personId           = personId;
         threeObjectsModel.approvalModel.approvalPersonId = personId;
         threeObjectsModel.vehicleModel.vehicleOwnerId    = personId;
         ThreeObjectsModel updatedThreeObjects = threeObjectsRepository.UpdateThreeObjects(threeObjectsModel);
         return(Request.CreateResponse(HttpStatusCode.OK, updatedThreeObjects));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
     }
 }
コード例 #3
0
        public List <ThreeObjectsModel> GetAllThreeObjects()
        {
            List <ThreeObjectsModel> threeObjectsList = new List <ThreeObjectsModel>();

            List <PersonModel> allPersonsId = personRepository.GetAllPersonsId();

            for (int i = 0; i < allPersonsId.Count; i++)
            {
                ThreeObjectsModel threeObjects = new ThreeObjectsModel();

                PersonModel personModel;

                if (studentRepository.GetOneStudentById(allPersonsId[i].personId) != null)
                {
                    personModel = studentRepository.GetOneStudentById(allPersonsId[i].personId);
                }
                else
                {
                    personModel = teacherRepository.GetOneTeacherById(allPersonsId[i].personId);
                }

                VehicleModel  vehicleModel  = vehicleRepository.GetOneVehicleByOwnerId(allPersonsId[i].personId);
                ApprovalModel approvalModel = approvalRepository.GetOneApprovalByPersonId(allPersonsId[i].personId);

                threeObjects.personModel   = personModel;
                threeObjects.vehicleModel  = vehicleModel;
                threeObjects.approvalModel = approvalModel;

                threeObjectsList.Add(threeObjects);
            }

            return(threeObjectsList);
        }
コード例 #4
0
 public HttpResponseMessage GetAllThreeObjectsByPersonId(string personId)
 {
     try
     {
         ThreeObjectsModel threeObjectsModel = threeObjectsRepository.GetAllThreeObjectsByPersonId(personId);
         return(Request.CreateResponse(HttpStatusCode.OK, threeObjectsModel));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
     }
 }
コード例 #5
0
        public ThreeObjectsModel AddThreeObjects(ThreeObjectsModel threeObjectsModel)
        {
            if (threeObjectsModel.personModel is StudentModel)
            {
                studentRepository.AddStudent(threeObjectsModel.personModel as StudentModel);
            }

            if (threeObjectsModel.personModel is TeacherModel)
            {
                teacherRepository.AddTeacher(threeObjectsModel.personModel as TeacherModel);
            }

            vehicleRepository.AddVehicle(threeObjectsModel.vehicleModel);
            approvalRepository.AddApproval(threeObjectsModel.approvalModel);


            return(GetAllThreeObjectsByPersonId(threeObjectsModel.personModel.personId));
        }
コード例 #6
0
        public ThreeObjectsModel UpdateThreeObjects(ThreeObjectsModel threeObjectsModel)
        {
            if (threeObjectsModel.personModel is StudentModel)
            {
                studentRepository.UpdateStudent(threeObjectsModel.personModel as StudentModel);
            }

            if (threeObjectsModel.personModel is TeacherModel)
            {
                teacherRepository.UpdateTeacher(threeObjectsModel.personModel as TeacherModel);
            }

            VehicleModel  vehicle  = vehicleRepository.UpdateVehicle(threeObjectsModel.vehicleModel);
            ApprovalModel approval = approvalRepository.UpdateApproval(threeObjectsModel.approvalModel);

            ThreeObjectsModel threeObjectsModel2 = GetAllThreeObjectsByPersonId(threeObjectsModel.personModel.personId);

            return(threeObjectsModel2);
        }
コード例 #7
0
 public HttpResponseMessage AddThreeObjects(ThreeObjectsModel threeObjectsModel)
 {
     try
     {
         HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.Created)
         {
             Content = new StringContent(JsonConvert.SerializeObject(threeObjectsRepository.AddThreeObjects(threeObjectsModel)))
         };
         return(hrm);
     }
     catch (Exception ex)
     {
         Errors errors          = ErrorsHelper.GetErrors(ex);
         HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content = new StringContent(errors.ToString())
         };
         return(hr);
     }
 }
コード例 #8
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));
            }
        }
コード例 #9
0
        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);
            }
        }