public async Task<IHttpActionResult> PutPurchase(int id, Purchase purchase)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != purchase.Id)
            {
                return BadRequest();
            }

            db.Entry(purchase).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PurchaseExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public async Task<IHttpActionResult> PostPurchase(Purchase purchase)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Purchases.Add(purchase);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = purchase.Id }, purchase);
        }
Example #3
0
        public ActionResult Purchase(int id)
        {
            if (cart.id != id)
            {
                // this should never occur
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            //create the purchase object
            Purchase purchase = new Purchase();
            purchase.createdOn = DateTime.Now;
            //purchase.items = new List<KeyValuePair<Product, int>>();
            purchase.items = cart.items.ToList(); // creates a elementwise copy of the list
            purchase.totalPrice = cart.totalAmount;
            purchase.userId = cart.userId;
            //purchase.id = TODO;  FIXME

            //add it to the purchases list
            purchases.Add(purchase);

            //clear the cart object
            cart.items.Clear();
            this.CalculateTotalAmount();

            return View("PurchaseCompleted", purchase);
        }
Example #4
0
 public ActionResult PurchaseDetails(Purchase purchase)
 {
     return View("PurchaseCompleted", purchase);
 }