public IHttpActionResult GetCorrespondencesByTradeId(int tradeId) { try { List <CorrespondenceDTO> dtoList = new List <CorrespondenceDTO>(); foreach (Correspondence corres in db.Correspondences.Where(corr => corr.tradeId == tradeId).OrderByDescending(corr => corr.dateSent)) { PersonalDetailsDTO personalDetailsSender = ((OkNegotiatedContentResult <PersonalDetailsDTO>)pdctr.GetPersonalDetailsByTraderId(corres.traderIdSender)).Content; PersonalDetailsDTO personalDetailsReciever = ((OkNegotiatedContentResult <PersonalDetailsDTO>)pdctr.GetPersonalDetailsByTraderId(corres.traderIdReceiver)).Content; CorrespondenceDTO mesdto = new CorrespondenceDTO(); mesdto.id = corres.id; mesdto.subject = db.Trades.First(tro => tro.tradeId == corres.tradeId).name; mesdto.message = corres.message; mesdto.content = corres.content; mesdto.statusSender = corres.statusSender; mesdto.statusReceiver = corres.statusReceiver; mesdto.dateSent = corres.dateSent; mesdto.tradeId = corres.tradeId; mesdto.traderIdSender = corres.traderIdSender; mesdto.traderIdReceiver = corres.traderIdReceiver; mesdto.sender = personalDetailsSender.firstName + " " + personalDetailsSender.middleName + " " + personalDetailsSender.lastName; mesdto.receiver = personalDetailsReciever.firstName + " " + personalDetailsReciever.middleName + " " + personalDetailsReciever.lastName; dtoList.Add(mesdto); } return(Ok <List <CorrespondenceDTO> >(dtoList)); } catch (Exception exc) { string mess = exc.Message; ModelState.AddModelError("Message", "An unexpected error has occured during getting correspondence by tradeId!"); return(BadRequest(ModelState)); } }
public async Task <IHttpActionResult> GetCorrespondence(int id) { Correspondence corres = await db.Correspondences.FindAsync(id); if (corres == null) { ModelState.AddModelError("Message", "Correspondence not found!"); return(BadRequest(ModelState)); } PersonalDetailsDTO personalDetailsSender = ((OkNegotiatedContentResult <PersonalDetailsDTO>)pdctr.GetPersonalDetailsByTraderId(corres.traderIdSender)).Content; PersonalDetailsDTO personalDetailsReciever = ((OkNegotiatedContentResult <PersonalDetailsDTO>)pdctr.GetPersonalDetailsByTraderId(corres.traderIdReceiver)).Content; CorrespondenceDTO mesdto = new CorrespondenceDTO(); mesdto.id = corres.id; mesdto.subject = db.Trades.First(tro => tro.tradeId == corres.tradeId).name; mesdto.message = corres.message; mesdto.content = corres.content; mesdto.statusSender = corres.statusSender; mesdto.statusReceiver = corres.statusReceiver; mesdto.dateSent = corres.dateSent; mesdto.tradeId = corres.tradeId; mesdto.traderIdSender = corres.traderIdSender; mesdto.traderIdReceiver = corres.traderIdReceiver; mesdto.sender = personalDetailsSender.firstName + " " + personalDetailsSender.middleName + " " + personalDetailsSender.lastName; mesdto.receiver = personalDetailsReciever.firstName + " " + personalDetailsReciever.middleName + " " + personalDetailsReciever.lastName; return(Ok(mesdto)); }
public async Task <Response <string> > UpdateAsync(CorrespondenceDTO model) { var response = new Response <string>(); try { var resp = _mapper.Map <Correspondence>(model); response.Data = await _CorrespondencesDomain.UpdateAsync(resp); if (response.Data == "Success") { response.IsSuccess = true; response.Message = "Se ha actualizado el Correspondencia exitosamente."; } else { response.IsSuccess = false; response.Message = "Ha ocurrido un error inesperado, por favor intente nuevamente"; _logger.LogWarning("Ha ocurrido un error inesperado, por favor intente nuevamente " + response.Data); } } catch (Exception ex) { response.IsSuccess = false; response.Message = ex.Message; _logger.LogError(ex.Message); } return(response); }
public async Task <IActionResult> UpdateAsync(CorrespondenceDTO model) { Response <string> response = new Response <string>(); try { #region Validaciones var validResult = _messageValidator.Validate(model); if (!validResult.IsValid) { response.Data = string.Empty; foreach (var error in validResult.Errors) { response.Data = error.ToString() + "|" + response.Data; } response.Data = response.Data.Substring(0, response.Data.Length - 1); response.IsSuccess = false; return(BadRequest(response)); } #endregion if (model == null) { return(BadRequest()); } response = await _CorrespondenceApplication.UpdateAsync(model); if (response.IsSuccess) { return(Ok(response)); } else { return(BadRequest(response)); } } catch (Exception ex) { response.Data = null; response.IsSuccess = false; response.Message = ex.Message; return(BadRequest(response)); } }
public async Task <IHttpActionResult> GetCorrespondenceByTradeIdAndId(string loggedOnTrader, int id) { Correspondence corres = await db.Correspondences.FindAsync(id); if (corres == null) { ModelState.AddModelError("Message", "Correspondence not found!"); return(BadRequest(ModelState)); } PersonalDetailsDTO personalDetailsSender = ((OkNegotiatedContentResult <PersonalDetailsDTO>)pdctr.GetPersonalDetailsByTraderId(corres.traderIdSender)).Content; PersonalDetailsDTO personalDetailsReciever = ((OkNegotiatedContentResult <PersonalDetailsDTO>)pdctr.GetPersonalDetailsByTraderId(corres.traderIdReceiver)).Content; // TODO do this if the status is not already read!!!! if (loggedOnTrader == corres.traderIdSender) { corres.statusSender = "Sent"; } else if (corres.statusReceiver == "New") { corres.statusReceiver = "Read"; } db.SaveChanges(); CorrespondenceDTO mesdto = new CorrespondenceDTO(); mesdto.id = corres.id; mesdto.subject = db.Trades.First(tro => tro.tradeId == corres.tradeId).name; mesdto.message = corres.message; mesdto.content = corres.content; mesdto.statusSender = corres.statusSender; mesdto.statusReceiver = corres.statusReceiver; mesdto.dateSent = corres.dateSent; mesdto.tradeId = corres.tradeId; mesdto.traderIdSender = corres.traderIdSender; mesdto.traderIdReceiver = corres.traderIdReceiver; mesdto.sender = personalDetailsSender.firstName + " " + personalDetailsSender.middleName + " " + personalDetailsSender.lastName; mesdto.receiver = personalDetailsReciever.firstName + " " + personalDetailsReciever.middleName + " " + personalDetailsReciever.lastName; return(Ok(mesdto)); }