Пример #1
0
        public bool AddPurchase(IEnumerable <ProductModel> orderedProducts, string userId)
        {
            var lineitemsEntities = Mapping.Mapper.Map <IEnumerable <ProductEntity> >(orderedProducts);
            var fullProducts      = _productRepository.GetPurchaseProducts(lineitemsEntities.Select(t => t.Id).Distinct().ToArray());

            var newPurchaseId   = GeneratePurchaseId();
            var totalCalculated = GetTotal(fullProducts, orderedProducts);


            var newPurchase = new PurchaseModel()
            {
                Id           = newPurchaseId,
                UserId       = userId,
                CreationDate = DateTime.UtcNow,
                IsConfirmed  = false,
                IsProcessed  = false,
                Total        = totalCalculated,
                TotalCount   = orderedProducts.Sum(t => t.Count)
            };

            var purchaseEntity = Mapping.Mapper.Map <PurchaseEntity>(newPurchase);

            var result         = _purchaseRepository.AddPurchase(purchaseEntity);
            int lineItemResult = 0;

            if (result > 0)
            {
                var lineItems = GetLineItems(fullProducts, orderedProducts, newPurchaseId);
                lineItemResult = _lineItemRepository.AddLineItems(lineItems);
            }

            return(result > 0 && lineItemResult > 0);
        }
Пример #2
0
        public IActionResult CreateTransaction(TransactionDetails inputDetails)
        {
            User currentUser = _customerList.GetUserByUsername(HttpContext.Session.GetString("Username"));

            IEnumerable <Cart> userCart = _cartList.GetCartItemsByUser(currentUser);

            foreach (var Item in userCart)
            {
                if (Item.Movie.MovieInventory == 0)
                {
                    ViewBag.Result = Item.Movie.MovieTitle + " Is not longer in stock, please remove from cart or try again at a later date.";
                    return(RedirectToAction("DisplayCart"));
                }
            }
            foreach (var cartItem in userCart)
            {
                Transaction newTransaction = _transactionList.CreateTransaction(cartItem.Movie, currentUser, cartItem.IsRental);
                _transactionDetailsList.AddTransactionDetails(inputDetails, newTransaction);

                if (cartItem.IsRental)
                {
                    _rentalList.AddRental(newTransaction);
                }
                else
                {
                    _purchaseList.AddPurchase(newTransaction);
                };
                cartItem.Movie.MovieInventory--;
            }
            ;

            _context.SaveChanges();
            return(RedirectToAction("DisplayOrderConfirmation"));
        }
Пример #3
0
 public int AddPurchase(PurchaseFullDto purchase)
 {
     var item = new DbPurchaseFull();
     item.PlanYear = purchase.PlanYear; 
     
     return _purchaseRepo.AddPurchase(item);
 }
Пример #4
0
 public void AddPurchase(PurchaseDTO p)
 {
     repository.AddPurchase(new Purchase
     {
         UserId      = p.UserId,
         EventSeatId = p.EventSeatId
     });
 }
Пример #5
0
        public void AddPurchase(AppUser buyer, Ad ad, int units)
        {
            IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ControllerContext);
            Purchase   purchase  = new Purchase {
                Buyer = buyer, Ad = ad, Units = units, DateTime = DateTime.Now
            };

            purchaseRepository.AddPurchase(purchase);

            ad.UnitsAvailable -= units;
            adRepository.Update(ad);

            notificationRepository.AddNotification(
                new Notification {
                User     = buyer,
                Message  = $"Successfuly purchased {units} unit(s) of {ad.Product}",
                Link     = urlHelper.Action("ShowPurchases", "Buyer"),
                DateTime = DateTime.Now,
                Type     = NotificationType.Success
            });

            notificationRepository.AddNotification(
                new Notification {
                User     = ad.User,
                Message  = $"{units} unit(s) of {ad.Product} have been sold",
                Link     = urlHelper.Action("ShowSales", "Seller"),
                DateTime = DateTime.Now,
                Type     = NotificationType.Success
            });

            if (ad.UnitsAvailable == 0)
            {
                notificationRepository.AddNotification(
                    new Notification {
                    User     = ad.User,
                    Message  = $"All units of {ad.Product} have been sold, do you have more?",
                    Link     = urlHelper.Action("EditAd", "Seller", new { id = ad.Id }),
                    DateTime = DateTime.Now,
                    Type     = NotificationType.Warning
                });
            }
        }
Пример #6
0
        public ActionResult <bool> Add(Purchase purchase)
        {
            Purchase result = _repository.AddPurchase(purchase);

            return(Ok(result));
        }
Пример #7
0
 public string AddPurchase(string no, int staff, int dep, int supplier, int type, int status, string remark)
 {
     return(_purchaseRepository.AddPurchase(no, staff, dep, supplier, type, status, remark));
 }
        public IActionResult Post(PurchaseVM purchase)
        {
            var result = purchases.AddPurchase(purchase);

            return(Ok(result));
        }