Example #1
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));
        }
 public HttpResponseMessage AddApproval(ApprovalModel approvalModel)
 {
     try
     {
         HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.Created)
         {
             Content = new StringContent(JsonConvert.SerializeObject(approvalRepository.AddApproval(approvalModel)))
         };
         return(hrm);
     }
     catch (Exception ex)
     {
         Errors errors          = ErrorsHelper.GetErrors(ex);
         HttpResponseMessage hr = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content = new StringContent(errors.ToString())
         };
         return(hr);
     }
 }
        public IActionResult AddApproval(ApprovalModel approvalModel)
        {
            try
            {
                if (approvalModel == null)
                {
                    return(BadRequest("Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(BadRequest(errors));
                }

                ApprovalModel addedApproval = approvalRepository.AddApproval(approvalModel);
                return(StatusCode(StatusCodes.Status201Created, addedApproval));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }
        public HttpResponseMessage AddApproval(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 addedApproval = approvalRepository.AddApproval(approvalModel);
                return(Request.CreateResponse(HttpStatusCode.Created, addedApproval));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }