Exemple #1
0
        protected override DriverResult Display(BidsPart part, string displayType, dynamic shapeHelper)
        {
            return(Combined(
                       ContentShape("Parts_ListOfBids", () => {
                var settings = part.Settings.GetModel <BidsPartSettings>();

                var list = shapeHelper.List();
                var bids = part
                           .Bids
                           .OrderByDescending(b => b.BidPrice)
                           .AsQueryable();

                if (settings.DefaultBidsShown > 0)
                {
                    bids = bids.Take(settings.DefaultBidsShown);
                }

                list.AddRange(bids.ToList().Select(b => _contentManager.BuildDisplay(b)));

                return shapeHelper.Parts_ListOfBids(List: list);
            }),
                       ContentShape("Parts_BidForm", () => {
                var minimumBid = part.MinimumBidPrice;
                var heighestBid = _bidService.GetHeighestBid(part.Id);
                if (heighestBid != null && heighestBid.BidPrice > minimumBid)
                {
                    minimumBid = heighestBid.BidPrice;
                }

                var newBid = _contentManager.New("Bid");
                if (newBid.Has <BidPart>())
                {
                    var bidPart = newBid.As <BidPart>();
                    bidPart.BidedOn = part.Id;
                }

                var editorShape = _contentManager.BuildEditor(newBid);

                return shapeHelper.Parts_BidForm(EditorShape: editorShape, CanStillBid: _bidService.CanStillBidOn(part), MinimumBid: minimumBid);
            })));
        }
Exemple #2
0
        public ActionResult Create(string returnUrl)
        {
            if (!_services.Authorizer.Authorize(Permissions.AddBid, T("Couldn't add bid")))
            {
                return(this.RedirectLocal(returnUrl, "~/"));
            }

            var bid         = _services.ContentManager.New <BidPart>("Bid");
            var editorShape = _services.ContentManager.UpdateEditor(bid, this);

            if (ModelState.IsValid)
            {
                _services.ContentManager.Create(bid);

                var bidPart = bid.As <BidPart>();

                // Check if bid is higher than others
                var heighestBid = _bidService.GetHeighestBid(bid.BidedOn);
                if (bidPart.BidPrice <= heighestBid.BidPrice && bidPart.Id != heighestBid.Id)
                {
                    _services.TransactionManager.Cancel();
                    _notifier.Error(T("Bid must be higher than {0}", heighestBid.BidPrice.ToString("c")));
                    AddEditorShapeToTempData(editorShape);
                    return(this.RedirectLocal(returnUrl, "~/"));
                }

                // Check if bid is higher than minimum bid
                var bidsPart     = _bidService.GetContainer(bidPart);
                var minimumPrice = bidsPart.MinimumBidPrice;
                if (bidPart.BidPrice <= minimumPrice)
                {
                    _services.TransactionManager.Cancel();
                    _notifier.Error(T("Bid must be higher than {0}", minimumPrice.ToString("c")));
                    AddEditorShapeToTempData(editorShape);
                    return(this.RedirectLocal(returnUrl, "~/"));
                }

                // Ensure the bids are not closed on the container, as the html could have been tampered manually
                if (!_bidService.CanCreateBid(bidPart))
                {
                    _services.TransactionManager.Cancel();
                    return(this.RedirectLocal(returnUrl, "~/"));
                }

                _notifier.Information(T("Your Bid has been added."));

                if (bidsPart.NotificationEmail)
                {
                    _bidService.SendNotificationEmail(bidPart);
                }
            }
            else
            {
                // Used a comma instead of a point, or the other way around
                _notifier.Error(T("Invalid format"));
                _services.TransactionManager.Cancel();

                AddEditorShapeToTempData(editorShape);
            }

            return(this.RedirectLocal(returnUrl, "~/"));
        }