コード例 #1
0
        public Transaction Add(Transaction item)
        {
            if (item == null)
              {
            throw new ArgumentNullException("item");
              }

              item.TransactionId = _nextId++;
              transactions.Add(item);
              return item;
        }
コード例 #2
0
 public bool Update(Transaction item)
 {
     if (item == null)
       {
     throw new ArgumentNullException("item");
       }
       int index = transactions.FindIndex(p => p.TransactionId == item.TransactionId);
       if (index == -1)
       {
     return false;
       }
       transactions.RemoveAt(index);
       transactions.Add(item);
       return true;
 }
コード例 #3
0
 public ActionResult Edit(Transaction transaction)
 {
     TransactionsController tc = new TransactionsController(db);
       var result = tc.PutTransaction(transaction.TransactionId, transaction) as OkNegotiatedContentResult<Transaction>;
       return RedirectToAction("Index");
 }
コード例 #4
0
 public void MarkAsModified(Transaction item)
 {
     Entry(item).State = EntityState.Modified;
 }
コード例 #5
0
 public void MarkAsModified(Transaction item)
 {
 }
コード例 #6
0
        /// <summary>
        /// Posts a single transaction
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public IHttpActionResult PostTransaction(Transaction item)
        {
            if (!ModelState.IsValid)
              {
            return BadRequest(ModelState);
              }

              item = db.Transactions.Add(item);
              db.SaveChanges();

              return CreatedAtRoute("DefaultApi", new { id = item.TransactionId }, item);
        }
コード例 #7
0
        /// <summary>
        /// Puts a single transaction
        /// </summary>
        /// <param name="id"></param>
        /// <param name="transaction"></param>
        public IHttpActionResult PutTransaction(long id, Transaction transaction)
        {
            if (!ModelState.IsValid)
              {
            return BadRequest(ModelState);
              }

              transaction.TransactionId = id;
              if (transaction == null)
              {
            return BadRequest("Transaction not found");
              }

              try
              {
            //db.Entry(transaction).State = EntityState.Modified;
            db.MarkAsModified(transaction);
            db.SaveChanges();
              }
              catch
              {
            return BadRequest(ModelState);
              }

              return Ok();
        }
コード例 #8
0
        private List<Transaction> getTransactions(string userId, int year)
        {
            List<Transaction> list = new List<Transaction>();
            Transaction item1 = new Transaction();
            item1.UserId = "";
            item1.Name = "Purchase";
            item1.Product = "Gold 150";
            item1.Amount = "3 grams";
            item1.Price = "£49.50";
            item1.Value = "£148.50";
            item1.Balance = "£1.50";
            item1.Date = "22-09-2015";
            list.Add(item1);

            Transaction item2 = new Transaction();
            item2.UserId = "";
            item2.Name = "Purchase";
            item2.Product = "Gold 150";
            item2.Amount = "2 grams";
            item2.Price = "£51.01";
            item2.Value = "£102.02";
            item2.Balance = "£49.48";
            item2.Date = "22-10-2015";
            list.Add(item2);

            Transaction item3 = new Transaction();
            item3.UserId = "";
            item3.Name = "Purchase";
            item3.Product = "Gold 150";
            item3.Amount = "3 grams";
            item3.Price = "£51.02";
            item3.Value = "£153.06";
            item3.Balance = "£46.42";
            item3.Date = "22-11-2015";
            list.Add(item3);

            return list;
        }