Ejemplo n.º 1
0
        public void Walker_CreateWalkerAd()
        {
            Walker   Walker   = (Walker)UserFactory.CreateWalker("Walker123", "testnaLozinka", "Ivan", "Horvat", "123456789", "Unska 3", "Zagreb", 40, UserType.WALKER, true, false);
            WalkerAd WalkerAd = (WalkerAd)AdFactory.CreateWalkerAd(40.0, "Setam pse POVOLJNO", AdStatus.ACTIVE,
                                                                   "Obozavam pse", new DateTime(2019, 8, 28, 12, 5, 0), 3, 4, Walker);

            Walker.AddAd((WalkerAd)WalkerAd);

            UserRepository repository = new UserRepository();

            repository.AddUser(Walker);

            Debug.Assert(WalkerAd.Equals(Walker.Ads[0]));

            repository.DeleteUser(Walker);
        }
Ejemplo n.º 2
0
        public Ad CreateAd(IAdView AdView, IUserRepository UserRepository, User CurrentUser)
        {
            AdView.AdjustCreateView();
            double   Price       = AdView.Price;
            DateTime Date        = DateTime.Now.Date;
            string   Description = AdView.Description;
            string   Title       = AdView.Title;
            AdStatus AdStatus    = AdStatus.ACTIVE;
            int      DogsNumber  = AdView.DogsNumber;
            int      Hours       = AdView.Hours;

            Ad Ad;

            if (Description == "" || Title == "")
            {
                MessageBox.Show("Obvezno je ispuniti sva polja");
                return(null);
            }
            if (Price <= 0 || DogsNumber <= 0 || Hours <= 0)
            {
                MessageBox.Show("Broj godina/Cijena/Broj pasa ne može manji ili jednak 0");
                return(null);
            }


            if (CurrentUser.UserType == UserType.WALKER)
            {
                Ad = AdFactory.CreateWalkerAd(Price, Title, AdStatus, Description, Date, DogsNumber, Hours, (Walker)CurrentUser);
                Walker Walker = (Walker)CurrentUser;
                Walker.AddAd((WalkerAd)Ad);
                UserRepository.UpdateUser(Walker);
            }
            else
            {
                Ad = AdFactory.CreateOwnerAd(Price, Title, AdStatus, Description, Date, DogsNumber, Hours, (Owner)CurrentUser);
                Owner Owner = (Owner)CurrentUser;
                Owner.AddAd((OwnerAd)Ad);
                UserRepository.UpdateUser(Owner);
            }

            var form = (Form)AdView;

            form.Hide();

            return(Ad);
        }