Пример #1
0
        public Coupling1Details GetCoupling1DetailsById(long id)
        {
            Coupling1Details details = null;

            details = _coupling1Repository.GetCoupling1DetailsById(id);
            return(details);
        }
Пример #2
0
        public ActionResult GetDriverDetailsById(long id)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest(new ApiBadRequestResponse()));
                }
                else
                {
                    bool isExist = _service.CheckIsCoupling1DetailsExist(id);
                    if (isExist == false)
                    {
                        return(StatusCode(StatusCodes.Status404NotFound, new ApiResponse(404, Constants.recordNotFound)));
                    }

                    Coupling1Details details = _service.GetCoupling1DetailsById(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)));
            }
        }
Пример #3
0
        public Coupling1Details GetCoupling1DetailsById(long id)
        {
            Coupling1Details    details   = new Coupling1Details();
            string              spName    = MIDDerivationLibrary.Models.Constants.spGetCoupling1DetailsById;
            List <SqlParameter> allParams = new List <SqlParameter>()
            {
                new SqlParameter($"@{MIDDerivationLibrary.Models.Constants.Id}", id)
            };

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

            if (result != null && result.Tables[0].Rows.Count > 0)
            {
                details = result.Tables[0].AsEnumerable().Select(dataRow => new Coupling1Details
                {
                    id                    = dataRow.Field <long>("id"),
                    componentType         = dataRow.Field <string>("componentType"),
                    couplingPosition      = dataRow.Field <int?>("couplingPosition"),
                    couplingType          = dataRow.Field <string>("couplingType"),
                    locations             = dataRow.Field <int?>("locations"),
                    coupledComponentType1 = dataRow.Field <string>("coupledComponentType1"),
                    coupledComponentType2 = dataRow.Field <string>("coupledComponentType2"),
                    componentCode         = dataRow.Field <decimal?>("componentCode")
                }).FirstOrDefault();
            }
            return(details);
        }
Пример #4
0
        public bool CheckIsCoupling1DetailsExist(long id)
        {
            bool             flag    = true;
            Coupling1Details details = null;

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

            return(flag);
        }
Пример #5
0
        public bool CheckIsCoupling1DetailsExist(string xmlContent)
        {
            bool             flag    = false;
            Coupling1Details details = null;

            details = _coupling1Repository.GetCoupling1Details(xmlContent);

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

            return(flag);
        }
Пример #6
0
        public ActionResult UpdateCoupling1Details(Coupling1Details model)
        {
            long id = 0;
            ModelStateDictionary ModelState = new ModelStateDictionary();

            CouplingValidationHelper.ValidateCoupling1Input(ref ModelState, ref model);

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

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

                    bool isExist = _service.CheckIsCoupling1DetailsExist(xmlString);

                    if (isExist == true)
                    {
                        return(StatusCode(StatusCodes.Status409Conflict, new ApiResponse(404, Constants.recordExist)));
                    }
                    else
                    {
                        id = _service.AddOrUpdateCoupling1Details(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)));
            }
        }
        public static void ValidateCoupling1Input(ref ModelStateDictionary modelState, ref Coupling1Details model)
        {
            //Validations for coupling1 component
            if (model != null)
            {
                //componentType
                if (string.IsNullOrEmpty(model.componentType) || !Enum.IsDefined(typeof(Coupling1ComponentType), model.componentType.ToLower()))
                {
                    modelState.AddModelError(nameof(Coupling1Details.componentType), Constants.coupling1ComponentTypeValidationMsg);
                }

                //couplingPosition
                if (model.couplingPosition == null || !Enum.IsDefined(typeof(Coupling1CouplingPosition), model.couplingPosition))
                {
                    modelState.AddModelError(nameof(Coupling1Details.couplingPosition), Constants.coupling1PositionTypeRequiredMessage);
                }

                //couplingType
                if (model.couplingType == null || !Enum.IsDefined(typeof(Coupling1CouplingType), model.couplingType))
                {
                    modelState.AddModelError(nameof(Coupling1Details.couplingType), Constants.coupling1CouplingTypeRequiredMessage);
                }

                //location
                if (model.locations != null && !(model.locations >= 1 && model.locations <= 10))
                {
                    modelState.AddModelError(nameof(Coupling1Details.locations), Constants.coupling1LocationValidationMessage);
                }

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