public bool Update(BankAccountB bankAccountBefore) { bool update = true; using (var NWEntities = new SaveWorldEntities()) { var bankId = bankAccountBefore.AccountId; var accountForSave = (from p in NWEntities.BankAccounts where p.id == bankId select p).FirstOrDefault(); accountForSave.accountNo = bankAccountBefore.AccountNo; accountForSave.amount = bankAccountBefore.Amount; accountForSave.ccv = bankAccountBefore.CCV; accountForSave.expiryDate = bankAccountBefore.ExpiryDate; accountForSave.rowVersion = bankAccountBefore.RowVersion; NWEntities.BankAccounts.Attach(accountForSave); NWEntities.Entry(accountForSave).State = System.Data.Entity.EntityState.Modified; try { NWEntities.SaveChanges(); } catch { update = false; } } return(update); }
public bool UpdateProduct(ProductB product) { var updated = true; using (var NWEntities = new SaveWorldEntities()) { var productId = product.ProductId; var productDatabase = (from p in NWEntities.Products where p.id == productId select p).FirstOrDefault(); if (productDatabase == null) { throw new Exception("No product with ID " + product.ProductId); } productDatabase.productName = product.ProductName; productDatabase.price = product.Price; productDatabase.description = product.ProductDescription; productDatabase.minStock = product.Stock; NWEntities.Products.Attach(productDatabase); NWEntities.Entry(productDatabase).State = System.Data.Entity.EntityState.Modified; var num = NWEntities.SaveChanges(); } return(updated); }
public void UpdateOrderLine(OrderLine orderLine) { using (var NWEntities = new SaveWorldEntities()) { var orderLineId = orderLine.OrderLineId; var orderLineDatabase = (from p in NWEntities.OrderLine where p.id == orderLineId select p).FirstOrDefault(); if (orderLineDatabase == null) { throw new Exception("No orderLine with ID " + orderLine.OrderLineId); } orderLineDatabase.id = orderLine.OrderLineId; orderLineDatabase.orderId = orderLine.OrderID; orderLineDatabase.price = orderLine.Price; orderLineDatabase.productId = orderLine.ProductID; orderLineDatabase.quantity = orderLine.Quantity; NWEntities.OrderLine.Attach(orderLineDatabase); NWEntities.Entry(orderLineDatabase).State = System.Data.Entity.EntityState.Modified; var num = NWEntities.SaveChanges(); } }
public bool CreateDisaster(DisasterB newDisaster) { using (SaveWorldEntities dbEntities = new SaveWorldEntities()) { if (dbEntities.Disasters.Any(o => o.disasterName == newDisaster.Name)) { return(false); } disaster disaster = new disaster() { disasterName = newDisaster.Name, categoryId = newDisaster.CategoryId, description = newDisaster.Description, priority = newDisaster.Priority, region = newDisaster.Region, victims = newDisaster.Victims, accountId = newDisaster.DisasterBankAccountId, }; dbEntities.Disasters.Add(disaster); dbEntities.SaveChanges(); } return(true); }
public OrderLine CreateOrderLine(OrderLine newOrder) { using (SaveWorldEntities dbEntities = new SaveWorldEntities()) { orderLine ordLine = new orderLine() { // id = newOrder.OrderLineId, orderId = 1, productId = newOrder.ProductID, quantity = newOrder.Quantity, price = newOrder.Price, }; dbEntities.OrderLine.Add(ordLine); dbEntities.SaveChanges(); OrderLine returnOrder = new OrderLine(); // returnOrder = null; returnOrder.OrderLineId = ordLine.id; returnOrder.ProductID = (int)ordLine.productId; returnOrder.OrderID = (int)ordLine.orderId; returnOrder.Quantity = ordLine.quantity; returnOrder.Price = ordLine.price; return(returnOrder); } }
public void DeleteProduct(int id) { using (var NWEntities = new SaveWorldEntities()) { var product = (from p in NWEntities.Products where p.id == id select p).FirstOrDefault(); if (product != null) { NWEntities.Products.Remove(product); NWEntities.SaveChanges(); } ; } }
public void DeleteDisaster(int id) { using (var NWEntities = new SaveWorldEntities()) { var disaster = (from p in NWEntities.Disasters where p.id == id select p).FirstOrDefault(); if (disaster != null) { NWEntities.Disasters.Remove(disaster); NWEntities.SaveChanges(); } ; } }
public void CreateUser(UserB newUser) { string salted = SaltGenerator(10); string passHash = Hasher(newUser.Password + salted); using (SaveWorldEntities dbEntities = new SaveWorldEntities()) { if (dbEntities.Ausers.Any(o => o.email == newUser.Email)) { return; } auser user = new auser() { name = newUser.Name, email = newUser.Email, password = passHash, salt = salted, address = newUser.Address, phoneno = newUser.Phone, typeOfUser = 1, accountId = newUser.BankAccountId, }; dbEntities.Ausers.Add(user); try { dbEntities.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } } }
public void ReturnStock(int idOfProduct, int returnQuantity) { using (SaveWorldEntities dbEntities = new SaveWorldEntities()) { var product = (from p in dbEntities.Products where p.id == idOfProduct select p).FirstOrDefault(); if (product != null) { product.minStock += returnQuantity; } dbEntities.SaveChanges(); } }
public void RemoveStockFromProduct(int id, int removeQuantity) { using (SaveWorldEntities dbEntities = new SaveWorldEntities()) { var product = (from p in dbEntities.Products where p.id == id select p).FirstOrDefault(); if (product != null) { product.minStock -= removeQuantity; } dbEntities.SaveChanges(); } }
public int CreateOrderAndReturnId(Order newOrder) { using (SaveWorldEntities dbEntities = new SaveWorldEntities()) { tbOrder order = new tbOrder() { userId = newOrder.UserId, date = newOrder.OrderDate, }; dbEntities.TbOrder.Add(order); dbEntities.SaveChanges(); return(order.id); } }
public int DeleteUser(int id) { using (var NWEntities = new SaveWorldEntities()) { var usr = (from p in NWEntities.Ausers where p.id == id select p).FirstOrDefault(); if (usr != null) { NWEntities.Ausers.Remove(usr); NWEntities.SaveChanges(); } ; } return(id); }
public int RemoveOrderLineAndReturnStock(int idToRemoveOrderLine) { int stock = 0; using (var NWEntities = new SaveWorldEntities()) { var orderLine = (from p in NWEntities.OrderLine where p.id == idToRemoveOrderLine select p).FirstOrDefault(); if (orderLine != null) { stock = orderLine.quantity; NWEntities.OrderLine.Remove(orderLine); NWEntities.SaveChanges(); } ; } return(stock); }
/* public bool IsCookieValid(string cookieId) * { * CoreValidator.ThrowIfNullOrEmpty(cookieId, nameof(cookieId)); * using (var db = new AuctionContext()) * { * return db.Users.Any(u => u.RememberToken == cookieId); * } * } */ public bool UpdateUser(UserB user) { string salted = SaltGenerator(10); string passHash = Hasher(user.Password + salted); var updated = true; using (var NWEntities = new SaveWorldEntities()) { var userId = user.UserId; var userDatabase = (from p in NWEntities.Ausers where p.id == userId select p).FirstOrDefault(); if (userDatabase == null) { throw new Exception("No user with ID " + user.UserId); } userDatabase.name = user.Name; userDatabase.email = user.Email; userDatabase.password = passHash; userDatabase.salt = salted; userDatabase.phoneno = user.Phone; userDatabase.address = user.Address; userDatabase.accountId = user.BankAccountId; NWEntities.Ausers.Attach(userDatabase); NWEntities.Entry(userDatabase).State = System.Data.Entity.EntityState.Modified; var num = NWEntities.SaveChanges(); } return(updated); }
public bool CreateProduct(ProductB newProduct) { using (SaveWorldEntities dbEntities = new SaveWorldEntities()) { if (dbEntities.Products.Any(o => o.productName == newProduct.ProductName)) { return(false); } product Product = new product() { productName = newProduct.ProductName, description = newProduct.ProductDescription, price = newProduct.Price, minStock = newProduct.Stock, }; dbEntities.Products.Add(Product); dbEntities.SaveChanges(); } return(true); }
public bool UpdateDisaster(DisasterB disaster) { var updated = true; using (var NWEntities = new SaveWorldEntities()) { var disasterId = disaster.DisasterId; var disasterDatabse = (from p in NWEntities.Disasters where p.id == disasterId select p).FirstOrDefault(); if (disasterDatabse == null) { throw new Exception("No disaster with ID " + disaster.DisasterId); } disasterDatabse.disasterName = disaster.Name; disasterDatabse.description = disaster.Description; disasterDatabse.priority = disaster.Priority; disasterDatabse.region = disaster.Region; disasterDatabse.victims = disaster.Victims; NWEntities.Disasters.Attach(disasterDatabse); NWEntities.Entry(disasterDatabse).State = System.Data.Entity.EntityState.Modified; var num = NWEntities.SaveChanges(); } return(updated); }