Exemplo n.º 1
0
 public async Task SetProductOrdersToReceiptAsync(ProductReceipt productReceipt)
 {
     productReceipt.ProductOrders = await this.dbContext.ProductOrders
                                    .Where(order => order.Status.Name == GlobalConstants.StatusActive &&
                                           order.IssuerId == productReceipt.RecipientId)
                                    .ToListAsync();
 }
Exemplo n.º 2
0
        public void CheckoutOrderWithRepeatingItemsTest()
        {
            //--Arrange
            Product sampleItem1 = new Product("Apple", (decimal)0.75, (decimal)0.25);
            Product sampleItem2 = new Product("Apple", (decimal)0.75, (decimal)0.25);

            Order order = new Order(new List <Product>()
            {
                sampleItem1,
                sampleItem2
            });

            ProductReceipt productReceipt1 = new ProductReceipt();

            productReceipt1.Discount  = sampleItem1.Discount;
            productReceipt1.Price     = sampleItem1.Price;
            productReceipt1.Quantity  = 2;
            productReceipt1.ItemTotal = (productReceipt1.Quantity * (productReceipt1.Price - productReceipt1.Discount));

            Hashtable expectedParameter = new Hashtable();

            expectedParameter.Add(sampleItem1.Name, productReceipt1);

            //--Act
            _checkoutService.Checkout(order);

            //--Assert
            _kioskPrinterMock.Verify(x => x.PrintReceipt(expectedParameter), Times.Once);
        }
 public static ProductReceiptViewModel ToProductReceiptViewModel(this ProductReceipt receipt)
 {
     return(new ProductReceiptViewModel
     {
         Id = receipt.Id,
         Name = receipt.Product.Name,
         Price = receipt.Price,
         Quantity = receipt.Quantity
     });
 }
        public IActionResult AddProductReceipt(ProductReceipt productReceiptToAdd)
        {
            var wasAddSuccessful = _productReceiptRepository.AddProductReceipts(productReceiptToAdd);

            if (wasAddSuccessful)
            {
                return(Ok());
            }
            return(Forbid());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add a new product receipt by given parameters.
        /// </summary>
        /// <param name="receiptId">Give the id of the receipt to add.</param>
        /// <param name="productCode">Give the code of the product to add.</param>
        /// <param name="quantityString">Give the quantity of the product to add.</param>
        /// <param name="discountString">Give the discount of the product to add
        /// if it has been given.</param>
        public void Add(int receiptId, string productCode, string quantityString, string discountString)
        {
            decimal quantity;
            bool    canQuantityBeParsed = decimal.TryParse(quantityString, out quantity);
            int     discountPercentage;
            bool    canDiscountBeParsed = int.TryParse(discountString, out discountPercentage);

            // Validation for quanity.
            if (!canQuantityBeParsed || !canDiscountBeParsed)
            {
                throw new ArgumentException("Wrong values for quantity/discount");
            }
            if (quantity <= 0)
            {
                throw new ArgumentException("Quantity must be positive.");
            }
            if (discountPercentage < 0)
            {
                throw new ArgumentException("Discount must NOT be negative.");
            }

            var product = this.eazyCartContext.Products.FirstOrDefault(x => x.Code == productCode);

            if (product.Quantity < quantity)
            {
                throw new ArgumentException("Insufficient quantity");
            }
            // When the Unit is 'Unit', the quantity must be a whole number.
            if (Math.Ceiling(quantity) != quantity && product.UnitId == 1)
            {
                throw new ArgumentException("Quantity must be a whole number");
            }

            Receipt        receipt        = this.eazyCartContext.Receipts.Last();
            ProductReceipt productReceipt = new ProductReceipt
            {
                Id                 = receiptId,
                Quantity           = quantity,
                DiscountPercentage = discountPercentage,
                ProductCode        = productCode,
                ReceiptId          = receipt.Id
            };

            var allProductReceiptsWithGivenId = this.eazyCartContext.ProductsReceipts.Where(x => x.Id == receiptId);

            if (allProductReceiptsWithGivenId.Count() > 0)
            {
                throw new ArgumentException("Such productReceipt is already added.");
            }

            this.eazyCartContext.ProductsReceipts.Add(productReceipt);
            this.eazyCartContext.SaveChanges();
        }
        public void PrintReceipt(Hashtable orderHash)
        {
            DateTime localDate = DateTime.Now;
            decimal  subtotal  = 0;
            decimal  discounts = 0;
            int      itemCount = 0;

            Console.WriteLine("");
            Console.WriteLine("++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine($"{localDate.DayOfWeek} {localDate.ToString("MMMM")} {localDate.Day}, {localDate.Year}\t{localDate.ToString("h:mm tt")}");
            Console.WriteLine("");
            foreach (DictionaryEntry productKeyValuePair in orderHash)
            {
                ProductReceipt productItemReceipt = (ProductReceipt)productKeyValuePair.Value;
                string         productName        = (string)productKeyValuePair.Key;

                subtotal  += (productItemReceipt.Price * productItemReceipt.Quantity);
                discounts += (productItemReceipt.Discount * productItemReceipt.Quantity);
                itemCount += productItemReceipt.Quantity;

                Console.WriteLine(productName);
                Console.WriteLine($"\tRegular price: ${productItemReceipt.Price}");
                if (productItemReceipt.Discount > 0)
                {
                    Console.WriteLine($"\tPrice after discount: ${productItemReceipt.Price - productItemReceipt.Discount}");
                }
                Console.WriteLine($"\tQuantity: {productItemReceipt.Quantity}");
                Console.WriteLine($"\tItem total: ${productItemReceipt.ItemTotal}");
                Console.WriteLine("");
            }
            Console.WriteLine("======================================");
            Console.WriteLine($"Subtotal ({itemCount} items):\t\t ${subtotal}");
            if (discounts > 0)
            {
                Console.WriteLine($"Discount:\t\t\t-${discounts}");
            }
            Console.WriteLine("--------------------------------------");
            Console.WriteLine($"Total:\t\t\t\t ${subtotal - discounts}");
            Console.WriteLine("======================================");
            Console.WriteLine("");
            Console.WriteLine(" Thank you for shopping at GroceryCo. ");
            Console.WriteLine("++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine("");
        }
        public async Task <int> CreateProductReceiptAsync(string recipientId)
        {
            var productReceipt = new ProductReceipt
            {
                IssuedOnPicture = null,
                RecipientId     = recipientId,
            };

            await this.ordersService.SetProductOrdersToReceiptAsync(productReceipt);

            foreach (var productOrder in productReceipt.ProductOrders)
            {
                await this.ordersService.CompleteProductOrdersAsync(productOrder.Id);
            }

            await this.dbContext.ProductReceipts.AddAsync(productReceipt);

            await this.dbContext.SaveChangesAsync();

            return(productReceipt.Id);
        }
Exemplo n.º 8
0
        public bool AddProductReceipts(ProductReceipt productReceiptToAdd)
        {
            var product = _context.Products.FirstOrDefault(pro => pro.Id == productReceiptToAdd.ProductId);
            var receipt = _context.Receipts.FirstOrDefault(rec => rec.Id == productReceiptToAdd.ReceiptId);

            if (product == null || receipt == null)
            {
                return(false);
            }

            if (productReceiptToAdd.Amount < 0 || productReceiptToAdd.PriceAtTheTime < 0 ||
                productReceiptToAdd.Name.Length < 1 || productReceiptToAdd.Tax < 0)
            {
                return(false);
            }

            _context.Add(productReceiptToAdd);
            _context.SaveChanges();

            return(true);
        }
Exemplo n.º 9
0
        public async Task <ActionResult> addProduct(string QualificationShortName, string AssessmentIndentifier,
                                                    string AssessmentName, int AssessmentVersion, string ComponentIdentifier, string ComponentName, int ComponentVersion,
                                                    string SessionIdentifier, string Name, string Timeframe,
                                                    string StartDate, string StartDatePart, string EndDate,
                                                    string QuestionPaperIdentifier, string Barcode, string QuestionPaperPartName, string MarkingType, string NameQP, int PageCount, string SyllabusCode)
        {
            string markingTypeCreated = "MFI";
            string RMKey1             = WebServiceDetails.RMKey;

            AssessmentStructureWS.AssessmentStructureWS test = new AssessmentStructureWS.AssessmentStructureWS();

            ProductArguments productArguments = new ProductArguments();
            ProductReceipt   productReceipt   = new ProductReceipt();

            ProductArgumentsProduct       productArgumentsProduct       = new ProductArgumentsProduct();
            ProductArgumentsSession       productArgumentsSession       = new ProductArgumentsSession();
            ProductArgumentsExam          productArgumentsExam          = new ProductArgumentsExam();
            ProductArgumentsQuestionPaper productArgumentsQuestionPaper = new ProductArgumentsQuestionPaper();


            productArgumentsProduct.BusinessStreamIndentifier = WebServiceDetails.BusinessStreamIndentifier;
            productArgumentsProduct.QualificationShortName    = QualificationShortName;
            productArgumentsProduct.AssessmentIndentifier     = AssessmentIndentifier;
            productArgumentsProduct.AssessmentName            = AssessmentName;
            productArgumentsProduct.AssessmentVersion         = AssessmentVersion;
            productArgumentsProduct.ComponentIdentifier       = ComponentIdentifier;
            productArgumentsProduct.ComponentName             = ComponentName;
            productArgumentsProduct.ComponentVersion          = ComponentVersion;

            productArgumentsSession.SessionIdentifier = SessionIdentifier;
            productArgumentsSession.Name      = Name;
            productArgumentsSession.Timeframe = Timeframe;

            productArgumentsExam.StartDate     = Convert.ToDateTime(StartDate);
            productArgumentsExam.StartDatePart = StartDatePart;
            productArgumentsExam.EndDate       = Convert.ToDateTime(EndDate);


            productArgumentsQuestionPaper.QuestionPaperIdentifier = QuestionPaperIdentifier;
            productArgumentsQuestionPaper.Barcode = Barcode;
            productArgumentsQuestionPaper.QuestionPaperPartName = QuestionPaperPartName;
            productArgumentsQuestionPaper.MarkingType           = markingTypeCreated;
            productArgumentsQuestionPaper.Name         = NameQP;
            productArgumentsQuestionPaper.PageCount    = PageCount;
            productArgumentsQuestionPaper.SyllabusCode = SyllabusCode;

            productArguments.Product       = productArgumentsProduct;
            productArguments.Session       = productArgumentsSession;
            productArguments.Exam          = productArgumentsExam;
            productArguments.QuestionPaper = productArgumentsQuestionPaper;

            productReceipt = test.Product(RMKey1, productArguments);

            if (productReceipt.Success)
            {
                AddCenterCandidate(SessionIdentifier, AssessmentIndentifier, AssessmentVersion, ComponentIdentifier, ComponentVersion, QuestionPaperIdentifier, QuestionPaperPartName);

                using (var db = new RM_GDEContext())
                {
                    db.Product.Add(new Product
                    {
                        QualificationShortName = QualificationShortName,
                        AssessmentIndentifier  = AssessmentIndentifier,
                        AssessmentName         = AssessmentName,
                        AssessmentVersion      = AssessmentVersion,
                        ComponentIdentifier    = ComponentIdentifier,
                        ComponentName          = ComponentName,
                        ComponentVersion       = ComponentVersion
                    });

                    db.QuestionPaper.Add(new QuestionPaper
                    {
                        QuestionPaperIdentifier = QuestionPaperIdentifier,
                        Barcode = Barcode,
                        QuestionPaperPartName = QuestionPaperPartName,
                        MarkingType           = markingTypeCreated,
                        SyllabusCode          = SyllabusCode,
                        CreatedDate           = DateTime.Now

                                                //Add to Table later
                                                //Name = NameQP,
                                                //PageCount = PageCount,
                    });

                    db.Session.Add(new Session
                    {
                        SessionIdentifier = SessionIdentifier,
                        Name      = Name,
                        Timeframe = Timeframe
                    });

                    db.Exam.Add(new Exam
                    {
                        StartDate     = Convert.ToDateTime(StartDate),
                        StartDatePart = StartDatePart,
                        EndDate       = Convert.ToDateTime(EndDate)
                    });

                    await db.SaveChangesAsync();

                    var listOfSessions = db.QuestionPaper.ToList();
                    return(View("Index", listOfSessions));
                }
            }
            return(View("Index"));
        }