コード例 #1
0
 public IHttpActionResult Donate(int id, [FromUri] string username)
 {
     if (db.Donations.Where(d => d.DonorId == username && d.NeedId == id).Count() != 0)
     {
         try
         {
             Donation donation = db.Donations.Where(d => d.DonorId == username && d.NeedId == id).Single();
             donation.Amount         += 1;
             db.Entry(donation).State = EntityState.Modified;
             db.SaveChanges();
         }
         catch
         {
             return(BadRequest());
         }
     }
     else
     {
         try
         {
             db.Donations.Add(new Donation {
                 Amount = 1, DonorId = username, NeedId = id
             });
             db.SaveChanges();
         }
         catch
         {
             return(BadRequest());
         }
     }
     return(Ok());
 }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "Id,Name,Rank,Units,Display,FoodBankId")] Need need)
 {
     if (ModelState.IsValid)
     {
         db.Entry(need).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(need));
 }