示例#1
0
        protected PurchaseItemViewModel BuildItemViewModelWithReplenishmentOnFirstReplDate(DateTime nextReplenishmentDate)
        {
            var itemViewModel = new PurchaseItemViewModel()
            {
                ItemId = 2,
                Name = "Brownies",
                NextReplenishmentDate = nextReplenishmentDate,
                ReplenishmentDate = new DateTime(2020, 10, 01),
                Quantity = "7",
                ReplenishmentSignalClass = string.Empty
            };

            return itemViewModel;
        }
示例#2
0
        protected PurchaseItemViewModel BuildNonUrgentItemViewModel(DateTime nextReplenishmentDate)
        {
            var itemViewModel = new PurchaseItemViewModel()
            {
                ItemId = 3,
                Name = "Yoghurt",
                NextReplenishmentDate = nextReplenishmentDate,
                ReplenishmentDate = new DateTime(2020, 10, 01),
                Quantity = "3",
                ReplenishmentSignalClass = string.Empty
            };

            return itemViewModel;
        }
示例#3
0
        protected PurchaseItemViewModel BuildUrgentReplenishmentItemViewModel(DateTime nextReplenishmentDate)
        {
            var itemViewModel = new PurchaseItemViewModel()
            {
                ItemId = 1,
                Name = "Popcorn",
                NextReplenishmentDate = nextReplenishmentDate,
                ReplenishmentDate = new DateTime(2020, 10, 01),
                Quantity = "3",
                ReplenishmentSignalClass = "itemNeedsReplenishment"
            };

            return itemViewModel;
        }
        public ActionResult orderHistory()
        {
            String CurrentUserId = User.Identity.GetUserId();
            var    query         = from p in db.Purchases
                                   where p.isPurchased == true && p.PurchaseUser.Id == CurrentUserId
                                   orderby p.PurchaseDate descending
                                   select p;

            List <Purchase>     PurchasedCartList = query.ToList();
            List <PurchaseItem> PurcahseItems     = new List <PurchaseItem>();

            foreach (Purchase p in PurchasedCartList)
            {
                foreach (PurchaseItem pi in p.PurchaseItems)
                {
                    PurcahseItems.Add(pi);
                }
            }

            //End Calc Subtotals
            List <PurchaseItemViewModel> PIDisplay = new List <PurchaseItemViewModel>();

            foreach (PurchaseItem pi in PurcahseItems)
            {
                if (pi.isAlbum)
                {
                    PurchaseItemViewModel PIVM = new PurchaseItemViewModel();
                    PIVM.PurchaseItem       = pi;
                    PIVM.PurchaseItemRating = getAverageAlbumRating(pi.PurchaseItemAlbum.AlbumID).ToString("0.0");
                    PIDisplay.Add(PIVM);
                }
                else
                {
                    PurchaseItemViewModel PIVM = new PurchaseItemViewModel();
                    PIVM.PurchaseItem       = pi;
                    PIVM.PurchaseItemRating = getAverageSongRating(pi.PurchaseItemSong.SongID).ToString("0.0");
                    PIDisplay.Add(PIVM);
                }
            }
            return(View(PIDisplay));
        }
        public ActionResult Index()
        {
            String CurrentUserId = User.Identity.GetUserId();
            var    query         = from p in db.Purchases
                                   where p.isPurchased == false && p.PurchaseUser.Id == CurrentUserId
                                   select p;

            List <Purchase> ActiveCartList = query.ToList();

            if (ActiveCartList.Count() == 1)
            {
                Purchase ActiveCartPurchase = new Purchase();
                ActiveCartPurchase = ActiveCartList[0];
                List <Album> Albums = new List <Album>();
                foreach (PurchaseItem pi in ActiveCartPurchase.PurchaseItems)
                {
                    if (pi.isAlbum)
                    {
                        Albums.Add(pi.PurchaseItemAlbum);
                    }
                }
                if (checkDuplicates(Albums))
                {
                    ViewBag.DuplicateMessage = "Remove duplicate items before checking out";
                }
                //CalcSubtotals
                decimal subtotal         = 0;
                decimal discountSubtotal = -1;
                bool    hasDiscount      = false;
                decimal taxTotal         = 0;
                decimal tax        = .0825m;
                decimal grandTotal = 0;
                foreach (PurchaseItem pi in ActiveCartPurchase.PurchaseItems)
                {
                    if (pi.Equals(null))
                    {
                        continue;
                    }
                    else if (pi.isAlbum)
                    {
                        subtotal += pi.PurchaseItemAlbum.AlbumPrice;
                        if (pi.PurchaseItemAlbum.isDiscounted)
                        {
                            discountSubtotal += pi.PurchaseItemAlbum.DiscountAlbumPrice;
                            hasDiscount       = true;
                        }
                        else
                        {
                            discountSubtotal += pi.PurchaseItemAlbum.AlbumPrice;
                        }
                    }
                    else
                    {
                        subtotal += pi.PurchaseItemSong.SongPrice;
                        if (pi.PurchaseItemSong.isDiscoutned)
                        {
                            discountSubtotal += pi.PurchaseItemSong.DiscountPrice;
                            hasDiscount       = true;
                        }
                        else
                        {
                            discountSubtotal += pi.PurchaseItemSong.SongPrice;
                        }
                    }
                }
                if (hasDiscount)
                {
                    discountSubtotal += 1;
                    taxTotal          = tax * discountSubtotal;
                    grandTotal        = discountSubtotal + taxTotal;
                }
                else
                {
                    discountSubtotal = -1;
                    taxTotal         = tax * subtotal;
                    grandTotal       = subtotal + taxTotal;
                }
                ViewBag.hasDiscount      = hasDiscount;
                ViewBag.subtotal         = subtotal.ToString("c");
                ViewBag.discountSubtotal = discountSubtotal.ToString("c");
                ViewBag.Savings          = (subtotal - discountSubtotal).ToString("c");
                ViewBag.taxTotal         = taxTotal.ToString("c");
                ViewBag.GrandTotal       = grandTotal.ToString("c");
                //End Calc Subtotals
                List <PurchaseItemViewModel> PIDisplay            = new List <PurchaseItemViewModel>();
                List <PurchaseItem>          currentPurchaseItems = ActiveCartPurchase.PurchaseItems.ToList();
                foreach (PurchaseItem pi in currentPurchaseItems)
                {
                    if (pi.isAlbum)
                    {
                        PurchaseItemViewModel PIVM = new PurchaseItemViewModel();
                        PIVM.PurchaseItem       = pi;
                        PIVM.PurchaseItemRating = getAverageAlbumRating(pi.PurchaseItemAlbum.AlbumID).ToString("0.0");
                        PIDisplay.Add(PIVM);
                    }
                    else
                    {
                        PurchaseItemViewModel PIVM = new PurchaseItemViewModel();
                        PIVM.PurchaseItem       = pi;
                        PIVM.PurchaseItemRating = getAverageSongRating(pi.PurchaseItemSong.SongID).ToString("0.0");
                        PIDisplay.Add(PIVM);
                    }
                }


                return(View(PIDisplay));
            }
            else
            {
                Purchase newPurchase = new Purchase();
                newPurchase.PurchaseUser = db.Users.Find(CurrentUserId);
                db.Purchases.Add(newPurchase);
                db.SaveChanges();
                var query2 = from p in db.Purchases
                             where p.isPurchased == false && p.PurchaseUser.Id == CurrentUserId
                             select p;
                List <Purchase> newPurchaseList = query2.ToList();
                Purchase        dbNewPurchase   = newPurchaseList[0];
                //ViewModel Code Start
                List <PurchaseItemViewModel> PIDisplay = new List <PurchaseItemViewModel>();
                ViewBag.subtotal         = 0.ToString("c");
                ViewBag.discountSubtotal = 0.ToString("c");
                ViewBag.taxTotal         = 0.ToString("c");
                ViewBag.GrandTotal       = 0.ToString("c");
                ViewBag.hasDiscount      = false;
                return(View(PIDisplay));
            }
        }
        public ActionResult Refund(Int32 PurchaseId)
        {
            String CurrentUserId = User.Identity.GetUserId();
            var    query         = from p in db.Purchases
                                   where p.PurchaseID == PurchaseId
                                   select p;

            List <Purchase> ActiveCartList     = query.ToList();
            Purchase        ActiveCartPurchase = new Purchase();

            ActiveCartPurchase = ActiveCartList[0];
            List <Album> Albums = new List <Album>();

            foreach (PurchaseItem pi in ActiveCartPurchase.PurchaseItems)
            {
                if (pi.isAlbum)
                {
                    Albums.Add(pi.PurchaseItemAlbum);
                }
            }
            //CalcSubtotals
            decimal subtotal         = 0;
            decimal discountSubtotal = -1;
            bool    hasDiscount      = false;
            decimal taxTotal         = 0;
            decimal tax        = .0825m;
            decimal grandTotal = 0;

            foreach (PurchaseItem pi in ActiveCartPurchase.PurchaseItems)
            {
                if (pi.Equals(null))
                {
                    continue;
                }
                else if (pi.isAlbum)
                {
                    subtotal += pi.PurchaseItemAlbum.AlbumPrice;
                    if (pi.PurchaseItemAlbum.isDiscounted)
                    {
                        discountSubtotal += pi.PurchaseItemAlbum.DiscountAlbumPrice;
                        hasDiscount       = true;
                    }
                    else
                    {
                        discountSubtotal += pi.PurchaseItemAlbum.AlbumPrice;
                    }
                }
                else
                {
                    subtotal += pi.PurchaseItemSong.SongPrice;
                    if (pi.PurchaseItemSong.isDiscoutned)
                    {
                        discountSubtotal += pi.PurchaseItemSong.DiscountPrice;
                        hasDiscount       = true;
                    }
                    else
                    {
                        discountSubtotal += pi.PurchaseItemSong.SongPrice;
                    }
                }
            }
            if (hasDiscount)
            {
                discountSubtotal += 1;
                taxTotal          = tax * discountSubtotal;
                grandTotal        = discountSubtotal + taxTotal;
            }
            else
            {
                discountSubtotal = -1;
                taxTotal         = tax * subtotal;
                grandTotal       = subtotal + taxTotal;
            }
            ViewBag.hasDiscount      = hasDiscount;
            ViewBag.subtotal         = subtotal.ToString("c");
            ViewBag.discountSubtotal = discountSubtotal.ToString("c");
            ViewBag.Savings          = (subtotal - discountSubtotal).ToString("c");
            ViewBag.taxTotal         = taxTotal.ToString("c");
            ViewBag.GrandTotal       = grandTotal.ToString("c");
            //End Calc Subtotals
            List <PurchaseItemViewModel> PIDisplay            = new List <PurchaseItemViewModel>();
            List <PurchaseItem>          currentPurchaseItems = ActiveCartPurchase.PurchaseItems.ToList();

            foreach (PurchaseItem pi in currentPurchaseItems)
            {
                if (pi.isAlbum)
                {
                    PurchaseItemViewModel PIVM = new PurchaseItemViewModel();
                    PIVM.PurchaseItem       = pi;
                    PIVM.PurchaseItemRating = getAverageAlbumRating(pi.PurchaseItemAlbum.AlbumID).ToString("0.0");
                    PIDisplay.Add(PIVM);
                }
                else
                {
                    PurchaseItemViewModel PIVM = new PurchaseItemViewModel();
                    PIVM.PurchaseItem       = pi;
                    PIVM.PurchaseItemRating = getAverageSongRating(pi.PurchaseItemSong.SongID).ToString("0.0");
                    PIDisplay.Add(PIVM);
                }
            }


            return(View(PIDisplay));
        }
        public ReplenishmentDto BuildReplenishmentDto(DateTime firstReplenishmentDate, DateTime secondReplenishmentDate, PurchaseItemViewModel viewModel)
        {
            var dto = _mapper.Map <PurchaseItemViewModel, PurchaseItemDto>(viewModel);

            var replenishmentModel = GetReplenishmentDtoWithBasicProperties(firstReplenishmentDate, secondReplenishmentDate);

            replenishmentModel.Purchaseitems.Add(dto);
            return(replenishmentModel);
        }