public void Buy(AddingToyServiceModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                throw new ArgumentException("Name cannot be null or whitespace!");
            }

            if (model.Profit < 0 ||
                model.Profit > 5)
            {
                throw new ArgumentException("Profit must be higher than 0% and lower than 500%");
            }

            var toy = new Toy()
            {
                Name             = model.Name,
                Description      = model.Description,
                DistributorPrice = model.Price,
                Price            = model.Price + (model.Price * (decimal)model.Profit),
                BrandId          = model.BrandId,
                CategoryId       = model.CategoryId
            };

            this.data.Toys.Add(toy);

            this.data.SaveChanges();
        }
Beispiel #2
0
        public void BuyFromDistributor(AddingToyServiceModel model)
        {
            if (String.IsNullOrWhiteSpace(model.Name))
            {
                throw new ArgumentException("Name cannot be null or whitespace!");
            }

            // Profit should be in range 0-500%
            if (model.Profit < 0 || model.Profit > 5)
            {
                throw new ArgumentException("Profit must be higher than zero and lowe than 500%");
            }

            Toy toy = new Toy()
            {
                Name             = model.Name,
                Description      = model.Description,
                DistributorPrice = model.Price,
                Price            = model.Price + (model.Price * (decimal)model.Profit),
                BrandId          = model.BrandId,
                CategoryId       = model.CategoryId,
            };

            this.context.Toys.Add(toy);
            this.context.SaveChanges();
        }
Beispiel #3
0
        public int BuyFromDistributor(AddingToyServiceModel model)
        {
            ValidateToy(model.Name, model.BrandId, model.CategoryId, model.Price);

            var toy = new Toy()
            {
                Name        = model.Name,
                Description = model.Description,
                Price       = model.Price,
                BrandId     = model.BrandId,
                CategoryId  = model.CategoryId
            };

            this.data.Toys.Add(toy);
            this.data.SaveChanges();

            return(toy.Id);
        }
        public void BuyToyFromDistributor(AddingToyServiceModel model)
        {
            ValidateName(model.Name);
            ValidateProfit(model.Profit);

            var toy = new Toy()
            {
                Name             = model.Name,
                Description      = model.Description,
                DistributorPrice = model.Price,
                Price            = model.Price + (model.Price * model.Profit),
                BrandId          = model.BrandId,
                CategoryId       = model.CategoryId
            };

            this.data.Toys.Add(toy);
            this.data.SaveChanges();
        }
Beispiel #5
0
        public void BuyFromDistributor(AddingToyServiceModel model)
        {
            if (this.data.Brands.Any(b => b.Id == model.BrandId) == false)
            {
                throw new InvalidOperationException(OutputMessages.InvalidBrand);
            }
            else if (this.data.Categories.Any(c => c.Id == model.CategoryId) == false)
            {
                throw new InvalidOperationException(OutputMessages.InvalidCategory);
            }

            var toy = CreateToy(model.Name, model.Description, model.Price, model.Profit, model.Quantity, model.BrandId, model.CategoryId);

            if (IsValid(toy) == false)
            {
                throw new InvalidOperationException(OutputMessages.InvalidToy);
            }

            this.data.Toys.Add(toy);
            this.data.SaveChanges();
        }
Beispiel #6
0
        public void ByToyByDistributor(AddingToyServiceModel model)
        {
            if (String.IsNullOrWhiteSpace(model.Name))
            {
                throw new ArgumentException("Name cannot be null or whitespace");
            }

            if (model.Profit < 0)
            {
                throw new ArgumentException("Profit must be figher than zero");
            }

            var toy = new Toy()
            {
                Name             = model.Name,
                Description      = model.Description,
                DistributorPrice = model.Price,
                Price            = model.Price + (model.Price * model.Profit),
                BrandId          = model.BrandId,
                CategoryId       = model.CategoryId
            };
        }