コード例 #1
0
        public string getBalance([FromUri] string userID)
        {
            var context     = new WingsCarrotDBContext();
            var balanceUser = context.Users.Select(u => new { u.Id, u.BalancePW }).Where(u => u.Id.Contains(userID)).ToList();

            return(balanceUser[0].BalancePW.ToString());
        }
コード例 #2
0
 public string addTransaction([FromBody] Transaction userTransaction)
 {
     using (var context = new WingsCarrotDBContext())
     {
         using (var dbContextTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 ApplicationUser tempUserFromBalance = context.Users.SingleOrDefault(u => u.Id == userTransaction.UserFromId);
                 tempUserFromBalance.BalancePW = tempUserFromBalance.BalancePW - Convert.ToInt32(userTransaction.SumPw);
                 ApplicationUser tempUserToBalance = context.Users.SingleOrDefault(u => u.Id == userTransaction.UserToId);
                 tempUserToBalance.BalancePW = tempUserToBalance.BalancePW + Convert.ToInt32(userTransaction.SumPw);
                 context.SaveChanges();
                 userTransaction.ResultPw = tempUserFromBalance.BalancePW.ToString();
                 context.Transactions.Add(userTransaction);
                 context.SaveChanges();
                 var tempId = userTransaction.UserToId;
                 userTransaction.UserToId      = userTransaction.UserFromId;
                 userTransaction.UserFromId    = tempId;
                 userTransaction.TypeOperation = "DEBIT";
                 userTransaction.ResultPw      = tempUserToBalance.BalancePW.ToString();
                 context.Transactions.Add(userTransaction);
                 context.SaveChanges();
                 dbContextTransaction.Commit();
                 return(tempUserFromBalance.BalancePW.ToString());
             }
             catch (Exception e)
             {
                 dbContextTransaction.Rollback();
                 return(e.ToString());
             }
         }
     }
 }
コード例 #3
0
        public List <ApplicationUser> getUsers([FromUri] string userID)
        {
            var context  = new WingsCarrotDBContext();
            var allUsers = context.Users.Select(u => u).Where(u => !u.Id.Contains(userID)).ToList();

            return(allUsers);
        }
コード例 #4
0
        public IQueryable getTransactions([FromUri] string userID)
        {
            var context      = new WingsCarrotDBContext();
            var Transactions = from tr in context.Transactions
                               join u in context.Users on tr.UserToId equals u.Id
                               where tr.UserFromId.Contains(userID)
                               orderby tr.TransactionTime descending
                               select new
            {
                tr.TransactionId,
                tr.UserFromId,
                tr.TypeOperation,
                UserToId = u.Name,
                tr.SumPw,
                tr.ResultPw,
                tr.TransactionTime
            };

            return(Transactions);
        }