private static void RemoveRecordById(int CarId, byte[] timeStamp) { using (var ir = new InventoryRepo()) { ir.Delete(CarId, timeStamp); } }
private static void RemoveRecordById(int carId, byte[] timeStamp) { using (var repo = new InventoryRepo()) { repo.Delete(carId, timeStamp); } }
private static void AddNewRecord(Inventory car) { using (var repo = new InventoryRepo()) { repo.Add(car); } }
private void btnDelete_Click(object sender, EventArgs e) { if (this.dgvProductdetails.SelectedRows.Count < 1) { MessageBox.Show("No row selected"); return; } string appId = this.dgvProductdetails.CurrentRow.Cells["appid"].Value.ToString(); string title = this.dgvProductdetails.CurrentRow.Cells["title"].Value.ToString(); if (MessageBox.Show($"Do you want to delete {title}?", "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { return; } SalesRepo.DeleteByProductId(appId); if (InventoryRepo.Delete(appId)) { MessageBox.Show(title + " has been deleted successfully"); this.PopulateGridView(); this.dgvProductdetails.ClearSelection(); this.dgvProductdetails.Refresh(); this.ClearInputs(); } else { MessageBox.Show("Product couldn't be deleted"); } }
private void DeleteCar(Inventory car) { var repo = new InventoryRepo(); repo.Delete(car); Cars = new ObservableCollection <Inventory>(repo.GetAll()); }
private static void TestConcurrency() { var repo1 = new InventoryRepo(); var repo2 = new InventoryRepo(); var car1 = repo1.GetOne(1); var car2 = repo1.GetOne(1); car1.PetName = "NewName"; repo1.Save(car1); car2.PetName = "OtherName"; try { repo2.Save(car2); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var currentValues = entry.CurrentValues; var originalValues = entry.OriginalValues; var dbValues = entry.GetDatabaseValues(); Console.WriteLine("*** Concurrency ***"); Console.WriteLine("Type\tPetName"); Console.WriteLine($"Current:\t{currentValues[nameof(Inventory.PetName)]}"); Console.WriteLine($"Original:\t{originalValues[nameof(Inventory.PetName)]}"); Console.WriteLine($"Db:\t{dbValues[nameof(Inventory.PetName)]}"); } }
public IHttpActionResult CreateDisbursementDetails(DisbursementDetailsModel dism) { string error = ""; DisbursementDetailsModel disbm = DisbursementDetailsRepo.CreateDisbursementDetails(dism, out error); // get the inventory using the item id from Requisition details InventoryModel invm = InventoryRepo.GetInventoryByItemid(dism.Itemid, out error); // subtract the stock accoring to qty invm.Stock -= dism.Qty; // update the inventory invm = InventoryRepo.UpdateInventory(invm, out error); InventoryTransactionModel invtm = new InventoryTransactionModel { InvID = invm.Invid, ItemID = invm.Itemid, Qty = dism.Qty * -1, TransType = ConInventoryTransaction.TransType.DISBURSEMENT, TransDate = DateTime.Now, Remark = dism.Disid.ToString() }; invtm = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error); if (error != "" || disbm == null) { return(Content(HttpStatusCode.BadRequest, error)); } return(Ok(disbm)); }
static void Main(string[] args) { Console.WriteLine("FUN WITH EF CORE"); using (var context = new AutoLotEntities()) { MyDataInitializer.RecreateDatabase(context); MyDataInitializer.InitializeData(context); foreach (Inventory inv in context.Cars) { Console.WriteLine(inv); } } Console.WriteLine("Fun with repos"); using (var repo = new InventoryRepo()) { foreach (var c in repo.GetAll()) { Console.WriteLine(c); } } Console.ReadLine(); }
private static void UpdateRecordWithConcurrency() { ForegroundColor = ConsoleColor.Cyan; WriteLine("=> Update Record with Concurrency"); var car = new Inventory { Make = "Yugo", Color = "Brown", PetName = "Brownie" }; AddNewRecord(car); WriteLine($"The new carId : {car.CarId}"); var repo1 = new InventoryRepo(); var car1 = repo1.GetOne(car.CarId); car1.PetName = "Updated1"; var repo2 = new InventoryRepo(); var car2 = repo2.GetOne(car.CarId); car2.Make = "Nissan"; repo1.Save(car1); try { repo2.Save(car2); } catch (DbUpdateConcurrencyException ex) { WriteLine(ex.Message); } catch (Exception ex) { WriteLine(ex.Message); } RemoveRecordById(car1.CarId, car1.Timestamp); }
private void viewProductService_bt_Click(object sender, EventArgs e) { InventoryRepo inventoryRepo = new InventoryRepo(); List <Inventory> inventoryList = inventoryRepo.GetAllInventory(); this.dataGridViewInventoryService.DataSource = inventoryList; }
private static void RemoveRecordCar(Test carDelete) { using (var repo = new InventoryRepo()) { repo.Delete(carDelete); } }
public static void AddNewRecord(Inventory inventory) { using (var repo = new InventoryRepo()) { repo.Add(inventory); } }
private static void UpdateRecordWithConcurrency() { var car = new Inventory { Make = "Boshi", Color = "Green", PetName = "Cake" }; AddNewRecord(car); var firstUser = new InventoryRepo(); var firstCar = firstUser.GetOne(car.CarId); firstCar.PetName = "Dread"; var secondUser = new InventoryRepo(); var secondCar = secondUser.GetOne(car.CarId); secondCar.PetName = "Mad"; firstUser.Save(firstCar); try { secondUser.Save(secondCar); } catch (DbUpdateConcurrencyException ex) { Console.WriteLine(ex); } finally { firstUser.Dispose(); secondUser.Dispose(); } }
private static void TestConcurrency() { InventoryRepo repo1 = new InventoryRepo(); InventoryRepo repo2 = new InventoryRepo(); Inventory car1 = repo1.GetOne(1); Inventory car2 = repo2.GetOne(1); car1.PetName = "NewName"; repo1.Save(car1); car2.PetName = "OtherName"; try { repo2.Save(car2); Console.WriteLine("Done!"); } catch (DbUpdateConcurrencyException ex) { Console.WriteLine("Exception!"); var entries = ex.Entries; foreach (var entry in entries) { Console.WriteLine("Orginal Value: {0}", entry.OriginalValues["PetName"]); Console.WriteLine("Current Value: {0}", entry.CurrentValues["PetName"]); Console.WriteLine("Database Value: {0}", entry.GetDatabaseValues()["PetName"]); } } }
private static void AddNewRecord(inventory car) { using (var repo = new InventoryRepo(new AutoLotContext())) { repo.Add(car); } }
private static void RemoveRecordById(int id, byte[] time) { WriteLine($"Remove a record with id {id}"); using (var repo = new InventoryRepo()) repo.Delete(id, time); }
private static void TestConcurrency() { var repo1 = new InventoryRepo(new AutoLotContext()); //Use a second repo to make sure using a different context var repo2 = new InventoryRepo(new AutoLotContext()); var car1 = repo1.GetOne(1); var car2 = repo2.GetOne(1); car1.PetName = "NewName"; repo1.Update(car1); car2.PetName = "OtherName"; try { repo2.Update(car2); } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var currentValues = entry.CurrentValues; var originalValues = entry.OriginalValues; var dbValues = entry.GetDatabaseValues(); Console.WriteLine(" ******** Concurrency ************"); Console.WriteLine("Type\tPetName"); Console.WriteLine($"Current:\t{currentValues[nameof(inventory.PetName)]}"); Console.WriteLine($"Orig:\t{originalValues[nameof(inventory.PetName)]}"); Console.WriteLine($"db:\t{dbValues[nameof(inventory.PetName)]}"); } }
static void Main(string[] args) { //Database.SetInitializer(new MyDataInitializer()); //Console.WriteLine("***** Fun with ADO.NET EF Code First *****\n"); //using (var context = new AutoLotEntities()) //{ // foreach (Inventory c in context.Inventory) // { // Console.WriteLine(c); // } //} //Console.ReadLine(); Console.WriteLine("***** Using a Repository *****\n"); using (var repo = new InventoryRepo()) { foreach (Inventory c in repo.GetAll()) { Console.WriteLine(c); } } TestConcurrency(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("EF Core 2"); using (var context = new AutoLotContext()) { MyDataInitializer.RecreateDatabase(context); MyDataInitializer.InitializeData(context); foreach (var car in context.Cars) { Console.WriteLine(car); } } Console.WriteLine("Using Repository"); using (var repo = new InventoryRepo()) { foreach (var car in repo.GetAll()) { Console.WriteLine("Repo: " + car); } } Console.ReadLine(); using (var context = new AutoLotContext()) { var car = context.Cars.Include(x => x.Orders).ThenInclude(x => x.Customer).FirstOrDefault(x => x.Id == 4); Console.WriteLine($"The customer of {car} is:"); Console.WriteLine(car.Orders.FirstOrDefault().Customer); } }
public static void Main(string[] args) { Database.SetInitializer(new MyDataInitializer()); Console.WriteLine("EF data"); using (var repo = new InventoryRepo()) { foreach (var inventory in repo.GetAll()) { Console.WriteLine(inventory); } } Console.ReadLine(); TestMethod.AddNewRecord(new Inventory { Make = "BMW", Color = "Green", PetName = "NewHank" }); Console.WriteLine("The new record has been created"); Console.ReadLine(); using (var repo = new InventoryRepo()) { foreach (var inventory in repo.GetAll()) { Console.WriteLine(inventory); } } Console.ReadLine(); }
private bool FillEntity() { this.Product = new Products { AppId = InventoryRepo.GetAppId(), Title = this.txtProductTitle.Text, Price = this.txtPrice.Text, PurchasePrice = this.txtPurchasePrice.Text, Quantity = this.txtQuantity.Text }; if (!this.CategoryFillEntity()) { return(false); } this.Product.CategoryName = this.cboCategory.Text; this.Product.CategoryId = this.GetCategoryId(); ProductsValidation validator = new ProductsValidation(); ValidationResult results = validator.Validate(this.Product); IList <ValidationFailure> failures = results.Errors; if (!(results.IsValid)) { foreach (ValidationFailure failure in failures) { MessageBox.Show(failure.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } return(true); }
private void ButtonViewInventoryMAnager_Click(object sender, EventArgs e) { InventoryRepo inventoryRepo = new InventoryRepo(); List <Inventory> inventoryList = inventoryRepo.GetAllInventory(); this.dataGridViewManagerInventory.DataSource = inventoryList; }
public ViewInventoryViewModel(INavigation navigation) { _navigation = navigation; _inventoryRepo = new InventoryRepo(); FetchInventory(); }
private void buttonOrderAddMan_Click(object sender, EventArgs e) { try { OrderMenu orderMenu = new OrderMenu(); // orderMenu.OrderNo = Convert.ToInt32(this.textBoxOrderNo.Text); orderMenu.ItemName = this.textBoxOdrItemNameMan_bt.Text; orderMenu.ItemQuantity = Convert.ToInt32(this.textBoxOrderQuantityMan.Text); OrderMenuRepo orderMenuRepo = new OrderMenuRepo(); if (orderMenu.ItemQuantity <= orderMenuRepo.GetQuantity(orderMenu.ItemName)) { if (orderMenuRepo.Insert(orderMenu)) { List <OrderMenu> orderMenuList = orderMenuRepo.GetAllOrderMenu(); this.dataGridViewOrderedItmManagwe2.DataSource = orderMenuList; InventoryRepo inventoryRepo = new InventoryRepo(); inventoryRepo.Update(orderMenuRepo.GetQuantity(orderMenu.ItemName) - orderMenu.ItemQuantity, orderMenu.ItemName); List <Inventory> inventoryList = inventoryRepo.GetAllInventory(); this.dataGridOrderMenuItemMan1.DataSource = inventoryList; } } else { MessageBox.Show("Quantity Limit Exceed"); } } catch { } }
private static void RemoveRecordByCar(Inventory carToDelete) { using (var repo = new InventoryRepo()) { repo.Delete(carToDelete); } }
private void buttonOrderDiscardMan_Click(object sender, EventArgs e) { try { OrderMenu orderMenu = new OrderMenu(); // orderMenu.OrderNo = Convert.ToInt32(this.textBoxOrderNo.Text); orderMenu.ItemName = this.textBoxOdrItemNameMan_bt.Text; orderMenu.ItemQuantity = Convert.ToInt32(this.textBoxOrderQuantityMan.Text); InventoryRepo inventoryRepo = new InventoryRepo(); OrderMenuRepo orderMenuRepo = new OrderMenuRepo(); inventoryRepo.Update(orderMenuRepo.GetQuantity(orderMenu.ItemName) + orderMenu.ItemQuantity, orderMenu.ItemName); orderMenuRepo.Delete(orderMenu.ItemName); // orderMenuRepo.Update(, orderMenu.ItemName); List <OrderMenu> orderMenuList = orderMenuRepo.GetAllOrderMenu(); this.dataGridViewOrderedItmManagwe2.DataSource = orderMenuList; List <Inventory> inventoryList = inventoryRepo.GetAllInventory(); this.dataGridOrderMenuItemMan1.DataSource = inventoryList; this.textBoxOdrItemNameMan_bt.Text = ""; this.textBoxOrderQuantityMan.Text = ""; } catch { } }
private static void UpdateRecordWIthConcurrency() { var car = new Inventory() { Make = "Yugo", Color = "Brown", Name = "Brownie" }; AddNewRecord(car); PrintAllInventory(); var repo1 = new InventoryRepo(); var car1 = repo1.GetOne(car.CarId); car1.Name = "Updated"; var repo2 = new InventoryRepo(); var car2 = repo2.GetOne(car.CarId); car2.Make = "Nissan"; repo1.Save(car1); try { repo2.Save(car2); } catch (DbUpdateConcurrencyException ex) { WriteLine(ex); } //RemoveRecordById(car1.CarId, car1.Timestamp); PrintAllInventory(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with ADO.NET EF Core 2 *****\n"); using (var context = new AutoLotContext()) { MyDataInitializer.RecreateDatabase(context); MyDataInitializer.InitializeData(context); foreach (inventory c in context.Cars) { Console.WriteLine(c); } } Console.WriteLine("***** Using a Repository *****\n"); using (var context = new AutoLotContext()) { using var repo = new InventoryRepo(context); foreach (inventory c in repo.GetAll()) { Console.WriteLine(c); } } TestConcurrency(); Console.ReadLine(); }
private static void AddNewRecords(IList <Inventory> cars) { using (var repo = new InventoryRepo()) { repo.AddRange(cars); } }
private static void RemoveRecordByCar(Inventory car) { using (var ir = new InventoryRepo()) { ir.Delete(car); } }