Пример #1
0
        public void Create(Credentials credentials, string token)
        {
            UserData userData = new UserData();
            UserDTO  user     = userData.GetUser(credentials);

            using (var dbctx = new ExpenseTrackerEntities())
            {
                UserToken userToken = dbctx.UserTokens.Where(t => t.UserId == user.UserId).SingleOrDefault();
                if (userToken != null)
                {
                    userToken.Token              = token;
                    userToken.ExpiryDate         = DateTime.Now.AddHours(4);
                    dbctx.Entry(userToken).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    dbctx.UserTokens.Add(new UserToken
                    {
                        UserId     = user.UserId,
                        Token      = token,
                        ExpiryDate = DateTime.Now.AddHours(4)
                    });
                }
                dbctx.SaveChanges();
            }
        }
Пример #2
0
 public void Create(TransactionDTO transaction)
 {
     using (var dbctx = new ExpenseTrackerEntities())
     {
         var tran = new Transaction
         {
             TransactionAmount = transaction.TransactionAmount,
             TransactionDate   = transaction.TransactionDate,
             TransactionNote   = transaction.TransactionNote,
             CategoryId        = transaction.CategoryId,
             UserId            = transaction.UserId
         };
         if (transaction.TransactionReceipts != null && transaction.TransactionReceipts.Any())
         {
             transaction.TransactionReceipts.ToList().ForEach(t =>
             {
                 tran.TransactionReceipts.Add(new TransactionReceipt
                 {
                     ReceiptImage = t.ReceiptImage,
                     ContentType  = t.ContentType
                 });
             });
         }
         dbctx.Transactions.Add(tran);
         dbctx.SaveChanges();
     }
 }
Пример #3
0
 public void CreateCategory(string name)
 {
     using (var dbctx = new ExpenseTrackerEntities())
     {
         dbctx.TransactionCategories.Add(new TransactionCategory
         {
             CategoryName = name
         });
         dbctx.SaveChanges();
     }
 }
Пример #4
0
 public void DeleteTransaction(int transactionId)
 {
     using (var dbctx = new ExpenseTrackerEntities())
     {
         Transaction transaction = dbctx.Transactions
                                   .Where(t => t.TransactionId == transactionId)
                                   .Include(t => t.TransactionReceipts)
                                   .Single();
         dbctx.TransactionReceipts.RemoveRange(transaction.TransactionReceipts);
         dbctx.Transactions.Remove(transaction);
         dbctx.SaveChanges();
     }
 }
 public void Create(UserDTO user)
 {
     using (var dbctx = new ExpenseTrackerEntities())
     {
         dbctx.Users.Add(new User
         {
             FirstName = user.FirstName,
             LastName  = user.LastName,
             Email     = user.Email,
             Password  = user.Password,
             UserName  = user.UserName
         });
         dbctx.SaveChanges();
     }
 }