예제 #1
0
        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());
        }
예제 #2
0
        public async Task <AlarmFeed> CreateFeed(AlarmFeed feed)
        {
            _db.AlarmFeeds.Add(feed);
            await _db.SaveChangesAsync();

            return(feed);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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());
        }
예제 #5
0
        public async Task <Printer> Create(Printer printer)
        {
            _db.Printers.Add(printer);

            await _db.SaveChangesAsync();

            return(printer);
        }
예제 #6
0
        public async Task <PointOfSale> Create(PointOfSale pos)
        {
            _db.PointOfSales.Add(pos);

            await _db.SaveChangesAsync();

            return(pos);
        }
예제 #7
0
        public async Task <SumUpAffiliate> CreateAffiliate(SumUpAffiliate affiliate)
        {
            _db.SumUpAffiliates.Add(affiliate);

            await _db.SaveChangesAsync();

            return(affiliate);
        }
예제 #8
0
        public async Task <Terminal> Create(Terminal terminal)
        {
            _db.Terminals.Add(terminal);

            await _db.SaveChangesAsync();

            return(terminal);
        }
예제 #9
0
        public async Task <Product> Create(Product product)
        {
            _db.Products.Add(product);

            await _db.SaveChangesAsync();

            return(product);
        }
예제 #10
0
        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));
        }
예제 #11
0
        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));
        }
예제 #12
0
        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));
        }
예제 #13
0
        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);
        }
예제 #14
0
        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));
        }
예제 #16
0
        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);
        }
예제 #17
0
        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));
        }
예제 #18
0
        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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        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();
            }
        }
예제 #22
0
        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);
        }
예제 #23
0
        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)));
            }
        }