public void RemoveAccountDetail(int id) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); AccountDetail accountDetail = db.AccountDetails.Where(ad => ad.accountDetailID == id).FirstOrDefault(); db.AccountDetails.Remove(accountDetail); db.SaveChanges(); }
public void RemoveFarmProduct(int id) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); FarmProduct farmProduct = db.FarmProducts.Where(fp => fp.farmProductID == id).FirstOrDefault(); db.FarmProducts.Remove(farmProduct); db.SaveChanges(); }
public void RemoveAccount(int id) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Account account = db.Accounts.Where(a => a.accountID == id).FirstOrDefault(); db.Accounts.Remove(account); db.SaveChanges(); }
public void RemoveOrder(int id) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Order order = db.Orders.Where(o => o.orderID == id).FirstOrDefault(); db.Orders.Remove(order); db.SaveChanges(); }
public void RemoveAddress(int id) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Address address = db.Addresses.Where(a => a.addressID == id).FirstOrDefault(); db.Addresses.Remove(address); db.SaveChanges(); }
public void RemoveFarm(int id) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Farm farm = db.Farms.Where(f => f.farmID == id).FirstOrDefault(); db.Farms.Remove(farm); db.SaveChanges(); }
public void AddFarmProduct(int farmID, int productID) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); FarmProduct farmProduct = new FarmProduct(); farmProduct.farmID = farmID; farmProduct.productID = productID; db.FarmProducts.Add(farmProduct); db.SaveChanges(); }
public void AddOrder(int accountID, int farmProductID) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Order order = new Order(); order.accountID = accountID; order.farmProductID = farmProductID; db.Orders.Add(order); db.SaveChanges(); }
public void UpdateAccount(int id, string email) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Account account = db.Accounts.Where(a => a.accountID == id).FirstOrDefault(); if (account != null) { account.email = email; db.SaveChanges(); } }
public void AddAccountDetail(int accountID, int farmID, int addressID) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); AccountDetail accountDetail = new AccountDetail(); accountDetail.accountID = accountID; accountDetail.farmID = farmID; accountDetail.addressID = addressID; db.AccountDetails.Add(accountDetail); db.SaveChanges(); }
public void UpdateFarm(int id, string name, string profile) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Farm farm = db.Farms.Where(f => f.farmID == id).FirstOrDefault(); if (farm != null) { farm.farmName = name; farm.farmProfile = profile; db.SaveChanges(); } }
public void AddFarm(string name, string profile) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Farm farm = new Farm(); farm.farmName = name; farm.farmProfile = profile; db.Farms.Add(farm); db.SaveChanges(); }
//Need to add encryption to password public void AddAccount(string username, string password, string email, string accountType) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Account account = new Account(); account.username = username; account.email = email; account.accountType = accountType; db.Accounts.Add(account); db.SaveChanges(); }
public void AddAddress(string streetName, string streetNum, string province, string city, string zip) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Address address = new Address(); address.streetName = streetName; address.streetNum = streetNum; address.province = province; address.city = city; address.zip = zip; db.Addresses.Add(address); db.SaveChanges(); }
//Need to add encryption to password public void AddAccount(string username, string password, string email, string accountType) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Account account = new Account(); account.username = username; account.password = password;//Add encryption? Do we need this field? account.email = email; account.accountType = accountType; db.Accounts.Add(account); db.SaveChanges(); }
public void AddProduct(string name, decimal price, string category, string description, int qtyInKG) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Product product = new Product(); product.productName = name; product.priceInKg = price; product.productCategory = category; product.productDescription = description; product.qtyInKG = qtyInKG; db.Products.Add(product); db.SaveChanges(); }
public void UpdateAddress(int id, string streetName, string streetNum, string province, string city, string zip) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Address address = db.Addresses.Where(a => a.addressID == id).FirstOrDefault(); if (address != null) { address.streetName = streetName; address.streetNum = streetNum; address.province = province; address.city = city; address.zip = zip; db.SaveChanges(); } }
public void InitializeFarmAccount(string username) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Farm farm = new Farm() { farmName = username, farmProfile = username + "profile" }; if (farm != null) { db.Farms.Add(farm); db.SaveChanges(); } }
public void UpdateProduct(int id, string name, decimal price, string category, string description, int qty) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Product product = db.Products.Where(p => p.productID == id).FirstOrDefault(); if (product != null) { product.productName = name; product.priceInKg = price; product.productCategory = category; product.productDescription = description; product.qtyInKG = qty; db.SaveChanges(); } }
public void RemoveProduct(int id) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Product product = db.Products.Where(p => p.productID == id).FirstOrDefault(); db.Products.Remove(product); db.SaveChanges(); }
public void InitializeUserAccount(RegisteredUser newUser) { FarmSaleDBEntities1 db = new FarmSaleDBEntities1(); Account account = new Account() { username = newUser.UserName, email = newUser.Email, accountType = newUser.UserRole }; db.Accounts.Add(account); Address address = new Address() { city = newUser.City, province = newUser.Province, streetName = newUser.StreetName, streetNum = newUser.StreetNum, zip = newUser.PostalCode }; db.Addresses.Add(address); Farm farm = new Farm(); if (newUser.UserRole.Equals("Farm")) { farm.farmName = newUser.FarmName; farm.farmProfile = newUser.FarmProfile; db.Farms.Add(farm); } db.SaveChanges(); Account newUserAccount = db.Accounts.Where(u => u.username == newUser.UserName).FirstOrDefault(); int accountID = newUserAccount.accountID; //querying new Address and Farm entities that we just added into sepearte tables. Address addressQuery = db.Addresses.Where(a => a.streetNum == newUser.StreetNum && a.streetName == newUser.StreetName && a.zip == newUser.PostalCode).FirstOrDefault(); Farm farmQuery = db.Farms.Where(f => f.farmName == newUser.FarmName && f.farmProfile == newUser.FarmProfile).FirstOrDefault(); //merging Address and Farm entities under the Account through the AccountDetails table AccountDetail newUserAccountDetail = new AccountDetail(); int addressID = addressQuery.addressID; if (farmQuery != null) { int farmID = farmQuery.farmID; newUserAccountDetail.farmID = farmID; } newUserAccountDetail.accountID = accountID; newUserAccountDetail.addressID = addressID; db.AccountDetails.Add(newUserAccountDetail); db.SaveChanges(); //farm.farmName = newUser.UserName = newUser.FarmName; //farm.farmProfile = newUser.UserName = newUser.FarmProfile; //address.AccountDetails.Add(newUserAccountDetail); //db.SaveChanges(); //account.AccountDetails.Add(newUserAccountDetails); //Address newUserAddress = new Address(); //Farm farm = new Farm(); //farm.farmName = " farm name " + newUser.UserName; //newUserAddress.city = "Vancouver"; //newUserAddress.AccountDetails.Add(newUserAccountDetails); //farm.AccountDetails.Add(newUserAccountDetails); db.SaveChanges(); //if ( newUser.UserRole.Equals("Farm")) //{ // Farm farm = new Farm(); // farm.farmName = newUser.UserName; // AccountDetail //} //if (account != null) //{ // account.email = email; // db.SaveChanges(); //} }