public int Create(ReceiptBody t) { int result = 0; try { //Initiate the instance of DBContext using BillingContext context = new BillingContext(); //check specific record for same ReceiptNo is exist or not var receipt = context.ReceiptBodies.FirstOrDefault(c => c.ReceiptNo == t.ReceiptNo); if (receipt == null) { //adding receiptbody object to context context.Add(t); //save changes return(result = context.SaveChanges()); } else { context.Update(t); return(result = context.SaveChanges()); } } catch (Exception ex) { Exc.ErMessage(ex); return(result = 0); } }
public Result <Component> Create(Component componentToCreate) { var componentDbo = new ComponentDbo { QuantityType = componentToCreate.QuantityType, UnitPrice = componentToCreate.UnitPrice, Description = componentToCreate.Description }; billingContext.Components.Add(componentDbo); var createdRows = billingContext.SaveChanges(); if (createdRows > 0) { componentToCreate.Id = componentDbo.Id; return(new Result <Component> { IsSuccess = true, Message = "Component successfully created!", Value = componentToCreate }); } return(new Result <Component> { IsSuccess = false, Message = "Component not created!" }); }
public Result <Customer> Create(Customer customerToCreate) { var customerDbo = new CustomerDbo { Phone = customerToCreate.Phone, Name = customerToCreate.Name, AdditionalInfo = customerToCreate.AdditionalInfo }; billingContext.Customers.AddIfNotExists(customerDbo, c => c.Phone == customerDbo.Phone); var createdRows = billingContext.SaveChanges(); if (createdRows > 0) { customerToCreate.Id = customerDbo.Id; return(new Result <Customer> { IsSuccess = true, Message = "Customer successfully created!", Value = customerToCreate }); } return(new Result <Customer> { IsSuccess = false, Message = "Customer not created!" }); }
public ActionResult AddCardPost([FromBody] Card c) { try { try { c.UserID = User.FindFirst(ClaimTypes.NameIdentifier).Value; } catch (NullReferenceException) { return(new StatusCodeResult(400)); } if (User.IsInRole("Customer")) { c.Type = "Customer"; } else { c.Type = "Staff"; } c.Active = true; db.Cards.Add(c); db.SaveChanges(); return(RedirectToAction(nameof(PayOrder))); } catch { return(new StatusCodeResult(500)); } }
public object Add(Domain.Bill item) { var entity = EntityFrom(item); logger.Log(context, "Bill", "Add", entity); context.Bills.Add(entity); context.SaveChanges(); return(entity.Id); }
private void btnBorrar_Click(object sender, EventArgs e) { var rowsSeleted = GridClientes.Rows.Cast <DataGridViewRow>().Where(x => x.Selected == true); foreach (var row in rowsSeleted) { db.Clientes.Remove(row.DataBoundItem as Cliente); clienteBindingSource.RemoveAt(row.Index); } db.SaveChanges(); }
// GET api/values public void Get(int id) { var address = new Address() { AddressId = 2, PostCode = "ST1 5HX", StreetName = "CenturyStreet" }; var order = new Order() { OrderId = 2, ItemName = "Laptop" }; var orders = new List <Order>(); var deliveraddress = new DeliveryAddress() { DevliverAddressID = 2, DeliveryAddressPostCode = "MK80BA", NickName = "MK- Addresss" }; address.DeliverAddress = deliveraddress; orders.Add(order); var customer = new Customer() { Name = "Danny", CustomerId = 2, CustomerAddress = address, orders = orders }; using (var context = new BillingContext()) { context.Database.Log = Console.WriteLine; context.Customers.Add(customer); context.SaveChanges(); } }
public IActionResult SaveOrder([FromBody] Order Order) { try { if (Order == null || Order.Products == null) { return(new StatusCodeResult(400)); } if (Order.Products.Count == 0) { return(new StatusCodeResult(400)); } foreach (BillingProduct bp in Order.Products) { db.Products.Add(bp); } db.Orders.Add(Order); db.SaveChanges(); return(StatusCode(200)); } catch { return(StatusCode(500)); } }
public int Create(Customer t) { int result = 0; try { //Initiate the instance of DBContext using BillingContext context = new BillingContext(); //check specific record for same Customer id is exist or not var cust = context.Customers.FirstOrDefault(c => c.CustomerId == t.CustomerId); if (cust == null) { //adding Customer object to context context.Add(t); //save changes return(result = context.SaveChanges()); } else { return(Update(t)); } } catch (Exception ex) { Exc.ErMessage(ex); return(result = 0); } }
private void BtnAgregar_Click(object sender, EventArgs e) { using (VendedorAddOrEdit frm = new VendedorAddOrEdit(new Modelos.Vendedor())) { if (frm.ShowDialog() == DialogResult.OK) { try { vendedorBindingSource.Add(frm.VendedorInfo); db.Vendedor.Add(frm.VendedorInfo); vendedorBindingSource.EndEdit(); db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void Add <T>(T entity, BillingContext context) where T : BaseEntity { if (entity.Id > 0) { context.Entry(entity).State = EntityState.Modified; } else { context.Entry(entity).State = EntityState.Added; } context.SaveChanges(); }
static void Main(string[] args) { int id; int customerId; decimal amount; using (var context = new ApplicationContext()) { Invoice invoice = context.Invoices.First(); id = invoice.Id; customerId = invoice.CustomerId; amount = invoice.Amount; } using (var context = new SalesContext()) { Order order = context.Orders.First(); Invoice invoice = order.Invoice; Console.WriteLine(invoice); } using (var context = new BillingContext()) { InvoiceReference invoiceReference = context.Invoices.First(); Console.WriteLine(invoiceReference); context.Invoices.Remove(invoiceReference); context.SaveChanges(); var newInvoiceReference = new InvoiceReference { Id = id, CustomerId = customerId, Amount = amount }; context.Invoices.Add(newInvoiceReference); context.SaveChanges(); } Console.ReadKey(); }
public Result <Good> Create(Good goodToCreate) { var goodDbo = new GoodDbo { QuantityType = goodToCreate.QuantityType, UnitPrice = goodToCreate.UnitPrice, Description = goodToCreate.Description }; var goodComponentLinks = goodToCreate.Components.Select(c => new GoodComponentLinkDbo { GoodId = goodDbo.Id, ComponentId = c.Id, Quantity = c.Quantity }).ToList(); goodDbo.GoodComponents = goodComponentLinks; billingContext.Goods.Add(goodDbo); var createdRows = billingContext.SaveChanges(); if (createdRows > 0) { goodToCreate.Id = goodDbo.Id; return(new Result <Good> { IsSuccess = true, Message = "Good successfully created!", Value = goodToCreate }); } return(new Result <Good> { IsSuccess = false, Message = "Good not created!" }); }
public int Update(ReceiptBody t) { int result = 0; try { using BillingContext context = new BillingContext(); context.Update(t); return(result = context.SaveChanges()); } catch (Exception ex) { Exc.ErMessage(ex); return(result); } }
public int Delete(ReceiptHeader t) { int result = 0; try { using BillingContext context = new BillingContext(); context.ReceiptHeaders.Remove(t); return(result = context.SaveChanges()); } catch (Exception ex) { Exc.ErMessage(ex); return(result); } }
/// <summary> /// Sets up some test only Db Objects. /// </summary> private void SetupTestingRecords() { using (var context = new BillingContext(options)) { var s1 = new Product() { Id = 8, Name = "Some Other Product", Price = 10, SKU = "somethingelse" }; var potterBooks = new List <Product> { s1 }; context.Add(s1); context.SaveChanges(); } }
/// <summary> /// In memory database seed /// </summary> private void SetupHarryPotterDiscounts() { using (var context = new BillingContext(options)) { // Products var p1 = new Product() { Id = 1, Name = "Harry Potter Book 1", Price = 10, SKU = "potter1", isHarryPotter = true }; var p2 = new Product() { Id = 2, Name = "Harry Potter Book 2", Price = 10, SKU = "potter2", isHarryPotter = true }; var p3 = new Product() { Id = 3, Name = "Harry Potter Book 3", Price = 10, SKU = "potter3", isHarryPotter = true }; var p4 = new Product() { Id = 4, Name = "Harry Potter Book 4", Price = 10, SKU = "potter4", isHarryPotter = true }; var p5 = new Product() { Id = 5, Name = "Harry Potter Book 5", Price = 10, SKU = "potter5", isHarryPotter = true }; var p6 = new Product() { Id = 6, Name = "Harry Potter Book 6", Price = 10, SKU = "potter6", isHarryPotter = true }; var p7 = new Product() { Id = 7, Name = "Harry Potter Book 7", Price = 10, SKU = "potter7", isHarryPotter = true }; var potterBooks = new List <Product> { p1, p2, p3, p4, p5, p6, p7 }; context.AddRange(potterBooks); // Discounts var d1 = new Discount() { Id = 1, MinProductsRequired = 2, Percent = 0.05 }; AddDiscountProduct(d1, p1); AddDiscountProduct(d1, p2); AddDiscountProduct(d1, p3); AddDiscountProduct(d1, p4); AddDiscountProduct(d1, p5); AddDiscountProduct(d1, p6); AddDiscountProduct(d1, p7); var d2 = new Discount() { Id = 2, MinProductsRequired = 3, Percent = 0.10, }; AddDiscountProduct(d2, p1); AddDiscountProduct(d2, p2); AddDiscountProduct(d2, p3); AddDiscountProduct(d2, p4); AddDiscountProduct(d2, p5); AddDiscountProduct(d2, p6); AddDiscountProduct(d2, p7); var d3 = new Discount() { Id = 3, MinProductsRequired = 4, Percent = 0.20 }; AddDiscountProduct(d3, p1); AddDiscountProduct(d3, p2); AddDiscountProduct(d3, p3); AddDiscountProduct(d3, p4); AddDiscountProduct(d3, p5); AddDiscountProduct(d3, p6); AddDiscountProduct(d3, p7); var d4 = new Discount() { Id = 4, MinProductsRequired = 5, Percent = 0.25 }; AddDiscountProduct(d4, p1); AddDiscountProduct(d4, p2); AddDiscountProduct(d4, p3); AddDiscountProduct(d4, p4); AddDiscountProduct(d4, p5); AddDiscountProduct(d4, p6); AddDiscountProduct(d4, p7); context.Add(d1); context.Add(d2); context.Add(d3); context.Add(d4); context.SaveChanges(); } }
public bool Commit() { return(_context.SaveChanges() > 0); }
public void Commit() { _context.SaveChanges(); }