public ActionResult Create([Bind(Include = "InvoiceID,NumberOf,CreateDate,BillingDeadline,TotalPrice,TotalPriceWithTax,Buyer,Quantity")] Invoice invoice, string[] selectedProducts, string[] quantity, string country) { if (ModelState.IsValid) { invoice.MyUser = getMyUser(); if (selectedProducts != null) { invoice.Products = getSelectedProducts(selectedProducts, quantity); } if (invoice.Products != null) { invoice.TotalPrice = getTotalPrice(invoice.Products); } invoice.TotalPriceWithTax = tax.CalculateTax(country, invoice.TotalPrice); invoice.CreateDate = DateTime.Now; db.Invoices.Add(invoice); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(invoice)); }
public IHttpActionResult PutClient(int id, Client client) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != client.ClientID) { return(BadRequest()); } db.Entry(client).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutEmployee(int id, Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employee.EmployeeID) { return(BadRequest()); } db.Entry(employee).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutInvoiceDetails(int id, InvoiceDetails invoiceDetails) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != invoiceDetails.FacturaDetailID) { return(BadRequest()); } db.Entry(invoiceDetails).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InvoiceDetailsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Insert(T entity) { if (entity == null) { throw new ArgumentNullException("entity"); } entities.Add(entity); context.SaveChanges(); }
public ActionResult Create([Bind(Include = "USERNAME,PASSWORD")] login login) { if (ModelState.IsValid) { db.logins.Add(login); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(login)); }
public ActionResult Create([Bind(Include = "ClientId,Name,Address,City,State,Zip,Phone,Email")] Client client) { if (ModelState.IsValid) { db.Clients.Add(client); db.SaveChanges(); return(RedirectToAction("AltClient", "Clients")); } return(View(client)); }
public ActionResult Create([Bind(Include = "InvoiceId,LineItemId,LineNumber,Description,Qty,UnitPrice")] LineItem lineItem) { if (ModelState.IsValid) { db.LineItems.Add(lineItem); db.SaveChanges(); return(RedirectToAction("AltClient", "Clients")); } return(View(lineItem)); }
public ActionResult Create([Bind(Include = "InvoiceId,ClientId,Number,Date,Status,StatusDate")] Invoice invoice) { if (ModelState.IsValid) { db.Invoices.Add(invoice); db.SaveChanges(); return(RedirectToAction("AltClient", "Clients")); } return(View(invoice)); }
public ActionResult Create([Bind(Include = "ProductID,Name,Quantity,Price,TotalPrice")] Product product) { if (ModelState.IsValid) { product.TotalPrice = product.Price * product.Quantity; db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task GetInvoiceById_Single() { var options = new DbContextOptionsBuilder <InvoiceContext>() .UseInMemoryDatabase(databaseName: "GetInvoiceById_Single") .Options; using (var context = new InvoiceContext(options)) { context.Invoices.AddRange( new Invoice { InvoiceId = new Guid("050b2d01-67a4-417c-9ef2-625aaa4d81b9"), Amount = 1.1m }, new Invoice { InvoiceId = new Guid("777a1a81-3115-474d-9c43-ed103a091eba"), Amount = 2.2m }, new Invoice { InvoiceId = new Guid("872db39e-19f5-4be9-8870-29c80c93eb4d"), Amount = 3.3m } ); context.SaveChanges(); } using (var context = new InvoiceContext(options)) { var repository = new EntityFrameworkInvoiceRepository(context); var invoice = await repository.GetInvoiceById(new Guid("777a1a81-3115-474d-9c43-ed103a091eba")); Assert.IsNotNull(invoice); Assert.AreEqual(2.2m, invoice.Amount); } }
public void DeleteInvoice_CanDelete() { var options = new DbContextOptionsBuilder <InvoiceContext>() .UseInMemoryDatabase(databaseName: "DeleteInvoice_CanDelete") .Options; using (var context = new InvoiceContext(options)) { context.Invoices.Add( new Invoice { InvoiceId = new Guid("050b2d01-67a4-417c-9ef2-625aaa4d81b9"), Amount = 1.1m } ); context.SaveChanges(); } using (var context = new InvoiceContext(options)) { var repository = new EntityFrameworkInvoiceRepository(context); repository.DeleteInvoice( new Invoice { InvoiceId = new Guid("050b2d01-67a4-417c-9ef2-625aaa4d81b9"), Amount = 1.1m } ); context.SaveChanges(); } using (var context = new InvoiceContext(options)) { Assert.AreEqual(0, context.Invoices.Count()); } }
public void ExistsInvoice_Exists() { var options = new DbContextOptionsBuilder <InvoiceContext>() .UseInMemoryDatabase(databaseName: "ExistsInvoice_Exists") .Options; using (var context = new InvoiceContext(options)) { context.Invoices.AddRange( new Invoice { InvoiceId = new Guid("050b2d01-67a4-417c-9ef2-625aaa4d81b9"), Amount = 1.1m }, new Invoice { InvoiceId = new Guid("777a1a81-3115-474d-9c43-ed103a091eba"), Amount = 2.2m }, new Invoice { InvoiceId = new Guid("872db39e-19f5-4be9-8870-29c80c93eb4d"), Amount = 3.3m } ); context.SaveChanges(); } using (var context = new InvoiceContext(options)) { var repository = new EntityFrameworkInvoiceRepository(context); var exists = repository.ExistsInvoice(new Guid("777a1a81-3115-474d-9c43-ed103a091eba")); Assert.IsTrue(exists); } }
private void Button_Click_2(object sender, RoutedEventArgs e) { try { BLL.AviaTicketXMLParser parser = new BLL.AviaTicketXMLParser(); AviaTicket ticket = parser.ParseTicket(this.ticketPath.Text).Result; using (AviaTicketModel db = new AviaTicketModel()) { db.AviaXMLTickets.Add(ticket); db.SaveChanges(); } AviaInvoice invoice = new Mapper(ticket).Map(); using (InvoiceContext db = new InvoiceContext()) { db.Invoices.Add(invoice); db.SaveChanges(); } oneTicketTextBox.Content = "Квиток додано до БД."; Thread.Sleep(1000); oneTicketTextBox.Content = "Оберiть новий квиток."; } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }
private void Parse_Ticket(object sender, FileSystemEventArgs argv) { Task.Run(() => { try { watcher.EnableRaisingEvents = false; if (argv.ChangeType == WatcherChangeTypes.Changed) { BLL.AviaTicketXMLParser parser = new BLL.AviaTicketXMLParser(); AviaTicket ticket = parser.ParseTicket(argv.FullPath).Result; using (AviaTicketModel db = new AviaTicketModel()) { db.AviaXMLTickets.Add(ticket); db.SaveChanges(); } AviaInvoice invoice = new Mapper(ticket).Map(); using (InvoiceContext db = new InvoiceContext()) { db.Invoices.Add(invoice); db.SaveChanges(); } } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } finally { this.watcher.EnableRaisingEvents = true; } }); }
private void btnInvoiceAdd_Click(object sender, EventArgs e) { if (!ProductInputControl()) { return; } InvoiceHeader invoiceHeader = new InvoiceHeader() { InvoiceID = invoiceID, invoiceDetails = invoiceDetails, InvoiceDate = DateTime.Now, DeliveryNote = Convert.ToInt32(tbWaybillNumber.Text), CustomerID = selectedCustomer.CustomerID, PaymentDate = dtpPaymentDate.Value }; // invoiceHeader. DbContextTransaction transaction = db.Database.BeginTransaction(); try { db.InvoiceHeaders.Add(invoiceHeader); db.SaveChanges(); ProductInputClear(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); MessageBox.Show("Beklenmeyen bir hata oluştu."); } }
private static void SeedInvoices(InvoiceContext context) { if (!context.Invoices.Any()) { context.Invoices.AddRange(new Invoice[] { new Invoice { InvoiceId = Guid.NewGuid(), Description = "Invoice #1", Supplier = "The Company", Amount = 1150.5m, Currency = "EUR", DateIssued = DateTime.Parse("2021-01-01 10:20:30"), }, new Invoice { InvoiceId = Guid.NewGuid(), Description = "Invoice #2", Supplier = "The Company", Amount = 99.5m, Currency = "USD", DateIssued = DateTime.Parse("2019-10-10 13:30:01"), }, new Invoice { InvoiceId = Guid.NewGuid(), Description = "Invoice #3", Supplier = "The Agency", Amount = 25.0m, Currency = "EUR", DateIssued = DateTime.Parse("2021-05-01 11:25:11"), }, }); context.SaveChanges(); } }
public void Insert(User User) { using (var context = new InvoiceContext()) { context.Users.Add(User); context.SaveChanges(); } }
public void Insert(UserType userType) { using (var context = new InvoiceContext()) { context.UserTypes.Add(userType); context.SaveChanges(); } }
public void Delete(int id) { using (var context = new InvoiceContext()) { var product = context.Products.Find(id); product.Enable = false; context.SaveChanges(); } }
public void Delete(int id) { using (var context = new InvoiceContext()) { var invoice = context.Invoices.Find(id); context.Invoices.Remove(invoice); context.SaveChanges(); } }
public void Insert(Invoice invoice) { using (var context = new InvoiceContext()) { invoice.Date = DateTime.Now; context.Invoices.Add(invoice); context.SaveChanges(); } }
public void Insert(Invoice Invoice) { using (var context = new InvoiceContext()) { Invoice.Date = DateTime.Today; context.Invoices.Add(Invoice); context.SaveChanges(); } }
public void Delete(int ID) { using (var context = new InvoiceContext()) { var Product = context.Products.Find(ID); context.Products.Remove(Product); context.SaveChanges(); } }
public void Delete(int id) { using (var context = new InvoiceContext()) { var detail = context.Details.Find(id); context.Details.Remove(detail); context.SaveChanges(); } }
public void Delete(int id) { using (var context = new InvoiceContext()) { var userType = context.UserTypes.Find(id); context.UserTypes.Remove(userType); context.SaveChanges(); } }
public void Update(UserType userType, int id) { using (var context = new InvoiceContext()) { var userTypeNew = context.UserTypes.Find(id); userTypeNew.UserTypeName = userType.UserTypeName == null ? userTypeNew.UserTypeName : userType.UserTypeName; context.SaveChanges(); } }
public void Update(Invoice Invoice, int ID) { using (var context = new InvoiceContext()) { var InvoiceNew = context.Invoices.Find(ID); InvoiceNew.InvoiceNumber = Invoice.InvoiceNumber == null ? InvoiceNew.InvoiceNumber : Invoice.InvoiceNumber; context.SaveChanges(); } }
private void btnAdd_Click(object sender, EventArgs e) { City city = new City(); city.Description = tbCityName.Text; db.Cities.Add(city); db.SaveChanges(); CityFill(); }
public void Insert(Detail Detail) { using (var context = new InvoiceContext()) { Detail.UserID = 1; context.Details.Add(Detail); context.SaveChanges(); } }