コード例 #1
0
        public IResult Add(Product product)
        {
            //Aynı isimde ürün eklenemez
            //Eğer mevcut kategori sayısı 15'i geçtiyse sisteme yeni ürün eklenemez. ve
            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #2
0
        [ValidationAspect(typeof(ProductValidator))] //bu yapı gidip parametreyi okuyacak productı bulup ilgili validator u bulup validation yapacak
        public IResult Add(Product product)
        {                                            //Aynı isimde ürün eklenemez
            //Eğer mevcut kategori sayısı 15i geçtiyse siteme yeni ürün eklenemez.

            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName), //İş kurallarını burada gönderdik
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));  //bunu yapabilmenin yöntemi constructor eklemektir
        }
コード例 #3
0
 public ProductModel Add(ProductModel model)
 {
     try
     {
         _productDal.Add(model.Product);
         model.Message = NotificationMessages.Success;
     }
     catch (System.Exception ex)
     {
         model.IsError    = true;
         model.StackTrace = ex.StackTrace;
         model.Code       = NotificationEnums.DbError.GetHashCode();
         model.Message    = NotificationMessages.ErrorSave;
     }
     return(model);
 }
コード例 #4
0
        public IResult Add(Product product)
        {
            ValidationTool.Validate(new ProductValidator(), product);

            if (product.UnitPrice <= 0)
            {
                return(new ErrorResult(Messages.UnitPriceInvalid));
            }
            if (product.ProductName.Length < 2)
            {
                return(new ErrorResult(Messages.ProductNameInvalid));
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #5
0
        public IResult Add(Product product)
        {
            // Validation : Doğrulama ve Business ayrı olmalı!
            //ValidationTool.Validate(new ProductValidator(),product);
            //loglama,cache,performance,transcation, auth. hepsini buraya yazmak yerine AOP ile metod üstünde yapılacak.

            // business codes here
            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName), CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }
            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #6
0
 public IResult Add(Product product)
 {
     //validation -- doğrulama
     //iş kodları -- business code
     BusinessRules.Run(CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                       CheckIfProductNameExists(product.ProductName));
     if (CheckIfProductCountOfCategoryCorrect(product.CategoryId).Success)
     {
         if (CheckIfProductNameExists(product.ProductName).Success)
         {
             _productDal.Add(product);
             return(new SuccessResult(Messages.ProductAdded));
         }
     }
     return(new ErrorResult());
 }
コード例 #7
0
        public IResult Add(Product product)
        {
            //business codes

            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName), // isterse bin tane böyle iş kuralı olsun. Bu şekilde gönderebiliriz
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfCategoryLimitExceded());                // burada polymorphizm var

            if (result != null)
            {
                return(result);
            }
            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #8
0
        public IResult Add(Product product)
        {
            //Bir kategoride en fazla 15 ürün olabilir
            //Eğer mevcut kategori sayısı 15'i geçtiyse sisteme yeni ürün eklenemez
            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }
            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
            //validation
        }
コード例 #9
0
        public IResult Add(Product product)
        {
            //bir kategoride en fazla 15 ürün olabilir kodunu yazalım
            //Aynı isimde farklı bir ürün eklenemz
            //eğer mevcut kategori sayısı 15 i geçtiyse sisteme yeni ürün eklenemez

            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName), CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceeded());

            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #10
0
        public IResult Add(Product product)
        {
            var errorResult = BusinessEngine.Run(
                //CheckIfProductCountOfCategoryExceeded(product.CategoryId),
                CheckIfProductWithSameNameExists(product.ProductName),
                CheckIfThereAreTooManyCategories()
                );

            if (errorResult != null)
            {
                return(errorResult);
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #11
0
        public IResult Add(Product product)
        {
            /* if (product.ProductName.Length < 2)
             * {
             *   return new ErrorResult(Messages.ProductNameInvalid);
             * }*/
            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }
            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #12
0
        public IResult Add(Product product)
        {
            IResult resp = BusinessRules.Run(
                CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                CheckCategoryCount()
                );

            if (resp != null)
            {
                return(resp);
            }

            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #13
0
        public IResult Add(Product product)
        {
            //validation -- doğrulama
            //iş kodları -- business code
            //Eğer mevcut kategori sayısı 15 ' i geçtiyse sisteme yeni ürün eklenemez.
            IResult result = BusinessRules.Run(CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfProductNameExists(product.ProductName),
                                               CheckIfCategoryLimitExceded());

            if (result != null)   //result : kurala uymayan.
            {
                return(result);
            }
            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #14
0
        public IResult Add(Product product)
        {
            //is kurallari
            IResult result = BusinessRules.Run(CheckIfProductCountOfCategoryCorrect(product.CategoryID),
                                               CheckIfProductNameExists(product.ProductName), CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }
            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));


            //validation: Doğrulama kodu
        }
コード例 #15
0
        public IResult Add(Product product)
        {
            IResult result = BusinessRules.Run(
                CheckIfProductNameExists(product.ProductName),
                CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                CheckIfCategoryLimitExceeded()
                );

            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #16
0
        public IResult Add(Product product)
        {
            //business code
            //buraya ürün eklemeden önce gerekli koşullar varsa yazılır.
            //validation

            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }
            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #17
0
        public IResult Add(Product product)
        {
            //iş kodları -- business code
            //validation -- doğrulama
            var context = new ValidationContext <Product>(product);
            ProductValidator productValidator = new ProductValidator();
            var result = productValidator.Validate(context);

            if (!result.IsValid)
            {
                throw new ValidationException(result.Errors);
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #18
0
        public IResult Add(Product product)
        {
            IResult result = BusinessRules.Run(CheckIfProductNameExistsCorrect(product.ProductName),
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfCategoryLimitsExceded()
                                               );

            // hata ise logic dönsün değilse eklesin
            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #19
0
        public IResult Add(Product product)
        {
            //business codes -- iş kodu
            //validation code -- doğrulama kodu
            IResult result = BusinessRules.Run(CheckIfProductNameExist(product.ProductName),
                                               CheckIfCategoryProductOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #20
0
        public IResult Add(Product product)
        {
            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfCategoryLimitExceded());

            // bunu bi result2a atadım.

            if (result != null)  //  eğer result, kurala uymayan bir durum oluştuysa,
            {
                return(result);  // o zaman result'ı döndürebilirim.
            }
            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #21
0
        public IResult Add(Product product)
        {
            //business kodlar yazılır (eğer böyleyse, şöyleyse)
            //business codes = product ile ilgili iş ihtiyaçlarına uygunluk. (Bir kişiye ehliyet verip vermeyeceğimze bakıldığı yer? sınavdan 70 almış mı? vs.)
            //validation codes = product'ı business'a dahil etmek için product'ın yapısal olarak uygunluğunu kontrol etme vs. işlemleri

            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId));

            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #22
0
        public IResult Add(Product product)
        {
            //validation: nesnenin yapısal olarak uygun olup  olmadığını kontrol eder.
            //business codes:iş ihtiyaclarına uygunluk

            //if (product.ProductName.Length < 2)
            //{
            //    return new ErrorResult(Messages.ProductNameInvalid);
            //}

            //ValidationTool.Validate(new ProductValidator(), product);

            _productDal.Add(product);


            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #23
0
        public IResult Add(Product product)
        {
            //validation -- doğrulama isim min 2 karakter olmalı gibi şifre şunları içermeli gibi
            //eklenecek nesnenin (productın) özellikleri yapısı ile ilgili olanlar

            IResult result = BusinessRules.Run(CheckIfProductNameExist(product.ProductName),
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }
            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #24
0
        public IResult Add(Product product)
        {
            //ValidationTool.Validate(new ProductValidator(), product);

            //business Codes
            //Validation >> business ve validasyon kodu ayri yazilir

            if (product.ProductName.Length < 2)
            {
                //Magic strings
                return(new ErrorResult(Messages.ProductNameInvalid));
            }
            //business codes
            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #25
0
        public void AddProduct()
        {
            Product product = new Product()
            {
                Name = "unit test product"
            };

            IProductDal productManager = IocUtil.Resolve <IProductDal>();

            productManager.Add(product);

            productManager.GetList();

            bool isAdded = productManager.GetList().Exists(x => x.Name == product.Name);

            Assert.AreEqual(true, isAdded);
        }
コード例 #26
0
        public IResult Add(Product product)
        {
            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),            //aynı isimde ürün olmamalı
                                               CheckIfProductCountOfCategoryCorrect(product.CategoryId), //ürün limiti kurallara uyuyor mu
                                               CheckIfCategoryLimitExceded());                           //category 15 i geçerse ürün ekleyemez

            //artık yukarda sadece virgülle yeni kural eklememiz yeterli. yeniden buraya kod yazmamıza gerek yok

            //result=kurala uymayan
            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #27
0
        public IResult Add(Product product)
        {
            //ValidationTool.Validate(new ProductValidator(), product);
            IResult result = BusinessRules.Run(CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfProductNameExist(product.ProductName),
                                               CheckIfCategoryLimitExceeded()
                                               );

            if (result != null)
            {
                return(result);
            }
            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));

            //business code
        }
コード例 #28
0
        public IResult Add(Product product)
        {
            //Magic strings kullanmamalıyız. Dolayısıyla Messages adında static bir class oluşturduk.
            //Validation

            IResult result = BusinessRules.Run(CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfProductNameExists(product.ProductName),
                                               CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }/***********************************************************************************************/
コード例 #29
0
        public IResult Add(Product product)
        {
            IResult result = BusinessRuleTool.Run(
                _productRuler.RuleCategoryCount(OptionVariables.MaxCategoryCount, product.CategoryId),
                _productRuler.RuleProductNameExists(product.ProductName),
                _productRuler.RuleCategoryLimit(OptionVariables.CategoryEndLimit)
                );

            if (result != null)
            {
                return(result);
            }

            //return CheckAllRules(product);
            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #30
0
        public IResult Add(Product product)
        {
            //bir kategoride en fazla 10 ürün olabilir.
            //aynı isimde ürün eklenemez.
            //eğer mevcut kategori sayısı 15 i geçtiyse sisteme yeni ürün eklenemez

            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName), CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());

            if (result != null) //result kurala uymayan demek
            {
                return(result);
            }

            _productDal.Add(product);//dala diyor ki ekle

            return(new SuccessResult(Messages.ProductAdded));
        }