public async Task <string> Post(Want want) { var fb = this.data.GetFacebookInfo(); var facebookClient = new Facebook.FacebookClient(fb.AccessToken); var postParams = new { name = string.Format("In Search Of: {0}", want.Title), caption = string.Format("Can anyone help me find: '{0}'?", want.Title), description = want.Description, link = string.Format("http://www.borentra.com/wanted/{0}", want.Key), picture = want.LargeImage, }; string shareMessage = null; try { await facebookClient.PostTaskAsync("/me/feed", postParams); shareMessage = string.Format("Successfully shared: '{0}'.", want.Title); } catch (Exception ex) { shareMessage = string.Format("Unable to post at this time: '{0}'", ex.Message); } return(shareMessage); }
public async Task DeleteWantAndPushToDbAsync(Want model) { Want want = await _itemFetcherService.GetSpecificWantAsync(model.Id); _db.Wants.Remove(want); await _db.SaveChangesAsync(); }
public async Task <IActionResult> Edit(int id, [Bind("Name,Price")] Want want) { if (id != want.id) { return(NotFound()); } if (ModelState.IsValid) { try { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (want.OwnerId != userId) { return(NoContent()); } _context.Update(want); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WantExists(want.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(want)); }
private async void PublishStory(Want want) { await this.loginButton.RequestNewPermissions("publish_stream"); var shareMessage = await this.facebook.Post(want); var diag = new MessageDialog(shareMessage); await diag.ShowAsync(); }
private void WantCreated(object sender, Want want) { this.flyout.Hide(); var items = this.DefaultViewModel["Items"] as IList <Want>; this.DefaultViewModel["Items"] = null; items.Add(want); this.DefaultViewModel["Items"] = items; }
public async Task EditWantAndPushToDbAsync(EditViewModel model) { Want want = await _itemFetcherService.GetSpecificWantAsync(model.Id); want.Name = model.Name; want.Amount = model.Amount; _db.Wants.Update(want); await _db.SaveChangesAsync(); }
public IHttpActionResult My(string token) { if (auth.IsNotValid(token)) { return(base.StatusCode(System.Net.HttpStatusCode.Unauthorized)); } var callerId = auth.Device.UserIdentifier; var requests = this.wantCore.Search(callerId, callerId); var wants = requests.Select(r => Want.Map(r)); return(this.Ok <IEnumerable <Want> >(wants)); }
public async Task <IActionResult> Create([Bind("Name,Price")] Want want) { if (ModelState.IsValid) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; want.OwnerId = userId; _context.Add(want); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(want)); }
public async Task CreateWantAndPushToDbAsync(AddViewModel model) { Want want = new Want() { Name = model.Name, Amount = model.Amount, User = _user, DateCreated = DateTime.Now }; await _db.Wants.AddAsync(want); await _db.SaveChangesAsync(); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (Have.Count() != Want.Count()) { yield break; } if (Have.All(i => Want.Any(j => j.Id == i.Id)) && Want.All(i => Have.Any(j => j.Id == i.Id))) { yield return(new ValidationResult( "It is not possible to create a trade for the same items.", new[] { "Have", "Want" })); } }
public async Task <EditViewModel> CreateNeededModelForEditWants(int Id) { Want want = await _itemFetcherService.GetSpecificWantAsync(Id); var model = new EditViewModel() { Id = want.Id, Name = want.Name, Amount = want.Amount, PreviousAmount = want.Amount, DateCreated = want.DateCreated }; return(model); }
public IHttpActionResult Save(SecuredWant want) { if (auth.IsNotValid(want)) { return(base.StatusCode(System.Net.HttpStatusCode.Unauthorized)); } if (null == want) { return(this.BadRequest("want")); } if (want.Delete && Guid.Empty == want.Identifier) { return(this.BadRequest("delete must have identifier")); } if (Guid.Empty == want.Identifier) { want.Identifier = Guid.NewGuid(); } if (!string.IsNullOrWhiteSpace(want.ImageUrl)) { try { this.SaveImagebyUrl(this.auth.Device.UserIdentifier, want.Identifier, want.ImageUrl); } catch { } } want.UserIdentifier = auth.Device.UserIdentifier; var itemRequest = this.wantCore.Save(want); if (null != itemRequest) { var result = Want.Map(itemRequest); return(this.Ok <Want>(result)); } else { return(this.Ok()); } }
public IHttpActionResult Get(string key, string token = null) { var authorized = auth.IsNotValid(token); if (string.IsNullOrWhiteSpace(key)) { return(this.BadRequest("key")); } key = key.TrimIfNotNull(); var callerId = authorized ? auth.Device.UserIdentifier : (Guid?)null; var itemRequest = this.wantCore.Get(key, null, callerId); if (null != itemRequest) { var want = Want.Map(itemRequest); return(this.Ok <Want>(want)); } else { return(this.BadRequest("found nothing")); } }
public async Task <IActionResult> DeleteWant(Want model) { if (ModelState.IsValid) { try { await _itemGenerator.DeleteWantAndPushToDbAsync(model); await _userEditor.AddCurrentMoney(model.Amount); await _userEditor.AddBudgetedForWants(model.Amount); await _userEditor.SubtractFromAllTimeSpent(model.Amount); return(RedirectToAction("Index", "Dashboard")); } catch { return(BadRequest()); } } return(BadRequest()); }
public async Task <Want> CreateNeededModelForDeleteWantAsync(int Id) { Want want = await _itemFetcherService.GetSpecificWantAsync(Id); return(want); }
public async Task <Want> GetSpecificWantAsync(int Id) { Want want = await _db.Wants.Where(a => (a.Id == Id) && (a.User == _user)).FirstOrDefaultAsync(); return(want); }