public async Task <IHttpActionResult> PutBoughtSouvenirs(int id, BoughtSouvenirs boughtSouvenirs) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != boughtSouvenirs.Id) { return(BadRequest()); } db.Entry(boughtSouvenirs).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BoughtSouvenirsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult RemoveSouvenirFromBucket(int id) { BoughtSouvenirs souvenir = (from c in db.BoughtSouvenirs where c.SouvenirId == id select c).FirstOrDefault(); db.BoughtSouvenirs.Remove(souvenir); db.SaveChanges(); int souvenirsInBucket = (from c in db.BoughtSouvenirs where c.InBucket == true select c).Count(); return(Ok(souvenirsInBucket)); }
public async Task <IHttpActionResult> GetBoughtSouvenirs(int id) { BoughtSouvenirs boughtSouvenirs = await db.BoughtSouvenirs.FindAsync(id); if (boughtSouvenirs == null) { return(NotFound()); } return(Ok(boughtSouvenirs)); }
public async Task <IHttpActionResult> PostBoughtSouvenirs(BoughtSouvenirsView souvenir) { BoughtSouvenirs boughtSouvenir = db.BoughtSouvenirs.Where(c => c.Id == souvenir.Id && c.UserName == souvenir.Name).FirstOrDefault(); boughtSouvenir.InBucket = false; boughtSouvenir.UserAddress = souvenir.Address; boughtSouvenir.Souvenir.NumSamples--; await db.SaveChangesAsync(); return(Ok()); }
public IHttpActionResult AddToBucket(BoughtSouvenirs souvenir) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.BoughtSouvenirs.Add(souvenir); db.SaveChanges(); int souvenirsInBucket = (from c in db.BoughtSouvenirs where c.InBucket == true select c).Count(); return(Ok(souvenirsInBucket)); }
public async Task <IHttpActionResult> DeleteBoughtSouvenirs(int id) { BoughtSouvenirs boughtSouvenirs = await db.BoughtSouvenirs.FindAsync(id); if (boughtSouvenirs == null) { return(NotFound()); } db.BoughtSouvenirs.Remove(boughtSouvenirs); await db.SaveChangesAsync(); return(Ok(boughtSouvenirs)); }