public IHttpActionResult CreateAssessment([FromBody] AssessmentsParametersCreate assessmentsParametersCreate)
        {
            if (assessmentsParametersCreate != null && ModelState.IsValid)
            {
                AssessmentsDTO assessmentsDTO = _gasstationsservice.CreateAssessments(assessmentsParametersCreate, out ReturnValues returnValues);

                if (!returnValues.Error)
                {
                    return(Ok(new ResponseSuccess
                    {
                        Success = true,
                        Status = Convert.ToInt32(returnValues.Code),
                        Message = returnValues.Message,
                        Data = new
                        {
                            assessments = assessmentsDTO,
                        },
                    }));
                }

                return(Ok(new ResponseError
                {
                    Success = false,
                    Status = Convert.ToInt32(returnValues.Code),
                    Message = returnValues.Message
                }));
            }

            return(BadRequest(ModelState));
        }
Ejemplo n.º 2
0
        public AssessmentsDTO CreateAssessments(AssessmentsParametersCreate assessmentsParametersCreate, out ReturnValues returnValues)
        {
            #region Parameters

            Assessment     assessment;
            AssessmentsDTO assessmentsDTO = null;
            returnValues = new ReturnValues();
            bool edit = EditAssessment(assessmentsParametersCreate.GasStationID, assessmentsParametersCreate.RegistrationID);
            #endregion

            if (!edit)
            {
                try
                {
                    assessment = new Assessment()
                    {
                        GasStaionID    = Convert.ToInt32(assessmentsParametersCreate.GasStationID),
                        RegistrationID = Convert.ToInt32(assessmentsParametersCreate.RegistrationID),
                        Assessment1    = Convert.ToBoolean(assessmentsParametersCreate.Assessment),
                        CreatedOn      = DateTime.Now
                    };

                    _unitOfWork.AssessmentRepository.Insert(assessment);
                    _unitOfWork.PersistChanges();

                    assessmentsDTO = new AssessmentsDTO
                    {
                        ID             = assessment.ID.ToString(),
                        GasStaionID    = assessment.GasStaionID.ToString(),
                        RegistrationID = assessment.RegistrationID.ToString(),
                        Assessment     = assessment.Assessment1.ToString(),
                        CreatedOn      = assessment.CreatedOn.ToString(),
                    };

                    returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok));
                }
                catch (Exception ex)
                {
                    returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message + " inner --> " + ex.InnerException);
                }
            }
            else
            {
                try
                {
                    int gasstation   = Convert.ToInt32(assessmentsParametersCreate.GasStationID);
                    int registration = Convert.ToInt32(assessmentsParametersCreate.RegistrationID);

                    assessment = _unitOfWork.AssessmentRepository.Get(row => row.GasStaionID == gasstation && row.RegistrationID == registration);

                    if (assessment == null)
                    {
                        returnValues.SetReturnValues(true, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.NotFound));
                        return(assessmentsDTO);
                    }

                    assessment.Assessment1 = Convert.ToBoolean(assessmentsParametersCreate.Assessment);

                    _unitOfWork.AssessmentRepository.Update(assessment);
                    _unitOfWork.PersistChanges();

                    assessmentsDTO = new AssessmentsDTO
                    {
                        ID             = assessment.ID.ToString(),
                        GasStaionID    = assessment.GasStaionID.ToString(),
                        RegistrationID = assessment.RegistrationID.ToString(),
                        Assessment     = assessment.Assessment1.ToString(),
                        CreatedOn      = assessment.CreatedOn.ToString(),
                    };

                    returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok));
                }
                catch (Exception ex)
                {
                    returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message);
                }
            }
            return(assessmentsDTO);
        }