Пример #1
0
        public AuctionViewModel PlaceBid(string username, AuctionViewModel auctionViewModel)
        {
            if (UserSameAsSeller(username, auctionViewModel))
            {
                throw new InvalidOperationException("Users are not allowed to bid for their own auctions");
            }

            if (BidAmountIsLessThanMinAmount(auctionViewModel))
            {
                throw new ArgumentException("Bid must not be less than minimum amount for auction item");
            }

            var user = GetUser(username);

            if (user == null)
            {
                throw new ArgumentException($"User {username} doesn't exist");
            }

            var seller = GetUser(auctionViewModel.Seller);

            if (seller == null)
            {
                throw new ArgumentException($"User {auctionViewModel.Seller} doesn't exist");
            }

            return(_auctionRepository.PlaceBid(user, auctionViewModel.ToAuction(seller), float.Parse(auctionViewModel.BidAmount)).ToAuctionViewModel());
        }
Пример #2
0
        public AuctionViewModel CloseAuction(AuctionViewModel auctionViewModel)
        {
            var user = GetUser(auctionViewModel.Seller);

            if (user == null)
            {
                throw new ArgumentException($"User {auctionViewModel.Seller} doesn't exist");
            }

            return(_auctionRepository.CloseAuction(auctionViewModel.ToAuction(user)).ToAuctionViewModel());
        }
Пример #3
0
        public AuctionViewModel CreateAuction(AuctionViewModel auctionViewModel)
        {
            if (auctionViewModel == null)
            {
                throw new ArgumentNullException($"AuctionItemViewModel must be provided");
            }

            var user = GetUser(auctionViewModel.Seller);

            if (user == null)
            {
                throw new ArgumentException($"User {auctionViewModel.Seller} doesn't exist");
            }

            var auction = _auctionRepository.CreateAuction(auctionViewModel.ToAuction(user));

            _auditRepository.CreateRecord(auctionViewModel.Seller, auction.AuctionId.ToString(), "Auction created");

            return(auction.ToAuctionViewModel());
        }