public Coupling2Details GetCoupling2DetailsById(long id) { Coupling2Details details = null; details = _coupling2Repository.GetCoupling2DetailsById(id); return(details); }
public Coupling2Details GetCoupling2DetailsById(long id) { Coupling2Details details = new Coupling2Details(); string spName = MIDDerivationLibrary.Models.Constants.spGetCoupling2DetailsById; 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 Coupling2Details { 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); }
public ActionResult GetDriverDetailsById(long id) { try { if (id <= 0) { return(BadRequest(new ApiBadRequestResponse())); } else { bool isExist = _service.CheckIsCoupling2DetailsExist(id); if (isExist == false) { return(StatusCode(StatusCodes.Status404NotFound, new ApiResponse(404, Constants.recordNotFound))); } Coupling2Details details = _service.GetCoupling2DetailsById(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))); } }
public bool CheckIsCoupling2DetailsExist(string xmlContent) { bool flag = false; Coupling2Details details = null; details = _coupling2Repository.GetCoupling2Details(xmlContent); if (details != null && details.id > 0) { flag = true; } return(flag); }
public bool CheckIsCoupling2DetailsExist(long id) { bool flag = true; Coupling2Details details = null; details = _coupling2Repository.GetCoupling2DetailsById(id); if (details != null && details.id == 0) { flag = false; } return(flag); }
public ActionResult UpdateCoupling2Details(Coupling2Details model) { long id = 0; ModelStateDictionary ModelState = new ModelStateDictionary(); CouplingValidationHelper.ValidateCoupling2Input(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.CheckIsCoupling2DetailsExist(xmlString); if (isExist == true) { return(StatusCode(StatusCodes.Status409Conflict, new ApiResponse(404, Constants.recordExist))); } else { id = _service.AddOrUpdateCoupling2Details(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 ValidateCoupling2Input(ref ModelStateDictionary modelState, ref Coupling2Details model) { //Validations for Coupling2 component if (model != null) { //componentType if (string.IsNullOrEmpty(model.componentType) || !Enum.IsDefined(typeof(Coupling2ComponentType), model.componentType.ToLower())) { modelState.AddModelError(nameof(Coupling2Details.componentType), Constants.coupling2ComponentTypeRequiredMsg); } //couplingPosition if (model.couplingPosition == null || !Enum.IsDefined(typeof(Coupling2CouplingPosition), model.couplingPosition)) { modelState.AddModelError(nameof(Coupling2Details.couplingPosition), Constants.coupling2PositionTypeRequiredMessage); } //couplingType if (model.couplingType == null || !Enum.IsDefined(typeof(Coupling2CouplingType), model.couplingType)) { modelState.AddModelError(nameof(Coupling2Details.couplingType), Constants.coupling2CouplingTypeRequiredMessage); } //location if (model.locations != null && !(model.locations >= 1 && model.locations <= 10)) { modelState.AddModelError(nameof(Coupling2Details.locations), Constants.coupling2LocationValidationMessage); } //componentCode if (model.componentCode == null) { modelState.AddModelError(nameof(model.componentCode), Constants.componentCodeRequiredMessage); } } }