public IActionResult GetCommercialsById(int id) { try { /// <summary> /// Metodo para guardar request en logs /// </summary> _securityService.RequestLog("api/bo/commercials/GetCommercialsById: " + JsonConvert.SerializeObject(id)); GetBOCommercialByIdResponseModel businessResult = _boCommercialService.GetCommercialById(id); switch (businessResult.status) { case ResultStatus.SUCCESS: return(Ok(_mapper.Map <BOCommercialDto>(businessResult.Commercial))); case ResultStatus.NOT_FOUND: return(NotFound()); case ResultStatus.ACCESS_DENIED: return(StatusCode(401)); case ResultStatus.NOT_AUTHORIZED: return(StatusCode(403)); default: return(StatusCode(500)); } } catch (Exception e) { return(StatusCode(500, e)); } }
/// <summary> /// <para> /// Busca y devuelve el comercial cuyo campo 'Id' coincide con el id indicado por el parametro <paramref id="intId"/>. /// </para> /// </summary> /// <param id="intId">Identificador del comercial.</param> /// <returns> /// Modelo <see cref="GetBOCommercialByIdResponseModel"/> con los datos de la respuesta. /// </returns> public GetBOCommercialByIdResponseModel GetCommercialById(int id) { GetBOCommercialByIdResponseModel result = new GetBOCommercialByIdResponseModel { status = ResultStatus.SUCCESS }; try { Commercials commercial = _commercialRepository.GetById(id); if (commercial != null) { var alternativeCommercialsDB = new List <AlternativeCommercials>(); var alternativeCommercials = new List <AlternativeCommercialModel>(); Commercials c; Func <AlternativeCommercials, bool> selector = c => c.CommercialId == commercial.Id; alternativeCommercialsDB.AddRange(_alternativeCommercialsRepository.FindAll(selector).Cast <AlternativeCommercials>().ToList()); foreach (AlternativeCommercials alternativeCommercial in alternativeCommercialsDB) { c = _commercialRepository.GetById(alternativeCommercial.AlternativeCommercialId); alternativeCommercials.Add( new AlternativeCommercialModel { Commercial = new CommercialModel { CommercialId = c.Id, CommercialName = String.Format("{0}", c.Name), CommercialEmail = c.Email, Peer = c.Peer, SiebelId = c.SiebelId, PBXPhoneNumber = c.PBXPhoneNumber, MobilePhoneNumber = c.MobilePhoneNumber, Active = c.Active }, Order = alternativeCommercial.Order } ); } result.Commercial = new CommercialModel { CommercialId = commercial.Id, CommercialName = String.Format("{0}", commercial.Name), CommercialEmail = commercial.Email, Peer = commercial.Peer, SiebelId = commercial.SiebelId, PBXPhoneNumber = commercial.PBXPhoneNumber, MobilePhoneNumber = commercial.MobilePhoneNumber, Active = commercial.Active, Alternatives = alternativeCommercials }; } else { result.status = ResultStatus.NOT_FOUND; } return(result); } catch (Exception e) { return(new GetBOCommercialByIdResponseModel { status = ResultStatus.ERROR }); } }