public async Task <IActionResult> PutAddress(int id, Address address) { if (id != address.Id) { return(BadRequest()); } _context.Entry(address).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <AlarmFeed> CreateFeed(AlarmFeed feed) { _db.AlarmFeeds.Add(feed); await _db.SaveChangesAsync(); return(feed); }
public async Task <IActionResult> PutInvoice(int id, Invoice invoice) { if (id != invoice.Id) { return(BadRequest()); } _context.Entry(invoice).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutVendor(int id, Vendor vendor) { if (id != vendor.Id) { return(BadRequest()); } _context.Entry(vendor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VendorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <Printer> Create(Printer printer) { _db.Printers.Add(printer); await _db.SaveChangesAsync(); return(printer); }
public async Task <PointOfSale> Create(PointOfSale pos) { _db.PointOfSales.Add(pos); await _db.SaveChangesAsync(); return(pos); }
public async Task <SumUpAffiliate> CreateAffiliate(SumUpAffiliate affiliate) { _db.SumUpAffiliates.Add(affiliate); await _db.SaveChangesAsync(); return(affiliate); }
public async Task <Terminal> Create(Terminal terminal) { _db.Terminals.Add(terminal); await _db.SaveChangesAsync(); return(terminal); }
public async Task <Product> Create(Product product) { _db.Products.Add(product); await _db.SaveChangesAsync(); return(product); }
public async Task <IActionResult> Create([Bind("ID,Name,Description")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("ID,LastName,FirstName,Email,PhoneNo")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("ID,ProductName,Price,QuanitityPurchased,SubTotal")] MakeSales makeSales) { if (ModelState.IsValid) { _context.Add(makeSales); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(makeSales)); }
public async Task <ActionResult <Order> > Create(Order order) { order.Total = order.Lines.Sum(x => x.Total); order.AmountDue = order.Total - order.Payments.Sum(x => x.Amount); order.Created = LocalClock.Now; _db.Orders.Add(order); await _db.SaveChangesAsync(); return(order); }
public async Task <IActionResult> Create([Bind("ID,Name,Price,QuantityAvailable,CategoryID")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", product.CategoryID); return(View(product)); }
public async Task <IActionResult> Create([Bind("ID,ProductID,QuantityPurchased,SubTotal,DatePurchased,SalesID")] SalesDetail salesDetail) { if (ModelState.IsValid) { _context.Add(salesDetail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SalesID"] = new SelectList(_context.Sales, "ID", "ID");//salesDetail.SalesID return(View(salesDetail)); }
public async Task <Account> Create(Account account) { account.RemainingCredit = account.MaxCredit; account.Payments.Add(new Payment() { Method = PaymentMethod.Offset, Amount = -account.MaxCredit, Created = LocalClock.Now }); _db.Accounts.Add(account); await _db.SaveChangesAsync(); return(account); }
public async Task <ActionResult <Customer> > AddCustomer(Customer customer) { if (ModelState.IsValid) { // using (var context = new PosContext()) { var addedCustomer = await context.Customers.AddAsync(customer); await context.SaveChangesAsync(); return(addedCustomer.Entity); } } return(BadRequest(ModelState)); }
public async Task <ActionResult <Serving> > Create(int orderId, Serving serving) { var order = await _db.Orders .Include(x => x.Lines) .FirstOrDefaultAsync(x => x.Id == orderId); if (order == null) { return(NotFound()); } var newestTag = await _db.OrderTags .OrderByDescending(x => x.Attached) .FirstOrDefaultAsync(x => x.OrderId == order.Id && x.Detached == null); serving.OrderId = orderId; serving.State = ServingState.Pending; serving.TagNumber = newestTag?.Number; serving.Created = LocalClock.Now; var orderLinesById = order.Lines.ToDictionary(x => x.Id, x => x); var position = 0; foreach (var servingLine in serving.Lines) { if (orderLinesById.TryGetValue(servingLine.OrderLineId, out var orderLine)) { servingLine.Position = position++; servingLine.Name = orderLine.Name; // Adjust receivable on order line orderLine.Receiveable = Math.Max(orderLine.Receiveable - servingLine.Quantity, 0); } else { return(BadRequest()); } } _db.Servings.Add(serving); await _db.SaveChangesAsync(); await _mediator.Publish(new ServingCreatedNotification(serving.Id)); return(serving); }
public async Task <ActionResult <Order> > Create(Order order) { order.Total = order.Lines.Sum(x => x.Total); order.AmountDue = order.Total - order.Payments.Sum(x => x.Amount); order.Created = LocalClock.Now; var position = 0; foreach (var line in order.Lines) { line.Position = position++; } _db.Orders.Add(order); await _db.SaveChangesAsync(); return(order); }
public async Task Handle(OrderPayedNotification notification, CancellationToken cancellationToken) { var order = await _db.Orders .Include(x => x.Lines) .FirstAsync(x => x.Id == notification.OrderId); var payment = await _db.Payments .Include(x => x.Account) .FirstAsync(x => x.Id == notification.PaymentId); var highPriority = payment.Method == PaymentMethod.Account && payment.Account.HighPriorityServing; var servingLines = order.Lines .OrderBy(x => x.Position) .Where(x => x.IsServing) .Select((line, index) => new ServingLine() { Position = index, OrderLineId = line.Id, Name = line.Name, Quantity = line.Quantity - line.Receiveable }) .Where(x => x.Quantity > 0) .ToList(); if (servingLines.Count > 0) { var newestTag = await _db.OrderTags .OrderByDescending(x => x.Attached) .FirstOrDefaultAsync(x => x.OrderId == order.Id && x.Detached == null); var serving = new Serving() { OrderId = order.Id, PointOfSaleId = order.PointOfSaleId, State = ServingState.Pending, HighPriority = highPriority, Created = LocalClock.Now, TagNumber = newestTag?.Number, Lines = servingLines.ToList() }; _db.Servings.Add(serving); await _db.SaveChangesAsync(); await _mediator.Publish(new ServingCreatedNotification(serving.Id)); } }
public async Task Handle(ServingUpdatedNotification notification, CancellationToken cancellationToken) { var serving = await _db.Servings.FirstAsync(x => x.Id == notification.ServingId); if (serving.State == ServingState.Completed) { var now = LocalClock.Now; var tags = await _db.OrderTags.Where(x => x.OrderId == serving.OrderId && x.Detached == null).ToListAsync(); foreach (var tag in tags) { tag.Detached = now; } await _db.SaveChangesAsync(); } }
public async Task <ActionResult <Payment> > Create(int orderId, Payment payment) { var order = await _db.Orders.FirstOrDefaultAsync(x => x.Id == orderId); if (order == null) { return(NotFound()); } if (payment.Method == PaymentMethod.Account) { if (payment.AccountId == null) { return(BadRequest()); } var account = await _db.Accounts.FirstOrDefaultAsync(x => x.Id == payment.AccountId); if (account.RemainingCredit >= payment.Amount) { account.RemainingCredit -= payment.Amount; } else { return(Conflict()); } } payment.Created = LocalClock.Now; order.Payments.Add(payment); order.AmountDue -= payment.Amount; await _db.SaveChangesAsync(); if (order.AmountDue == 0) { await _mediator.Publish(new OrderPayedNotification(order.Id, payment.Id)); } return(payment); }
public async Task Handle(OrderTagAssignedNotification notification, CancellationToken cancellationToken) { var servings = await _db.Servings .Where(x => x.OrderId == notification.OrderId && x.State == ServingState.Pending && x.TagNumber == null) .ToListAsync(); if (servings.Count > 0) { var notifications = new List <INotification>(servings.Count); foreach (var serving in servings) { serving.TagNumber = notification.TagNumber; notifications.Add(new ServingUpdatedNotification(serving.Id)); } await _db.SaveChangesAsync(); await Task.WhenAll(notifications.Select(x => _mediator.Publish(x))); } }