public ActionResult Create(NewAuctionViewModel auction)
        {
            if (this.ModelState.IsValid)
            {
                var members = new SimpleMemberService(this.mainRepository);

                var newAuction = new Auction()
                {
                    Title            = auction.Title,
                    Description      = auction.Description,
                    StartDateTimeUtc = auction.StartDateTimeUtc,
                    EndDateTimeUtc   = auction.EndDateTimeUtc,
                    StartPrice       = auction.StartPrice,
                    Seller           = members.GetCurrentMember()
                };

                // Get File Contents
                if (auction.Image != null)
                {
                    byte[] fileContent = new byte[auction.Image.InputStream.Length];
                    auction.Image.InputStream.Read(fileContent, 0, fileContent.Length);

                    newAuction.Image = fileContent;
                }

                this.service.Save(newAuction);
            }

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public App()
        {
            this.MainRepository = new FileSystemMainRepository("appdata.json");
            this.MainRepository.SaveChanges();

            var memberService = new SimpleMemberService(this.MainRepository);
            var service       = new AuctionService(this.MainRepository, memberService);

            if (!service.GetAll().Any())
            {
                var me = memberService.GetCurrentMember();

                service.Save(new Auction
                {
                    Title            = "My First Auction",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 72,
                    Seller           = me
                });
            }

            this.AuctionRunner = new AuctionRunner(this.MainRepository);
            this.AuctionRunner.Start();
        }
예제 #3
0
        public ActionResult Create(
            [Bind(Include = "StartPrice,Title,Description,StartDateTimeUtc,EndDateTimeUtc,Image")]
            NewAuctionViewModel viewAuction)
        {
            if (this.ModelState.IsValid)
            {
                var members = new SimpleMemberService(this.mainRepository);

                var auction = new Auction()
                {
                    Title            = viewAuction.Title,
                    Description      = viewAuction.Description,
                    StartPrice       = viewAuction.StartPrice,
                    StartDateTimeUtc = viewAuction.StartDateTimeUtc,
                    EndDateTimeUtc   = viewAuction.EndDateTimeUtc,
                    Seller           = members.GetCurrentMember(),
                };

                if (viewAuction.Image != null)
                {
                    byte[] fileContent = new byte[viewAuction.Image.InputStream.Length];
                    viewAuction.Image.InputStream.Read(fileContent, 0, fileContent.Length);

                    auction.Image = fileContent;
                }

                this.service.Save(auction);
                return(RedirectToAction("Index"));
            }

            return(View());
        }
예제 #4
0
        public BidView(Auction auction)
        {
            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);
        }
예제 #5
0
        public SellView()
        {
            InitializeComponent();
            var app            = Application.Current as App;
            var memberService  = new SimpleMemberService(app.MainRepository);
            var auctionService = new AuctionService(app.MainRepository, memberService);

            DataContext = new SellViewModel(memberService, auctionService);
        }
예제 #6
0
        public void GettingCurrentMemberTwice_IsSame()
        {
            var repo    = new InMemoryMainRepository();
            var service = new SimpleMemberService(repo);

            var currentMember1 = service.GetCurrentMember();
            var currentMember2 = service.GetCurrentMember();

            Assert.AreEqual(currentMember1, currentMember2);
        }
예제 #7
0
        public void WhenAddingAnAuction_WithUnknownMember_RaisesException()
        {
            var auction = CreateGeneratedAuction();

            var repo = new InMemoryMainRepository();

            var memberService = new SimpleMemberService(repo);
            var service       = new AuctionService(repo, memberService);

            service.Save(auction);
        }
예제 #8
0
        public MainWindow()
        {
            var app = Application.Current as App;

            InitializeComponent();

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

            this.DataContext = new MainViewModel(app.AuctionRunner.Auctioneer, auctionService);
        }
예제 #9
0
        public MainWindow()
        {
            InitializeComponent();
            //this.DataContext = this;
            var app = Application.Current as App;

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

            this.DataContext = new MainViewModel(memberService, _auctionService);
        }
예제 #10
0
        public void WhenMemberIsNotInRepo_GetCurrentUser_AlwaysGetAMember()
        {
            var repo    = new InMemoryMainRepository();
            var service = new SimpleMemberService(repo);

            var currentMember = service.GetCurrentMember();

            Assert.NotNull(currentMember);
            Assert.IsNotNullOrEmpty(currentMember.DisplayName);
            Assert.IsNotNullOrEmpty(currentMember.EMail);
        }
예제 #11
0
        public BidView(Auction selectedAuction)
        {
            this.selectedAuction = selectedAuction;
            this.InitializeComponent();

            this.DataContext = this;

            var app = Application.Current as App;

            this.simpleMemberService = new SimpleMemberService(app.MainRepository);
            this.auctionService      = new AuctionService(app.MainRepository, simpleMemberService);

            this.YourBid = Math.Max(this.SelectedAuction.CurrentPrice, this.SelectedAuction.StartPrice);
        }
예제 #12
0
        public SellView()
        {
            InitializeComponent();
            this.DataContext = this;

            var app           = Application.Current as App;
            var memberService = new SimpleMemberService(app.MainRepository);

            this._auctionService = new AuctionService(app.MainRepository, memberService);
            this._auctionNew     = new Auction();
            this._auctionNew.StartDateTimeUtc = DateTime.Now;
            this._auctionNew.EndDateTimeUtc   = DateTime.Now;
            this._auctionNew.Seller           = memberService.GetCurrentMember();
        }
예제 #13
0
        public void PlacingABid_AuctionHasNotYetStarted_RaisesException()
        {
            var repo = new InMemoryMainRepository();
            var simpleMemberService = new SimpleMemberService(repo);
            var auction             = CreateGeneratedAuction();

            auction.Seller = simpleMemberService.GetCurrentMember();

            var service = new AuctionService(repo, simpleMemberService);

            auction.StartDateTimeUtc = DateTime.UtcNow.AddDays(1);
            service.Save(auction);

            service.PlaceBid(auction, 100);
        }
예제 #14
0
        public void GivenAProperService_SavesAValidAuction_ShouldReturnSameFromAuctionList()
        {
            var repo        = new InMemoryMainRepository();
            var userService = new SimpleMemberService(repo);
            var service     = new AuctionService(repo, userService);

            var auction = CreateGeneratedAuction();

            auction.Seller = userService.Add("Seller", "*****@*****.**");

            service.Save(auction);

            var auctionFromService = service.GetAll().First();

            Assert.AreEqual(auctionFromService, auction);
        }
예제 #15
0
        public void PlacingABid_AuctionHasExpired_RaisesException()
        {
            var repo = new InMemoryMainRepository();
            var simpleMemberService = new SimpleMemberService(repo);
            var auction             = CreateGeneratedAuction();

            auction.Seller = simpleMemberService.GetCurrentMember();

            var service = new AuctionService(repo, simpleMemberService);

            auction.StartDateTimeUtc = DateTime.UtcNow.AddDays(-2);
            auction.EndDateTimeUtc   = DateTime.UtcNow.AddDays(-2);

            repo.Add(auction);

            Assert.Throws <AuctionStateException>(() => service.PlaceBid(auction, 100));
        }
예제 #16
0
        public App()
        {
            MainRepository = new FileSystemMainRepository("Repo1.rp");
            AuctionRunner  = new AuctionRunner(MainRepository);
            AuctionRunner.Start();

            MemberService  = new SimpleMemberService(this.MainRepository);
            AuctionService = new AuctionService(this.MainRepository, MemberService);
            if (!AuctionService.GetAll().Any())
            {
                var me = MemberService.GetCurrentMember();
                AuctionService.Save(new Auction
                {
                    Title = "My First Auction", StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10), EndDateTimeUtc = DateTime.UtcNow.AddDays(14), StartPrice = 72, Seller = me
                });
            }
        }
예제 #17
0
        public App()
        {
            var serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);

            _serviceProvider = serviceCollection.BuildServiceProvider();

            this._mainRepository = new FileSystemMainRepository("fileName");
            this._auctionRunnter = new AuctionRunner(this._mainRepository);

            var memberService = new SimpleMemberService(this._mainRepository);
            var service       = new AuctionService(this._mainRepository, memberService);

            if (!service.GetAll().Any())
            {
                var me = memberService.GetCurrentMember();
                service.Save(new Auction
                {
                    Title            = "My First Auction",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 72,
                    Seller           = me
                });
                service.Save(new Auction
                {
                    Title            = "My Second Auction",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 200,
                    Seller           = me
                });
                service.Save(new Auction
                {
                    Title            = "My Third Auction",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 5000,
                    Seller           = me
                });
            }

            this._auctionRunnter.Start();
        }
예제 #18
0
        private void InitializeTestData()
        {
            var memberService = new SimpleMemberService(this.MainRepository);
            var service       = new AuctionService(this.MainRepository, memberService);

            if (!service.GetAll().Any())
            {
                var me = memberService.GetCurrentMember();
                service.Save(new Auction
                {
                    Title            = "My First Auction",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 72,
                    Seller           = me
                });
            }
        }
예제 #19
0
        public App()
        {
            String path = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\\..\\"));

            this.MainRepository = new FileSystemMainRepository(path + @"data\data.json");
            this.MainRepository.SaveChanges();

            var memberService = new SimpleMemberService(this.MainRepository);
            var service       = new AuctionService(this.MainRepository, memberService);

            if (!service.GetAll().Any())
            {
                var me = memberService.GetCurrentMember();

                service.Save(new Auction
                {
                    Title            = "Kaputtes Auto",
                    Description      = "This is a description",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 72,
                    Image            = File.ReadAllBytes(path + @"data\img\auto.jpg"),
                    Seller           = me,
                    IsClosed         = true,
                    IsRunning        = false
                });
                service.Save(new Auction
                {
                    Title            = "Haufen Schrott",
                    Description      = "This is a description",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 3000,
                    Image            = File.ReadAllBytes(path + @"data\img\schrott.jpg"),
                    Seller           = me,
                    IsClosed         = false,
                    IsRunning        = true
                });
            }


            this.AuctionRunner = new AuctionRunner(this.MainRepository);
            this.AuctionRunner.Start();
        }
예제 #20
0
        public SellView()
        {
            this.InitializeComponent();

            this.DataContext = this;

            var app = Application.Current as App;

            var simpleMemberService = new SimpleMemberService(app.MainRepository);

            this.auctionService  = new AuctionService(app.MainRepository, simpleMemberService);
            this.FilePathToImage = "<select image with extension jpg>";
            this.newAuction      = new Auction()
            {
                Seller           = simpleMemberService.GetCurrentMember(),
                StartDateTimeUtc = DateTime.UtcNow,
                EndDateTimeUtc   = DateTime.UtcNow.AddDays(7)
            };
        }
예제 #21
0
        public SellView()
        {
            InitializeComponent();

            // Set Data-Context to this Window
            this.DataContext = this;

            // Set initial Data for Auction
            var app = Application.Current as App;

            if (app != null)
            {
                var simpleMemberService = new SimpleMemberService(app.MainRepository);
                this.auctionService = new AuctionService(app.MainRepository, simpleMemberService);
                this.newAuction     = new Auction
                {
                    Seller           = simpleMemberService.GetCurrentMember(),
                    StartDateTimeUtc = DateTime.UtcNow,
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(7)
                };
            }
        }
예제 #22
0
        public App()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            this.AuctionRunner = new AuctionRunner(this.MainRepository);
            this.AuctionRunner.Start();

            var memberService = new SimpleMemberService(this.MainRepository);
            var service       = new AuctionService(this.MainRepository, memberService);

            if (!service.GetAll().Any())
            {
                var me = memberService.GetCurrentMember();

                service.Save(new Auction
                {
                    Title            = "My First Auction",
                    StartDateTimeUtc = DateTime.UtcNow.AddSeconds(10),
                    EndDateTimeUtc   = DateTime.UtcNow.AddDays(14),
                    StartPrice       = 72,
                    Seller           = me
                });
            }
        }
 public MockedMemberService(InMemoryMainRepository repo)
 {
     this.repo          = repo;
     this.userService   = new SimpleMemberService(this.repo);
     this.currentMember = this.userService.GetCurrentMember();
 }