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());
 }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "Id,Name,Rank,Units,Display,FoodBankId")] Need need)
        {
            need.FoodBankId = int.Parse(Session["foodbankId"].ToString());
            if (ModelState.IsValid)
            {
                db.Needs.Add(need);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(need));
        }