public async Task <User> AuthorizeAsync(string username, string password)
        {
            var user = await _repositories.Users.FindByUsernameAsync(username);

            if (null == user)
            {
                return(null);
            }

            var valid = user.VerifyPassword(password);
            await _repositories.SaveChangesAsync(); // update audit data

            return(valid ? user : null);
        }
        public async Task <ProductModel> CreateProductAsync(ProductAddModel model)
        {
            if (await _repositories.Products.AnyAsync(o => o.Name == model.Name))
            {
                throw new BusinessException(string.Format("A product already exists with name: {0}", model.Name));
            }

            var product = new Product(model.Name)
            {
                Description       = model.Description,
                QuantityAvailable = model.QuantityAvailable
            };

            _repositories.Products.Insert(product);

            await _repositories.SaveChangesAsync();

            return(Mapper.Map <ProductModel>(product));
        }