コード例 #1
0
        public ActionResult GetIntermediateDetailsById(long id)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest(new ApiBadRequestResponse()));
                }
                else
                {
                    bool isExist = _service.CheckIsIntermediateDetailsExist(id);
                    if (isExist == false)
                    {
                        return(StatusCode(StatusCodes.Status404NotFound, new ApiResponse(404, Constants.recordNotFound)));
                    }

                    IntermediateDetails details = _service.GetIntermediateDetailsById(id);

                    if (details != null)
                    {
                        return(Ok(new ApiOkResponse(details)));
                    }
                    else
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse(500, null)));
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                return(StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse(500, null)));
            }
        }
コード例 #2
0
        public IntermediateDetails GetIntermediateDetails(string xml)
        {
            IntermediateDetails details = new IntermediateDetails();
            string spName = MIDDerivationLibrary.Models.Constants.spCheckIsIntermediateDetailsExist;
            List <SqlParameter> allParams = new List <SqlParameter>()
            {
                new SqlParameter($"@{MIDDerivationLibrary.Models.Constants.xmlInput}", xml)
            };

            DataSet result = sqlRepository.ExecuteQuery(spName, allParams);

            if (result != null && result.Tables[0].Rows.Count > 0)
            {
                details = result.Tables[0].AsEnumerable().Select(dataRow => new IntermediateDetails
                {
                    id               = dataRow.Field <long>("id"),
                    componentType    = dataRow.Field <string>("componentType"),
                    intermediateType = dataRow.Field <string>("intermediateType"),
                    locations        = dataRow.Field <int?>("locations"),
                    drivenBy         = dataRow.Field <string>("drivenBy"),
                    speedChangesMax  = dataRow.Field <int?>("speedChangesMax"),
                    componentCode    = dataRow.Field <decimal?>("componentCode")
                }).FirstOrDefault();
            }
            return(details);
        }
コード例 #3
0
        public IntermediateDetails GetIntermediateDetailsById(long id)
        {
            IntermediateDetails details = null;

            details = _intermediateRepository.GetIntermediateDetailsById(id);
            return(details);
        }
コード例 #4
0
        public bool CheckIsIntermediateDetailsExist(string xmlContent)
        {
            bool flag = false;
            IntermediateDetails details = null;

            details = _intermediateRepository.GetIntermediateDetails(xmlContent);
            if (details != null && details.id > 0)
            {
                flag = true;
            }

            return(flag);
        }
コード例 #5
0
        public bool CheckIsIntermediateDetailsExist(long id)
        {
            bool flag = true;
            IntermediateDetails details = null;

            details = _intermediateRepository.GetIntermediateDetailsById(id);
            if (details != null && details.id == 0)
            {
                flag = false;
            }

            return(flag);
        }
コード例 #6
0
        public ActionResult UpdateIntermediateDetails(IntermediateDetails model)
        {
            long id = 0;
            ModelStateDictionary ModelState = new ModelStateDictionary();

            IntermediateValidationHelper.ValidateIntermediateInput(ref ModelState, ref model);

            if (model.id == 0)
            {
                ModelState.AddModelError(nameof(IntermediateDetails.id), Constants.idValidationMessage);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string   xmlString = XmlHelper.ConvertObjectToXML(model);
                    XElement xElement  = XElement.Parse(xmlString);

                    bool isExist = _service.CheckIsIntermediateDetailsExist(xmlString);

                    if (isExist == true)
                    {
                        return(StatusCode(StatusCodes.Status409Conflict, new ApiResponse(404, Constants.recordExist)));
                    }
                    else
                    {
                        id = _service.AddOrUpdateIntermediateDetails(xElement.ToString());
                        if (id > 0)
                        {
                            return(Ok(new ApiOkResponse(id, Constants.recordSaved)));
                        }
                        else
                        {
                            return(StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse(500, null)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    return(StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse(500, null)));
                }
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse(ModelState)));
            }
        }
コード例 #7
0
        public static void ValidateIntermediateInput(ref ModelStateDictionary modelState, ref IntermediateDetails model)
        {
            if (model != null)
            {
                //componentType
                if (!Enum.IsDefined(typeof(IntermediateComponentType), model.componentType.ToLower()))
                {
                    modelState.AddModelError(nameof(model.componentType), Constants.intermediateComponentTypeValidationMsg);
                }

                //locations
                if (model.locations == null || !(model.locations >= 0 && model.locations <= 4))
                {
                    modelState.AddModelError(nameof(model.locations), Constants.intermediateLocationValidationMsg);
                }

                //intermediateType
                if (string.IsNullOrEmpty(model.intermediateType) || !Enum.IsDefined(typeof(IntermediateType), model.intermediateType.ToLower()))
                {
                    modelState.AddModelError(nameof(model.intermediateType), Constants.intermediateImmediateTypeValidationMsg);
                }

                //gearbox
                if (!string.IsNullOrEmpty(model.intermediateType) && model.intermediateType.ToLower() == IntermediateType.gearbox.ToString())
                {
                    if (model.speedChangesMax == null || !(model.speedChangesMax >= 1 && model.speedChangesMax <= 3))
                    {
                        modelState.AddModelError(nameof(model.speedChangesMax), Constants.intermediateSpeedChangesMaxValidationMsg);
                    }
                }

                //AOP
                if (!string.IsNullOrEmpty(model.intermediateType) && model.intermediateType.ToLower() == IntermediateType.aop.ToString())
                {
                    if (string.IsNullOrEmpty(model.drivenBy) || !Enum.IsDefined(typeof(IntermediateAOPDrivenBy), model.drivenBy.ToLower()))
                    {
                        modelState.AddModelError(nameof(model.drivenBy), Constants.intermediateDrivenByRequiredValidationMsg);
                    }
                }

                //AccDrGr
                if (!string.IsNullOrEmpty(model.intermediateType) && model.intermediateType.ToLower() == IntermediateType.accdrgr.ToString())
                {
                    if (string.IsNullOrEmpty(model.drivenBy) || !Enum.IsDefined(typeof(IntermediateAccDrGrDrivenBy), model.drivenBy.ToLower()))
                    {
                        modelState.AddModelError(nameof(model.drivenBy), Constants.intermediateDrivenByRequiredValidationMsg);
                    }
                }

                //componentCode
                if (model.componentCode == null)
                {
                    modelState.AddModelError(nameof(model.componentCode), Constants.componentCodeRequiredMessage);
                }
            }
        }