Exemplo n.º 1
0
        public BrandDto Add(BrandDto dto)
        {
            var brand = new Brand();

            if (dto.Id != 0)
            {
                brand = uow.Brands.GetAll().Where(x => x.Id == dto.Id)
                    .Include(x => x.Providers)
                    .Include(x=>x.Pages)                    
                    .Single();
                brand.Name = dto.Name;
                brand.Providers = new List<Provider>();
                brand.Pages = new List<Page>();
            } else
            {
                brand = new Brand() { Name = dto.Name };
                this.uow.Brands.Add(brand);
            }
                
            foreach(var provider in dto.Providers)
            {
                if(provider.Checked == true)
                {
                    brand.Providers.Add(uow.Providers.GetById(provider.Id));
                }
            }

            foreach (var page in dto.Pages)
            {
                if (page.Checked == true)
                {
                    brand.Pages.Add(uow.Pages.GetById(page.Id));
                }
            }
            this.uow.SaveChanges();
            return new BrandDto(brand);
        }
Exemplo n.º 2
0
 public BrandDto(Brand brand) {
     this.Id = brand.Id;
     this.Name = brand.Name;
     this.Providers = brand.Providers.Select(x => new ProviderDto(x)).ToList();
 }