Ejemplo n.º 1
0
        public IEnumerable <ProviderDTO> GetProvidersByCategory(int?categoryId)
        {
            var products = GetProductsByCategory(categoryId);

            if (categoryId == null)
            {
                throw new ArgumentNullException();
            }
            if (products == null)
            {
                throw new ArgumentException();
            }
            else
            {
                List <Provider> providers = new List <Provider>();
                foreach (ProductDTO product in products)
                {
                    var provider = UnitOfWork.ProviderRepository.Get((pr => pr.Name == product.ProviderName)).FirstOrDefault();
                    if (provider != null && !providers.Contains(provider))
                    {
                        providers.Add(provider);
                    }
                }
                return(ProviderMapper.Map(providers));
            }
        }
Ejemplo n.º 2
0
 public ProviderDTO GetById(int?id)
 {
     if (id == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         var provider = UnitOfWork.ProviderRepository.GetById(id);
         return(ProviderMapper.Map(provider));
     }
 }
Ejemplo n.º 3
0
 public IEnumerable <ProviderDTO> GetProvidersWithFilter(IEnumerable <PropertyFilterDTO> propertyFilters)
 {
     if (propertyFilters == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         Filter <Provider> filter = new Filter <Provider>();
         foreach (PropertyFilterDTO propertyFilter in propertyFilters)
         {
             if (propertyFilter.PropertyId == null)
             {
                 throw new ArgumentNullException();
             }
             else if (propertyFilter.PropertyId.CompareTo("Id") != 0 && propertyFilter.PropertyId.CompareTo("Name") != 0)
             {
                 throw new ArgumentException();
             }
             else
             {
                 var type = (new Category()).GetType().GetProperty(propertyFilter.PropertyId).PropertyType;
                 if (propertyFilter.Value != null && propertyFilter.Value2 != null)
                 {
                     var value1 = Convert.ChangeType(propertyFilter.Value, type);
                     var value2 = Convert.ChangeType(propertyFilter.Value2, type);
                     filter.By(propertyFilter.PropertyId, propertyFilter.Operation, value1,
                               value2, propertyFilter.Connector);
                 }
                 else if (propertyFilter.Value != null)
                 {
                     var value1 = Convert.ChangeType(propertyFilter.Value, type);
                     filter.By(propertyFilter.PropertyId, propertyFilter.Operation, value1, null, propertyFilter.Connector);
                 }
                 else
                 {
                     filter.By(propertyFilter.PropertyId, propertyFilter.Operation, propertyFilter.Connector);
                 }
             }
         }
         var providers = UnitOfWork.ProviderRepository.Get(filter);
         return(ProviderMapper.Map(providers));
     }
 }
Ejemplo n.º 4
0
 public ProviderDTO Create(ProviderDTO dto)
 {
     if (dto == null)
     {
         throw new ArgumentNullException();
     }
     else if (UnitOfWork.ProviderRepository.Get(p => p.Name == dto.Name).FirstOrDefault() != null)
     {
         throw new ArgumentException("Entity already exist");
     }
     else
     {
         var entity = ProviderMapper.Map(dto);
         UnitOfWork.ProviderRepository.Insert(entity);
         UnitOfWork.Save();
         var created = UnitOfWork.ProviderRepository.Get((c => c.Name == dto.Name)).FirstOrDefault();
         return(ProviderMapper.Map(created));
     }
 }
Ejemplo n.º 5
0
        public IEnumerable <ProviderDTO> GetAll()
        {
            var providers = UnitOfWork.ProviderRepository.Get();

            return(ProviderMapper.Map(providers));
        }