Exemplo n.º 1
0
        public CategoryBTO FillChildrenRec(CategoryBTO CategorieToFindChildren)
        {
            UnitOfWork unitOfWork = new UnitOfWork(context);

            var ChildrenOfCategorie =
                unitOfWork.CategoryRepo.RetrieveChildren(CategorieToFindChildren.Id)
                .Select(x => x.CategoryToCategoryBTO()).ToList();


            if (ChildrenOfCategorie.Count() > 0)
            {
                CategorieToFindChildren.subCategories = new List <CategoryBTO>();

                foreach (var ChildToFindChildren in ChildrenOfCategorie)
                {
                    CategorieToFindChildren.subCategories.Add(FillChildrenRec(ChildToFindChildren));
                }
            }
            else
            {
                CategorieToFindChildren.subCategories = null;
            }

            return(CategorieToFindChildren);
        }
Exemplo n.º 2
0
        //Update
        public void Update(CategoryBTO existingCateg)
        {
            UnitOfWork unitOfWork = new UnitOfWork(context);

            unitOfWork.CategoryRepo.Update(existingCateg.CategoryBTOToCategory());
            unitOfWork.Save();
        }
Exemplo n.º 3
0
        //Create
        public CategoryBTO Create(CategoryBTO bto)
        {
            UnitOfWork unitOfWork = new UnitOfWork(context);
            var        response   = unitOfWork.CategoryRepo.Create(bto.CategoryBTOToCategory());

            unitOfWork.Save();
            return(response.CategoryToCategoryBTO());
        }
Exemplo n.º 4
0
 public static Category CategoryBTOToCategory(this CategoryBTO bto)
 {
     return(new Category
     {
         CategoryId = bto.Id,
         Name = bto.Name,
         ParentId = bto.ParentId
     });
 }
Exemplo n.º 5
0
        public IHttpActionResult Post(CategoryBTO categBto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            CategoryLogic categ = new CategoryLogic();
            var           model = categ.Create(categBto);

            return(CreatedAtRoute("DefaultApi", new { id = model.Id }, model));
        }
Exemplo n.º 6
0
        //ReadAll
        public List <CategoryBTO> RetrieveAllWithChildren()
        {
            UnitOfWork         unitOfWork = new UnitOfWork(context);
            List <CategoryBTO> Listbto    = new List <CategoryBTO>();

            foreach (var item in unitOfWork.CategoryRepo.RetrieveAll().Where(x => x.ParentId == null))
            {
                CategoryBTO btoToAdd = this.Retrieve(item.CategoryId);
                Listbto.Add(btoToAdd);
            }

            return(Listbto);
        }
Exemplo n.º 7
0
        public List <CategoryBTO> RetrieveAll()
        {
            UnitOfWork unitOfWork = new UnitOfWork(context);

            List <CategoryBTO> Listbto = new List <CategoryBTO>();

            foreach (var item in unitOfWork.CategoryRepo.RetrieveAll())
            {
                CategoryBTO btoToAdd = this.Retrieve(item.CategoryId);
                Listbto.Add(btoToAdd);
            }

            return(Listbto);
        }
Exemplo n.º 8
0
        public List <CategoryBTO> RetrieveAllWithoutChildren()
        {
            UnitOfWork unitOfWork = new UnitOfWork(context);

            List <CategoryBTO> Listbto = new List <CategoryBTO>();

            foreach (var item in unitOfWork.CategoryRepo.RetrieveAll())
            {
                CategoryBTO btoToAdd = item.CategoryToCategoryBTO();
                Listbto.Add(btoToAdd);
            }

            return(Listbto);
        }
Exemplo n.º 9
0
        public IHttpActionResult Put(CategoryBTO categBto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            CategoryLogic categ         = new CategoryLogic();
            var           existingCateg = categ.Retrieve(categBto.Id);

            if (existingCateg != null)
            {
                categ.Update(categBto);
            }
            else
            {
                return(NotFound());
            }

            return(Ok());
        }