예제 #1
0
        public void FindReceiptInclude()
        {
            Receipt receipt = new Receipt
            {
                Book = new Book {
                    Author = "Автор", Id = 1, Name = "Name"
                },
                BookId     = 1,
                Date       = DateTime.Now,
                UserId     = 1,
                DateReturn = DateTime.Now,
                Id         = 1,
                User       = new User {
                    Birthday = DateTime.Now, Id = 1, Name = "Name"
                }
            };

            _repository = new ReceiptRepository(new LibContext());
            _repository.Create(receipt);
            // Act
            var result = _repository.FindReceiptInclude(receipt.Id);

            // Assert
            Assert.IsNotNull(result);
        }
예제 #2
0
        public IActionResult Create(ReceiptVM receiptVM)
        {
            var create = _receiptRepository.Create(receiptVM);

            if (create > 0)
            {
                return(Ok(create));
            }
            return(BadRequest("Can't be created"));
        }
예제 #3
0
        public Receipt Checkout(int shoppingCartId)
        {
            var shoppingCart = _shoppingCartRepository.GetById(shoppingCartId);
            var receipt      = _receiptRepository.Create();

            receipt.ShoppingCartId = shoppingCartId;
            receipt.ShoppingItems  = shoppingCart.ShoppingItems;
            receipt.TotalPrice     = shoppingCart.ShoppingItems.Sum(i => i.TotalPrice);

            return(receipt);
        }
예제 #4
0
        public ReceiptDto CreateReceipt(PaymentCommand payment)
        {
            try
            {
                string        itemList      = JsonConvert.SerializeObject(payment.ItemList);
                ReceiptEntity receiptEntity = new ReceiptEntity()
                {
                    ShiftId              = payment.ShiftId,
                    StoreEmail           = payment.StoreEmail,
                    ItemList             = itemList,
                    Discount             = payment.Discount,
                    IsDiscountPercentage = payment.IsDiscountPercentage,
                    Total         = payment.Total,
                    TotalDiscount = payment.TotalDiscount,
                    PaymentType   = payment.PaymentType
                };

                _receiptRepository.Create(receiptEntity);

                receiptEntity.Reference = GenerateRef(payment.ShiftId, receiptEntity.Id);

                _receiptRepository.Update(receiptEntity);

                var storeName = _storeRepository.GetStoreByEmail(payment.StoreEmail).StoreName;


                return(new ReceiptDto()
                {
                    Reference = receiptEntity.Reference,
                    ShiftId = payment.ShiftId,
                    Store = storeName,
                    ItemList = JsonConvert.DeserializeObject <List <DtoModels.Sale.OrderItemModel> >(itemList),
                    Discount = payment.Discount,
                    IsDiscountPercentage = payment.IsDiscountPercentage,
                    Total = payment.Total,
                    TotalDiscount = payment.TotalDiscount,
                    CreateDateTime = receiptEntity.CreateDateTime,
                    PaymentType = payment.PaymentType
                });
            }
            catch (Exception e)
            {
                return(null);
            }
        }