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); }
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)); } }
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); }
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)); } }
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)); }
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); }
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); } }
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)); } }
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); } }