Ejemplo n.º 1
0
        private void RemoveCategory(IRepositoryFactory repositoryFactory)
        {
            int id       = UnitOfView.Catalog.GetCategoryId(repositoryFactory);
            var category = repositoryFactory.Categories.Get(id);

            repositoryFactory.Categories.Remove(category);
            repositoryFactory.Complete();
        }
Ejemplo n.º 2
0
        private void EditCategory(IRepositoryFactory repositoryFactory)
        {
            int id       = UnitOfView.Catalog.GetCategoryId(repositoryFactory);
            var category = repositoryFactory.Categories.Get(id);

            category.Name = UnitOfView.Catalog.GetCategoryName();
            repositoryFactory.Complete();
        }
Ejemplo n.º 3
0
        private void AddProducts(IRepositoryFactory db)
        {
            UserInputSequenceView customerView = new UserInputSequenceView();
            string  name = customerView.SingleWordSeter(1, 20);
            Product produktRepository = new Product(name);

            db.Products.Add(produktRepository);
            db.Complete();
        }
Ejemplo n.º 4
0
        private void AddCategory(IRepositoryFactory repositoryFactory)
        {
            Category newCategory = new Category();

            newCategory.Name        = UnitOfView.Catalog.GetCategoryName();
            newCategory.IsAvailable = UnitOfView.Catalog.IsCategoryAvailable();
            newCategory.Products    = new List <Product>();
            repositoryFactory.Categories.Add(newCategory);
            repositoryFactory.Complete();
        }
Ejemplo n.º 5
0
        private void EditProduct(IRepositoryFactory db, Product product)
        {
            UserInputSequenceView userInputSequenceView = new UserInputSequenceView();

            product.Name     = userInputSequenceView.MultipleWordSeter(1, 30);
            product.Price    = Convert.ToDecimal(userInputSequenceView.InputUser());
            product.Quantity = userInputSequenceView.NumberSeter(1, 1000);
            db.Products.Add(product);
            db.Complete();
        }
Ejemplo n.º 6
0
        public User Register()
        {
            bool   isUsernameFree = false;
            string username;

            _view.Access.ShowRegisterPage();
            do
            {
                username = _view.Access.GetUsername();

                try
                {
                    if (!_db.Users.Find(u => u.Username == username).Any())
                    {
                        isUsernameFree = true;
                    }
                    else
                    {
                        _view.Access.ShowMessage("User with given username already exists in this store.");
                    }
                }
                catch
                {
                    throw new ArgumentException("There was a problem connecting to the database. Try again later.");
                }
            }while (!isUsernameFree);

            string  password    = _view.Access.GetPassword();
            string  firstname   = _view.Access.GetFirstName();
            string  lastname    = _view.Access.GetLastName();
            string  phonenumber = _view.Access.GetPhoneNumber();
            string  streetname  = _view.Access.GetStreetName();
            string  postalcode  = _view.Access.GetPostalCode();
            string  city        = _view.Access.GetCityName();
            Country country     = _view.Access.GetCountyFromList(_db.Countries.GetAll());

            try
            {
                var user = _db.Users.Add(new User(username, password, UserRole.Customer));
                _db.Customers.Add(new Customer(user, firstname, lastname, phonenumber, streetname, postalcode, city, country));
                _db.Complete();
                return(user);
            }
            catch
            {
                throw new ArgumentException("There was a problem connecting to the database. Try again later.");
            }
        }
Ejemplo n.º 7
0
        private void SwitchProductAvaliability(IRepositoryFactory repositoryFactory)
        {
            int id      = UnitOfView.Catalog.GetProductId(repositoryFactory);
            var product = repositoryFactory.Products.Get(id);

            if (product.IsAvailable == true)
            {
                product.IsAvailable = false;
            }
            else
            {
                product.IsAvailable = true;
            }

            repositoryFactory.Complete();
        }