public HttpResponseMessage AddGift(NewSuggestedGift model, [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string accessToken) { return(this.ExecuteOperationAndHandleExceptions(() => { var context = new ApplicationDbContext(); var currentUser = this.GetUserByAccessToken(accessToken, context); var giftFor = context.Users.FirstOrDefault(x => x.Username == model.SuggestedFor); if (giftFor == null) { return this.Request.CreateResponse(HttpStatusCode.BadRequest); } var giftEntity = new Gift { Name = model.Name, Description = model.Description, SuggestedBy = currentUser, SuggestedFor = giftFor, Bought = false, Checked = false, Seen = false }; if (model.Image != null) { giftEntity.Image = model.Image; } if (model.Latitude != null && model.Longitude != null) { giftEntity.Latitude = model.Latitude.Value; giftEntity.Longitude = model.Longitude.Value; } if (model.Url != null) { giftEntity.Url = model.Url; } giftFor.SuggestedGifts.Add(giftEntity); context.SaveChanges(); var responseModel = new GiftCreatedModel() { Id = giftEntity.Id, Name = giftEntity.Name }; var response = this.Request.CreateResponse(HttpStatusCode.Created, responseModel); //response.Headers.Location = new Uri(Url.Link("DefaultApi", new { listId = listEntity.Id })); return response; })); }
public async Task <HttpResponseMessage> AddSuggestedGift(NewSuggestedGift model) { var client = new HttpClient(); client.DefaultRequestHeaders.Add("X-accessToken", accessToken); HttpContent postContent = new StringContent(JsonConvert.SerializeObject(model)); postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync(BaseRootUri + "gifts/suggest-gift", postContent); return(response); }
public Task <HttpResponseMessage> AddSuggestedGift(NewSuggestedGift model) { throw new NotImplementedException(); }