コード例 #1
0
ファイル: ProductManager.cs プロジェクト: jacobgoredema/ABC
        public void Add(Product product)
        {
            //AOP Aspect Oriented Programming
            // ValidationTool.FluentValidate(new ProductValidator(), product);

            // Business rules
            _productDal.Add(product);
        }
コード例 #2
0
        public IResult Add(Product product)
        {
            IResult result = BusinessRules.Run(CheckIfProductNameExist(product.ProductName), CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExcedeed());

            //validation

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

            _productDal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));



            // ValidationTool.Validate(new ProductValidator(), product);
        }
コード例 #3
0
        public IResult Add(Product product)
        {
            //REFACTORY

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

            //List<Product> listOfProduct = new List<Product>();
            //var res = _productDAL.GetAll(p => p.CategoryID == product.CategoryID).Count;


            //foreach (var item in listOfProduct)
            //{
            //if (res > 10)
            //{
            //    return new ErrorResult(Messages.ProductCountOfCategoryError);
            //}
            //}

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


            ////business codes
            //_productDAL.Add(product);
            //return new SuccessResult(Messages.ProductAdded);//set vermediğim için ctor da eklemem lazım
            IResult result = BusinessRules.Run(CheckIfProductNameExist(product.ProductName), CheckIfProductCountOfCategoryCorrect(product.CategoryID), CheckIfCategoryCountCorrect());

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

            _productDAL.Add(product);
            return(new SuccessResult(Messages.ProductAdded));//set vermediğim için ctor da eklemem lazım

            //if (CheckIfProductCountOfCategoryCorrect(product.ProductID).Success && CheckIfProductNameExist(product.ProductName).Success)
            //{
            //    _productDAL.Add(product);
            //    return new SuccessResult(Messages.ProductAdded);//set vermediğim için ctor da eklemem lazım
            //}
            //return new ErrorResult();
        }
コード例 #4
0
        public ActionResult Add(VMProduct model)
        {
            Product yeniUrun = new Product();

            ProductModel pm = ProductModelDAL.Get(x => x.ModelID == model.ModelID);

            yeniUrun.ModelID      = pm.ModelID;
            yeniUrun.Description  = model.Description;
            yeniUrun.IsActive     = true;
            yeniUrun.ProductID    = Guid.NewGuid();
            yeniUrun.ProductName  = model.ProductName;
            yeniUrun.UnitPrice    = model.UnitPrice;
            yeniUrun.UnitsInStock = model.UnitsInStock;
            yeniUrun.ViewCount    = 0;

            Guid     cID = pm.CategoryID;
            Category c   = CategoryDAL.Get(x => x.CategoryID == cID);

            foreach (Property item in c.Properties)
            {
                string valProp = Request.Form[item.PropertyID.ToString()];
                if (valProp != null)
                {
                    ProductTechnicProperty temp = new ProductTechnicProperty();

                    temp.PropertyID        = item.PropertyID;
                    temp.PropertyValue     = valProp;
                    temp.ProductPropertyID = Guid.NewGuid();
                    yeniUrun.ProductTechnicProperties.Add(temp);
                }
            }

            foreach (HttpPostedFileBase item in model.Picture)
            {
                if (item != null)
                {
                    string pic  = System.IO.Path.GetFileName(item.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/Assets/img/products"), pic);
                    // file is uploaded
                    item.SaveAs(path);

                    ProductPicture temp = new ProductPicture();

                    temp.ProductPictureID = Guid.NewGuid();
                    temp.PicturePath      = item.FileName;
                    temp.IsActive         = true;
                    yeniUrun.ProductPictures.Add(temp);
                }
            }

            ProductDAL.Add(yeniUrun);


            return(RedirectToAction("Add"));
        }
コード例 #5
0
 public void Add(Product product)
 {
     //ProductValidator productValidator = new ProductValidator();
     //var result = productValidator.Validate(product);
     //if (result.Errors.Count>0)
     //{
     //	throw new ValidationException(result.Errors);
     //}
     ValidationTool.Validate(new ProductValidator(), product);
     _productDAL.Add(product);
 }
コード例 #6
0
ファイル: ProductManager.cs プロジェクト: SKarakayaa/perdecim
        public async Task <IResult> CreateProduct(CreateProductDto productDto)
        {
            Product product = new Product
            {
                BrandId      = productDto.BrandId,
                CanNotable   = productDto.CanNotable,
                CategoryId   = productDto.CategoryId,
                Description  = productDto.Description,
                DiscountRate = productDto.DiscountRate,
                InStock      = productDto.InStock,
                IsNew        = productDto.IsNew,
                IsPopular    = productDto.IsPopular,
                Name         = productDto.Name,
                Price        = productDto.Price
            };

            product = _productDAL.Add(product);

            foreach (var colorId in productDto.ColorIds)
            {
                product.ProductColors.Add(new ProductColor(product.Id, colorId));
            }

            if (productDto.DemandTypeIds != null && productDto.DemandTypeIds.Count() != 0)
            {
                foreach (var demandTypeId in productDto.DemandTypeIds)
                {
                    product.ProductDemands.Add(new ProductDemand(product.Id, demandTypeId));
                }
            }

            if (productDto.Images != null && productDto.Images.Count() > 0)
            {
                foreach (var image in productDto.Images)
                {
                    string imageName  = Guid.NewGuid() + "." + image.FileName.Split('.')[1];
                    var    fileLocate = $"{productDto.FilePath}/{imageName}";
                    product.ProductImages.Add(new ProductImage {
                        ImageName = imageName, ProductId = product.Id
                    });

                    using (var stream = new FileStream(fileLocate, FileMode.Create))
                    {
                        image.CopyTo(stream);
                    }
                }
            }

            int result = await _uow.Complete();

            return(ResultHelper <int> .ResultReturn(result));
        }
コード例 #7
0
        public IActionResult Add(Product entity)
        {
            Product added = _productDal.Add(entity);

            if (added != null && added.Id > 0)
            {
                return(Ok(added));
            }
            else
            {
                return(BadRequest("Ekleme işlemi başarısız oldu!"));
            }
        }
コード例 #8
0
        public IResult Add(Product product)
        {
            IResult result = BusinessRules.Run(CheckProductName(product.ProductName),
                                               ChechIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }
            _Iproductdal.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #9
0
        public IResult Add(Product product)
        {
            IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),
                                               ChecktIfProductCountOfCategoryCorrect(product.CategoryID),
                                               CheckIfCategoryLimitExceded());

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

            _productDAL.Add(product);
            return(new SuccessResult());
        }
コード例 #10
0
        public IResult Add(Product product)
        {
            var result = BusinessRules.Run(
                CheckIfHaveAlreadySameProductName(product.ProductName),
                CheckIfHaveAlreadySameProductType(product.ProductType)
                );

            if (result != null)
            {
                return(result);
            }
            _productDAL.Add(product);
            return(new SuccessResult("Successfully Added"));
        }
コード例 #11
0
        //[RemoveCache]
        //[Transaction] // örn. hata olursa geri al
        //[Performance] // örn. çalışması 5sn geçerse uyar
        public IResult Add(Product product)
        {
            // Business  codes
            // Validation
            // üst 2si AYRI olmalı!

            // fluent validation ile bu doğrulamaları yapıp burdan kaldırıcaz. :  product.UnitPrice <= 0, product.ProductName.Length < 2 vs hep validation
            // Business. add folder : ValidationRules :  ProductValidator yazdık.. Aşağıyı kapat.
            ////if (product.UnitPrice <= 0)
            ////{
            ////    return new ErrorResult(Messages.UnitPriceInvalid);
            ////}

            ////if (product.ProductName.Length < 2)
            ////{
            ////    // magic string : öyle elle metinsel standardı olmayan şeyler
            ////    // return new ErrorResult("Ürün ismi en az 2 karakter olmalıdır");
            ////    return new ErrorResult(Messages.ProductNameInvalid);
            ////}
            ///
            //var context = new ValidationContext<Product>(product);
            //ProductValidator productValidator = new ProductValidator();
            //var result = productValidator.Validate(context);
            //if (!result.IsValid)
            //{
            //    throw new ValidationException(result.Errors);
            //}
            // üsttekinin yerine
            //ValidationTool.Validate(new ProductValidator(), product); // 1e1 aynı anlam attribute artık :   [ValidationAspect(typeof(ProductValidator)]
            // Loglama
            // Cacheremove
            // performance
            // transaction
            // authorization
            //...... > bunlar iş mantığı değil.. buraya eklenirlerse de burası ÇORBA : AOP> attribute ekleyerek!!örn. method üstüne    [ValidationAspect(typeof(ProductValidator)]

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

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

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #12
0
        public IResult Add(Product product)
        {
            //business vs validation : iş kuralları ayrı doğrulama ayrı olmalıdır
            //if (product.ProductName.Length<2)
            //{
            //    //magic strings
            //    return new ErrorResult(Messages.ProductNameInvalid);
            //}
            //ValidationTool.Validate(new ProductValidator(),product);
            IResult result = BusinessRules.Run(CheckIfProductCountOfCategoryCorrect(product.CategoryId),
                                               CheckIfProductNameExists(product.ProductName),
                                               CheckIfCategoryLimitExceded());

            if (result != null)
            {
                return(result);
            }
            _productDAL.Add(product);
            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #13
0
 //[FluentValidationAspect(typeof(ProductValidator))]
 public Product Add(Product product)
 {
     return(_productDal.Add(product));
 }
コード例 #14
0
 public bool Add(Product entity)
 {
     return(_productDAL.Add(entity) > 0);
 }
コード例 #15
0
 public IResult Add(Product product)
 {
     //Business codes
     _productDAL.Add(product);
     return(new SuccessResult(Messages.ProductAdded));
 }
コード例 #16
0
 public void Add(Product product)
 {
     ValidationTool.Validate(new ProductValidator(), product);
     _productDAL.Add(product);
 }
コード例 #17
0
 public IResult Add(Product product)
 {
     _productDal.Add(product);
     // validasyon kodları, iş kodları vs. buraya çağrılacak
     return(new SuccessResult(Messages.ProductAdded));
 }
コード例 #18
0
 public void Insert(Product entity)
 {
     _dal.Add(entity);
 }
コード例 #19
0
 public static int Add(Product data)
 {
     return(ProductDB.Add(data));
 }
コード例 #20
0
        public IResult Add(Product product)
        {
            _productDal.Add(product);

            return(new SuccessResult(Messages.ProductAdded));
        }
コード例 #21
0
 public void createProduct(Products product)
 {
     _productDAL.Add(product);
 }
コード例 #22
0
 public void Insert(Product entity)
 {
     _product.Add(entity);
 }
コード例 #23
0
 public void AddProduct(Product model)
 {
     _productDAL.Add(model);
 }
コード例 #24
0
ファイル: ProductManager.cs プロジェクト: yt17/netcore_blog
 public void Add(Product product)
 {
     productDAL.Add(product);
 }
コード例 #25
0
        public Product Add(Product product)
        {
            //ValidatorTool.FluentValidate(new ProductValidatior(), product);

            return(_productDal.Add(product));
        }
コード例 #26
0
 public void AddProduct(Product product)
 {
     _productDAL.Add(product);
 }
コード例 #27
0
 public void Add(Product product)
 {
     _productDal.Add(product);
 }
コード例 #28
0
 /// <summary>
 /// 新增产品
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public int AddProduct(TblAdProductV2 entity)
 {
     return(productDAL.Add(entity));
 }
コード例 #29
0
 public ResponseModel <Product> Add(Product entity)
 {
     responseModel.Success = _productDAL.Add(entity);
     responseModel.result  = entity;
     return(responseModel);
 }
 public void Add(Products entity)
 {
     _ProductDAL.Add(entity);
 }