Пример #1
0
        public void AddAuction(object sender, RoutedEventArgs e)
        {
            var repo = ((App) Application.Current).MainRepository;
            var memberService = new SimpleMemberService(repo);
            var service = new AuctionService(repo, memberService);

            var title = this.Title.Text;
            var description = this.Description.Text;
            var startdate = DateTime.Parse(this.Start.Text);
            var enddate = DateTime.Parse(this.End.Text);
            var price = double.Parse(this.StartPrice.Text);
            var member = memberService.GetCurrentMember();
            var image = this.Image.Text;
            var imageArr = File.ReadAllBytes(image);

            var auction = new Auction
            {
                Title = title,
                StartDateTimeUtc = startdate,
                EndDateTimeUtc = enddate,
                StartPrice = price,
                Seller = member,
                Image = imageArr,
                Description = description
            };

            service.Save(auction);
            this.Auctions.Add(auction);
            this.Cancel(sender, e);
        }
        public Bid PlaceBid(Auction auction, double amount)
        {
            var auct = this.mainRepository.GetAuctions().ToList().FirstOrDefault(a => a.Id == auction.Id && a == auction);

            var bidder = this.memberService.GetCurrentMember();

            if (auct == null)
            {
                throw new MissingAuctionException("This auction does not exist in the store");
            }

            if (auct.StartDateTimeUtc > DateTime.UtcNow)
            {
                throw new AuctionStateException("The requested auction has not started yet");
            }

            if (auct.EndDateTimeUtc <= DateTime.UtcNow)
            {
                throw new AuctionStateException("The requested auction has already closed");
            }

            var bid = new Bid()
            {
                ReceivedOnUtc = DateTime.UtcNow,
                Accepted = null,
                Auction = auct,
                Amount = amount,
                Bidder = bidder
            };

            this.mainRepository.Add(bid);
            this.mainRepository.SaveChanges();

            return bid;
        }
Пример #3
0
        public AuctionViewModel(Auction auction)
        {
            this.auction = auction;

            this.AddBidCommand = new RelayCommand(this.AddBidAction);

            this.Apply();
        }
Пример #4
0
        private void ApplyChanges(Auction auction)
        {
            var auctionViewModel = this.auctions.FirstOrDefault(vm => vm.Auction == auction);

            if (auctionViewModel != null)
            {
                auctionViewModel.Update(auction);
            }
        }
Пример #5
0
        public BidView(Auction auction)
        {
            this.InitializeComponent();

            var app = Application.Current as App;

            var memberService = new SimpleMemberService(app.MainRepository);
            var auctionService = new AuctionService(app.MainRepository, memberService);

            this.DataContext = new BidViewModel(auction, memberService, auctionService);
        }
Пример #6
0
        public BidViewModel(Auction selectedAuction, IMemberService memberService, IAuctionService auctionService)
        {
            this.memberService = memberService;
            this.auctionService = auctionService;
            this.selectedAuction = selectedAuction;

            this.CloseDialogCommand = new RelayCommand<Window>(this.CloseAction);
            this.AddBidAndCloseCommand = new RelayCommand<Window>(this.AddBidAndCloseAction);

            // Default Values
            this.YourBid = Math.Max(this.selectedAuction.CurrentPrice, this.selectedAuction.StartPrice);
        }
        public Auction Save(Auction auction)
        {
            if (this.mainRepository.GetAuctions().Any(a => a.Id == auction.Id))
            {
                var updatedAuction = this.mainRepository.Update(auction);
                this.mainRepository.SaveChanges();

                return updatedAuction;
            }

            this.ValidateNewAuctionAndThrowOnError(auction);

            var newAuction = this.mainRepository.Add(auction);
            this.mainRepository.SaveChanges();

            return newAuction;
        }
        private void AddAuction(object sender, RoutedEventArgs e)
        {
            try
            {
                var auction = new Auction
                {
                    Title = model.Title,
                    Description = model.Description,
                    StartPrice = double.Parse(model.StartPrice),
                    StartDateTimeUtc = model.StartDate,
                    EndDateTimeUtc = model.EndDate,
                    Image = File.ReadAllBytes(model.ImagePath),
                    Seller = App.MemberService.GetCurrentMember()
                };

                App.AuctionService.Save(auction);
                this.Close();
            }
            catch (Exception ex)
            {
                model.Errors = ex.Message;
            }
        }
        private static Auction CreateAndStoreAuction(InMemoryMainRepository repo, DateTime startDateTimeUtc, DateTime endDateTimeUtc)
        {
            var seller = new Member() { DisplayName = "Seller", UniqueId = Guid.NewGuid().ToString() };
            var auction = new Auction() { Title = "TestAuction", Seller = seller, StartPrice = 50, StartDateTimeUtc = startDateTimeUtc, EndDateTimeUtc = endDateTimeUtc };

            repo.Add(seller);
            repo.Add(auction);

            Assert.AreEqual(1, repo.GetAuctions().Count());
            Assert.AreEqual(1, repo.GetMembers().Count());

            return auction;
        }
        private static void AddInitialBidToAuction(InMemoryMainRepository repo, Auction auction)
        {
            var bidder = new Member() { DisplayName = "Bidder1", UniqueId = Guid.NewGuid().ToString() };
            repo.Add(bidder);

            repo.Add(new Bid() { ReceivedOnUtc = DateTime.UtcNow, Auction = auction, Amount = auction.StartPrice + 10, Bidder = bidder });
        }
Пример #11
0
 public Auction Update(Auction auction)
 {
     return auction;
 }
Пример #12
0
        public Auction Add(Auction auction)
        {
            this.context.Auctions.Add(auction);

            return auction;
        }
Пример #13
0
 public BidView(Auction auction)
 {
     this.auction = auction;
     this.DataContext = auction;
     this.InitializeComponent();
 }
 public void AddAuctionAndNotify(Auction a)
 {
     auctionService.Save(a);
 }
        private void ValidateNewAuctionAndThrowOnError(Auction auction)
        {
            if (auction == null)
            {
                throw new ArgumentException("Auction cannot be null", "auction");
            }

            if (auction.StartDateTimeUtc < DateTime.UtcNow)
            {
                throw new ArgumentException("The start of the auction needs to be in the future", "auction");
            }

            if (auction.EndDateTimeUtc < DateTime.UtcNow)
            {
                throw new ArgumentException("The end of the auction needs to be in the future", "auction");
            }

            if (auction.Bids != null && auction.Bids.Any())
            {
                throw new ArgumentException("A new auction cannot have bids", "auction");
            }

            if (auction.Seller == null)
            {
                throw new ArgumentException("The Seller of an auction cannot be null", "auction");
            }

            if (this.memberService.GetByUniqueId(auction.Seller.UniqueId) == null)
            {
                throw new ArgumentException("The seller cannot be cound and has to be created before using it in a auction", "auction");
            }

            if (auction.Winner != null)
            {
                throw new ArgumentException("The Winner of an auction cannot be known at the begin of an auction", "auction");
            }

            if (auction.StartPrice < 0)
            {
                throw new ArgumentException("Negative startprices are not allowed", "auction");
            }

            if (string.IsNullOrEmpty(auction.Title))
            {
                throw new ArgumentException("Every auction needs a title", "auction");
            }
        }
Пример #16
0
 public void Update(Auction auction)
 {
     this.auction = auction;
     this.Apply();
 }