Пример #1
0
        public LiqPayViewModelTests()
        {
            navigationServiceMock = new Mock <INavigationService>();
            dialogServiceMock     = new Mock <IPageDialogService>();

            cardNumber     = "1234 5678 1234 5678";
            expirationDate = "12/34";
            cvv2           = "123";

            buyTicketResponseDto = new BuyTicketResponseDto();

            ticketsServiceMock = new Mock <ITicketsService>();
            ticketsServiceMock
            .Setup(ts => ts.RequestBuyTicketAsync(It.IsAny <BuyTicketRequestDto>()))
            .ReturnsAsync(buyTicketResponseDto);

            liqPayViewModel = new LiqPayViewModel(navigationServiceMock.Object, dialogServiceMock.Object, ticketsServiceMock.Object);
        }
Пример #2
0
        public async Task <IActionResult> buyProduct([FromBody] InvoiceItem invoiceItemFake)
        {
            int    companyID    = invoiceItemFake.InvoiceID;//kostil
            int    productID    = invoiceItemFake.ProductID;
            int    quantity     = invoiceItemFake.ProductQuantity;
            string path         = @"A:\Универ\3 курс\WriteText.txt";
            var    invoiceItems = getCompanyInvoiceItems(companyID);



            int havingQuantity = 0;

            foreach (var ii in invoiceItems)
            {
                if (ii.ProductID == productID)
                {
                    havingQuantity += ii.ProductQuantity;
                }
            }



            if (havingQuantity < quantity)
            {
                return(BadRequest(ModelState));
            }



            //foreach (var ii in invoiceItems)
            //{


            //    var invoiceItem1 = await _context.InvoiceItems.SingleOrDefaultAsync(m => m.ID == ii.ID);
            //    invoiceItem1.ProductQuantity -= 1;
            //    _context.Entry(invoiceItem1).State = EntityState.Modified;
            //    await _context.SaveChangesAsync();
            //}

            foreach (var ii in invoiceItems)
            {
                if (ii.ProductID == productID)
                {
                    if (quantity >= ii.ProductQuantity)
                    {
                        quantity -= ii.ProductQuantity;
                        //DeleteInvoiceItem
                        var invoiceItem1 = await _context.InvoiceItems.SingleOrDefaultAsync(m => m.ID == ii.ID);

                        if (invoiceItem1 == null)
                        {
                            return(NotFound());
                        }

                        _context.InvoiceItems.Remove(invoiceItem1);
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        var invoiceItem1 = await _context.InvoiceItems.SingleOrDefaultAsync(m => m.ID == ii.ID);

                        invoiceItem1.ProductQuantity      -= quantity;
                        _context.Entry(invoiceItem1).State = EntityState.Modified;
                        await _context.SaveChangesAsync();

                        break;
                    }
                }
            }

            var data = CreateDefaultTestRequest();

            LiqPayViewModel lpvm = new LiqPayViewModel();

            lpvm.data      = data["data"];
            lpvm.signature = data["data"];
            return(Ok(data));
        }