public static List <TransactionModel> getTransactionForSpecificUser(int id) { var joinQuery = from trans in DBSingleton.getDB().Transaction join user in DBSingleton.getDB().MsUser on trans.UserId equals user.UserId join shoe in DBSingleton.getDB().ShoeTable on trans.ProductId equals shoe.ShoeId where user.UserId == id select new TransactionModel { MemberName = user.UserName, ProductName = shoe.ShoeName, ProductPrice = shoe.ShoePrice, Quantity = trans.Quantity, Subtotal = trans.Quantity * shoe.ShoePrice, TransactionDate = trans.TransactionDate, TransactionStatus = trans.TransactionStatus, TransactionId = trans.TransactionId }; List <TransactionModel> joinList = new List <TransactionModel>(); foreach (var item in joinQuery) { joinList.Add(item); } return(joinList); }
public static List <CartModel> getUserCart(int userId) { var joinQuery = from cart in DBSingleton.getDB().UserCart join user in DBSingleton.getDB().MsUser on cart.UserId equals user.UserId join shoe in DBSingleton.getDB().ShoeTable on cart.ShoeId equals shoe.ShoeId //where user.UserId == userId && shoe.ShoeId == productId select new CartModel { CartId = cart.CartId, ShoeId = shoe.ShoeId, UserId = user.UserId, Quantity = cart.Quantity, ShoeName = shoe.ShoeName, ShoeImage = shoe.ShoeImage, ShoePrice = shoe.ShoePrice, SubTotal = shoe.ShoePrice * cart.Quantity }; //System.Diagnostics.Debug.WriteLine("JoinQuery = " + joinQuery); foreach (var str in joinQuery) { System.Diagnostics.Debug.WriteLine(str); } List <CartModel> joinList = new List <CartModel>(); foreach (var item in joinQuery) { joinList.Add(item); } return(joinList); }
public static void updatePassword(int id, string pass) { List <MsUser> data = UserRepository.getUserData(); MsUser updateUser = data.Where(y => y.UserId == id).SingleOrDefault(); updateUser.UserPassword = pass; DBSingleton.getDB().SaveChanges(); }
public static void incrementTotalSales(int id) { List <ShoeTable> data = ShoeRepository.getShoeData(); ShoeTable incrementShoe = data.Where(y => y.ShoeId == id).SingleOrDefault(); incrementShoe.TotalSales += 1; DBSingleton.getDB().SaveChanges(); }
public static void updateUserToAdmin(int id) { List <MsUser> data = UserRepository.getUserData(); MsUser updateUser = data.Where(y => y.UserId == id).SingleOrDefault(); updateUser.UserRole = "U002"; DBSingleton.getDB().SaveChanges(); }
//Update public static void updateCart(int cartId, int userId, int shoeId, int quantity) { UserCart updateCart = DBSingleton.getDB().UserCart.Where(y => y.CartId == cartId).SingleOrDefault(); updateCart.UserId = userId; updateCart.ShoeId = shoeId; updateCart.Quantity = quantity; DBSingleton.getDB().SaveChanges(); }
//Update public static void updateTransaction(int transactionId, string transactionStatus, int quantity, int subtotal) { Transaction updateCart = DBSingleton.getDB().Transaction.Where(y => y.TransactionId == transactionId).SingleOrDefault(); updateCart.TransactionId = transactionId; updateCart.TransactionStatus = transactionStatus; updateCart.Quantity = quantity; updateCart.Subtotal = subtotal; DBSingleton.getDB().SaveChanges(); }
//Update public static void updateShoe(int id, string updateName, int updatePrice, int updateStock, string updateImage) { ShoeTable updateShoe = DBSingleton.getDB().ShoeTable.Where(y => y.ShoeId == id).SingleOrDefault(); updateShoe.ShoeName = updateName; updateShoe.ShoeStock = updateStock; updateShoe.ShoePrice = updatePrice; updateShoe.ShoeImage = updateImage; DBSingleton.getDB().SaveChanges(); }
//Update public static void updateUser(int id, string updateName, string email, string updatePassword, string gender, DateTime birthDate, string phoneNumber, string address, string profile, string userRole) { MsUser updateUser = DBSingleton.getDB().MsUser.Where(y => y.UserId == id).SingleOrDefault(); updateUser.UserName = updateName; updateUser.Email = email; updateUser.UserPassword = updatePassword; updateUser.Gender = gender; updateUser.BirthDate = birthDate; updateUser.PhoneNumber = phoneNumber; updateUser.Address = address; updateUser.Profile = profile; updateUser.UserRole = userRole; DBSingleton.getDB().SaveChanges(); }
public static CartModel getSpecificProductUserCart(int userId, int productId) { var joinQuery = from cart in DBSingleton.getDB().UserCart join user in DBSingleton.getDB().MsUser on cart.UserId equals user.UserId join shoe in DBSingleton.getDB().ShoeTable on cart.ShoeId equals shoe.ShoeId where user.UserId == userId && shoe.ShoeId == productId select new CartModel { CartId = cart.CartId, ShoeId = shoe.ShoeId, UserId = user.UserId, Quantity = cart.Quantity, ShoeName = shoe.ShoeName, ShoeImage = shoe.ShoeImage, ShoePrice = shoe.ShoePrice }; return(joinQuery.SingleOrDefault()); }
//CRUD //Read public static List <ShoeTable> getShoeData() { try { List <ShoeTable> data = DBSingleton.getDB().ShoeTable.ToList(); return(data); } catch { ShoeTable b = new ShoeTable() { ShoeId = 0, ShoeImage = "Error.jpg", ShoeName = "Error", ShoePrice = 0, ShoeStock = 0, TotalSales = 0 }; List <ShoeTable> errorData = new List <ShoeTable>(); errorData.Add(b); return(errorData); } }
public static UserRole findUserRole(string roleId) { return(DBSingleton.getDB().UserRole.Where(x => x.UserRoleId == roleId).SingleOrDefault()); }
//CRUD //Read public static List <UserCart> getUserCart() { return(DBSingleton.getDB().UserCart.ToList()); }
//Delete public static void deleteTransaction(Transaction delTransaction) { DBSingleton.getDB().Transaction.Remove(delTransaction); DBSingleton.getDB().SaveChanges(); }
public static void insertUser(MsUser newUser) { DBSingleton.getDB().MsUser.Add(newUser); //lamda exprestion DBSingleton.getDB().SaveChanges(); }
//Delete public static void deleteUser(MsUser delUser) { DBSingleton.getDB().MsUser.Remove(delUser); DBSingleton.getDB().SaveChanges(); }
//CRUD //Read public static List <MsUser> getUserData() { return(DBSingleton.getDB().MsUser.ToList()); }
public static void insertTransaction(Transaction newTransaction) { DBSingleton.getDB().Transaction.Add(newTransaction); //lamda exprestion DBSingleton.getDB().SaveChanges(); }
//Delete public static void deleteCart(UserCart delCart) { DBSingleton.getDB().UserCart.Remove(delCart); DBSingleton.getDB().SaveChanges(); }
public static void insertShoe(ShoeTable newShoe) { DBSingleton.getDB().ShoeTable.Add(newShoe); //lamda exprestion DBSingleton.getDB().SaveChanges(); }
//Delete public static void deleteShoe(ShoeTable delShoe) { DBSingleton.getDB().ShoeTable.Remove(delShoe); DBSingleton.getDB().SaveChanges(); }
public static void insertCart(UserCart newCart) { DBSingleton.getDB().UserCart.Add(newCart); //lamda exprestion DBSingleton.getDB().SaveChanges(); }
//CRUD //Read public static List <Transaction> getTransaction() { return(DBSingleton.getDB().Transaction.ToList()); }