public async Task <IHttpActionResult> PostShareInterest([FromBody] InterestedShareInModel entity) { try { string authorization = Request.Headers.Authorization.Parameter; string scheme = Request.Headers.Authorization.Scheme; string user = ""; InterestedShareModel pref = new InterestedShareModel(entity); pref.UserId = await RetreiveUserId(); using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, "Share?symbol=" + entity.ShareSymbol)) { requestMessage.Headers.Authorization = new AuthenticationHeaderValue(scheme, authorization); HttpResponseMessage response = await _client.SendAsync(requestMessage); if (response.IsSuccessStatusCode) { string id = await response.Content.ReadAsStringAsync(); pref.ShareId = Convert.ToInt32(id); } //get shareid using the symbol _service.Add(pref); } return(Ok()); } catch (Exception e) { return(Content(HttpStatusCode.InternalServerError, "error: " + e.Message)); } }
public bool Add(InterestedShareModel entity) { try { db.InterestedShares.Add(entity); db.SaveChanges(); return(true); } catch (Exception e) { throw new Exception("error in adding new interested share: " + e.Message); } }