public String insertWallet(String name, int money) { using (var context = new QLTCDbEntities()) { var k = (from a in context.Wallets select a.ID).ToList(); int id = k.Count(); id++; var checkName = (from a in context.Wallets where a.Name.Equals(name) select a).ToList(); if (checkName.Count() > 0) { return("1"); } else { Wallet wallet = new Wallet() { ID = id, Name = name, FirstMoney = money, Money = money }; context.Wallets.Add(wallet); context.Entry(wallet).State = EntityState.Added; context.SaveChanges(); return("0"); } } }
public List <String> getAllAction() { using (var context = new QLTCDbEntities()) { var result = (from a in context.ActionNames select a.ActionName1).ToList(); return(result); } }
public List <String> getWalletName() { using (var context = new QLTCDbEntities()) { var result = (from a in context.Wallets select a.Name).ToList(); return(result); } }
public List <WalletShowModel> getAllWallet() { using (var context = new QLTCDbEntities()) { var result = (from a in context.Wallets select new WalletShowModel() { ID = a.ID, Name = a.Name }).ToList(); return(result); } }
public int SumMoney() { using (var context = new QLTCDbEntities()) { var ls = (from a in context.Wallets select a.Money).ToList <int>(); int result = 0; for (int i = 0; i < ls.Count(); i++) { result += ls[i]; } return(result); } }
public String checkValidate(String name) { using (var context = new QLTCDbEntities()) { var check = (from a in context.ActionNames where a.ActionName1.Equals(name) select a).ToList(); if (check.Count() > 0) { return("Tên hoạt động đã tồn tại"); } else { return("Success"); } } }
public void AddAction(String name) { using (var context = new QLTCDbEntities()) { var i = (from a in context.ActionNames select a).ToList(); int id = i.Count(); id++; ActionName action = new ActionName() { ID = id, ActionName1 = name }; context.ActionNames.Add(action); context.Entry(action).State = EntityState.Added; context.SaveChanges(); } }
public List <ActionViewModel> GetAll() { using (var context = new QLTCDbEntities()) { var result = (from w in context.Wallets from a in context.ActionNames from m in context.MemoryActions where a.ID.Equals(m.ID_action) && w.ID.Equals(m.ID_wallet) select new ActionViewModel() { NameWallet = w.Name, NameAction = a.ActionName1, Money = m.Money, DateUse = m.DateUse }).ToList(); return(result); } }
public String AddNewHistory(String action, String wallet, int money, DateTime dateUse) { using (var context = new QLTCDbEntities()) if (checkValidate(money).Equals("Success")) { int i_action = (from a in context.ActionNames where a.ActionName1.Equals(action) select a.ID).FirstOrDefault(); int i_wallet = (from a in context.Wallets where a.Name.Equals(wallet) select a.ID).FirstOrDefault(); var i = (from a in context.MemoryActions select a.ID).ToList(); int id = i.Count(); MemoryAction m = new MemoryAction() { ID = id, ID_action = i_action, ID_wallet = i_wallet, Money = money, DateUse = dateUse }; context.MemoryActions.Add(m); context.Entry(m).State = EntityState.Added; context.SaveChanges(); return("Success"); } else { return(checkValidate(money)); } }