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 <IHttpActionResult> GetPersonalDetails(int id) { PersonalDetails personaldetails = await db.PersonalDetails.FindAsync(id); if (personaldetails == null) { ModelState.AddModelError("Message", "Personal details not found!"); return(BadRequest(ModelState)); } try { PersonalDetailsDTO pddto = new PersonalDetailsDTO(); pddto.id = personaldetails.id; pddto.firstName = personaldetails.firstName; pddto.middleName = personaldetails.middleName; pddto.lastName = personaldetails.lastName; pddto.dateOfBirth = personaldetails.dateOfBirth; pddto.traderId = personaldetails.traderId; return(Ok(pddto)); } catch (Exception exc) { string mess = exc.Message; ModelState.AddModelError("Message", "An unexpected error has occured during getting the personal details!"); return(BadRequest(ModelState)); } }
public IHttpActionResult GetPersonalDetailsByTraderId(string traderId) { if (!IsValidGUID(traderId)) { ModelState.AddModelError("Message", "The user does not exist in the system!"); return(BadRequest(ModelState)); } try { var personaldetails = db.PersonalDetails.FirstOrDefault(pd => pd.traderId == traderId); if (personaldetails != null) { PersonalDetailsDTO pddto = new PersonalDetailsDTO(); pddto.id = personaldetails.id; pddto.firstName = personaldetails.firstName; pddto.middleName = personaldetails.middleName; pddto.lastName = personaldetails.lastName; pddto.dateOfBirth = personaldetails.dateOfBirth; pddto.traderId = personaldetails.traderId; return(Ok <PersonalDetailsDTO>(pddto)); } return(Ok <PersonalDetailsDTO>(new PersonalDetailsDTO())); } catch (Exception exc) { string error = exc.InnerException.Message; ModelState.AddModelError("Message", "An unexpected error occured during getting all personal details!"); return(BadRequest(ModelState)); } }
// GET: api/personaldetails public IHttpActionResult GetPersonalDetails() { try { List <PersonalDetailsDTO> dtoList = new List <PersonalDetailsDTO>(); foreach (PersonalDetails personaldetails in db.PersonalDetails) { PersonalDetailsDTO pddto = new PersonalDetailsDTO(); pddto.id = personaldetails.id; pddto.firstName = personaldetails.firstName; pddto.middleName = personaldetails.middleName; pddto.lastName = personaldetails.lastName; pddto.dateOfBirth = personaldetails.dateOfBirth; pddto.traderId = personaldetails.traderId; dtoList.Add(pddto); } return(Ok <List <PersonalDetailsDTO> >(dtoList)); } catch (Exception exc) { string mess = exc.Message; ModelState.AddModelError("Message", "An unexpected error has occured during getting all personal details!"); return(BadRequest(ModelState)); } }
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)); }