Esempio n. 1
0
        public void Owner_CreateOwnerAd()
        {
            Owner   Owner   = (Owner)UserFactory.CreateOwner("Owner123", "testnaLozinka", "Ivan", "Horvat", "123456789", "Unska 3", "Zagreb", 40, UserType.OWNER);
            OwnerAd OwnerAd = (OwnerAd)AdFactory.CreateOwnerAd(40.0, "Setam pse POVOLJNO", AdStatus.ACTIVE,
                                                               "Obozavam pse", new DateTime(2019, 8, 28, 12, 5, 0), 3, 4, Owner);

            Owner.AddAd((OwnerAd)OwnerAd);

            UserRepository repository = new UserRepository();

            repository.AddUser(Owner);

            Debug.Assert(OwnerAd.Equals(Owner.Ads[0]));
            repository.DeleteUser(Owner);
        }
Esempio 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);
        }