public bool CategoryExists(string name) { using (var dbctx = new ExpenseTrackerEntities()) { return(dbctx.TransactionCategories.Where(x => x.CategoryName == name).Any()); } }
public List <TransactionCategoryDTO> GetTransactionCategories() { using (var dbctx = new ExpenseTrackerEntities()) { return(Mapper.Map <List <TransactionCategoryDTO> >(dbctx.TransactionCategories.ToList())); } }
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(); } }
public List <TransactionDTO> GetTransactions(TransactionSearchCriteriaDTO searchCriteria) { List <TransactionDTO> trans; using (var dbctx = new ExpenseTrackerEntities()) { dbctx.Configuration.ProxyCreationEnabled = false; trans = dbctx.Transactions .Where(t => t.TransactionDate >= searchCriteria.StartDate.Date && t.TransactionDate <= searchCriteria.EndDate) .Include(t => t.TransactionCategory) .OrderBy(t => t.TransactionDate) .Select(t => new TransactionDTO { TransactionId = t.TransactionId, TransactionAmount = t.TransactionAmount, TransactionDate = t.TransactionDate, TransactionNote = t.TransactionNote, TransactionCategory = new TransactionCategoryDTO { CategoryName = t.TransactionCategory.CategoryName }, HasReceipts = t.TransactionReceipts.Any() }) .ToList(); } return(trans); }
public bool EmailExists(string email) { using (var dbctx = new ExpenseTrackerEntities()) { return(!dbctx.Users.Where(user => user.Email == email).Any()); } }
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(); } }
public bool UserNameExists(string username) { using (var dbctx = new ExpenseTrackerEntities()) { return(!dbctx.Users.Where(user => user.UserName == username).Any()); } }
public List <TransactionReceiptDTO> GetTransactionReceipts(int transactionId) { using (var dbctx = new ExpenseTrackerEntities()) { return(Mapper.Map <List <TransactionReceiptDTO> >(dbctx. TransactionReceipts.Where(r => r.TransactionId == transactionId))); } }
public bool IsValid(Credentials credentials) { using (var dbctx = new ExpenseTrackerEntities()) { return(dbctx.Users .Where(user => user.UserName == credentials.UserName && user.Password == credentials.Password) .Count() == 1); } }
public UserToken GetToken(string token) { using (var dbctx = new ExpenseTrackerEntities()) { return(dbctx.UserTokens .Where(userToken => userToken.Token == token && userToken.ExpiryDate > DateTime.Now) .SingleOrDefault()); } }
public bool IsValid(string token) { using (var dbctx = new ExpenseTrackerEntities()) { return(dbctx.UserTokens .Where(userToken => userToken.Token == token && userToken.ExpiryDate > DateTime.Now) .Count() == 1); } }
public void CreateCategory(string name) { using (var dbctx = new ExpenseTrackerEntities()) { dbctx.TransactionCategories.Add(new TransactionCategory { CategoryName = name }); dbctx.SaveChanges(); } }
public UserDTO GetUser(string token) { User userData; using (var dbctx = new ExpenseTrackerEntities()) { userData = dbctx.Users .Where(user => user.UserToken.Token == token && user.UserToken.ExpiryDate > DateTime.Now) .SingleOrDefault(); } return(Mapper.Map <UserDTO>(userData)); }
public UserDTO GetUser(Credentials credentials) { User userData; using (var dbctx = new ExpenseTrackerEntities()) { userData = dbctx.Users .Where(user => user.UserName == credentials.UserName && user.Password == credentials.Password) .Include(x => x.UserToken) .SingleOrDefault(); } return(Mapper.Map <UserDTO>(userData)); }
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(); } }
public TransactionDTO GetTransaction(int transactionId) { using (var dbctx = new ExpenseTrackerEntities()) { return(dbctx.Transactions .Where(t => t.TransactionId == transactionId) .Select(t => new TransactionDTO { TransactionId = t.TransactionId, TransactionAmount = t.TransactionAmount, TransactionDate = t.TransactionDate, TransactionNote = t.TransactionNote, TransactionCategory = new TransactionCategoryDTO { CategoryId = t.TransactionCategory.CategoryId, CategoryName = t.TransactionCategory.CategoryName } }) .SingleOrDefault()); } }