Example #1
0
 public T Create(T entity)
 {
     if (_validationTool.FluentValidate(_validator, entity))
     {
         return(_tdal.Create(entity));
     }
     return(null);
 }
Example #2
0
        public override void OnEntry(MethodExecutionArgs args)
        {
            var validator  = (IValidator)Activator.CreateInstance(_validatorType);
            var entityType = _validatorType.BaseType.GetGenericArguments()[0];
            var entities   = args.Arguments.Where(t => t.GetType() == entityType);

            foreach (var entity in entities)
            {
                ValidationTool.FluentValidate(validator, entity);
            }
        }
Example #3
0
        //PostSharp ile attribute bazında validation işlemi gerçekleştirebiliriz.
        //      [FluentValidationAspect(typeof(ProductValidator))]
        public void Add(Product product)
        {
            //validation işlemi yapıyoruz.
            //AOP (Aspect oriented programming tekniği)
            ValidationTool.FluentValidate(new ProductValidator(), product);  //böyle yapmak yerine PostSharp ile attribute bazında yaparak daha temiz bir kod uygulayabiliriz.AOP'nin temellerinden biri.öncelikle Core projesine ve Business projesine manage nugettan PostSharp yükle.
            //yukarda FluentValidationAspect attribute vasıtasıyla daha temiz bir kod uygulamış oluyoruz PostSharp ile



            _productDal.Add(product);
        }
        public override void OnBefore(IInvocation invocation)
        {
            var validator  = (IValidator)Activator.CreateInstance(_validatorType);
            var entityType = _validatorType.BaseType.GenericTypeArguments[0];
            var entities   = invocation.Arguments.Where(arg => arg.GetType() == entityType);

            foreach (var entity in entities)
            {
                ValidationTool.FluentValidate(validator, entity);
            }
        }
Example #5
0
        public Cart AddToCart(string userId, Cart cart, string operatorValue = null)
        {
            try
            {
                var cartItem = GetCart(userId);
                if (cartItem != null)
                {
                    foreach (var item in cart.CartItems)
                    {
                        var index = cartItem.CartItems.FindIndex(c => c.Products_Id == item.Products_Id);
                        if (index < 0)
                        {
                            cartItem.CartItems.Add(new CartItem
                            {
                                Carts_Id    = cartItem.Id,
                                Products_Id = item.Products_Id,
                                Quantity    = item.Quantity
                            });
                        }
                        else
                        {
                            switch (operatorValue)
                            {
                            case "-":
                                cartItem.CartItems[index].Quantity -= item.Quantity;
                                break;

                            default:
                                cartItem.CartItems[index].Quantity += item.Quantity;
                                break;
                            }
                        }
                    }
                    ValidationTool     _validationTool     = new ValidationTool();
                    CartItemValidation cartItemValidations = new CartItemValidation();
                    bool result = _validationTool.FluentValidate(cartItemValidations, cartItem.CartItems);
                    if (result == true)
                    {
                        return(_cartDal.Update(cartItem));
                    }
                }
                return(null);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Example #6
0
 public void Add(User u)
 {
     ValidationTool.FluentValidate(new UserValidator(), u);
     _userDAL.Add(u);
 }
 public void Add(Product product)
 {
     //Implement validation with AOP: Aspect Oriented Programming
     ValidationTool.FluentValidate(new ProductValidator(), product);
     _productDal.Add(product);
 }
 public void CreateOrder(Order order)
 {
     ValidationTool.FluentValidate(new OrderValidator(), order);
     order.OrderPlaced = DateTime.Now;
     _orderDal.Add(order);
 }
Example #9
0
 public IResult Update(Car car)
 {
     ValidationTool.FluentValidate(new CarValidator(), car);
     _carDal.Update(car);
     return(new SuccessResult(Messages.CarUpdate));
 }