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); }
//Update public void Update(CategoryBTO existingCateg) { UnitOfWork unitOfWork = new UnitOfWork(context); unitOfWork.CategoryRepo.Update(existingCateg.CategoryBTOToCategory()); unitOfWork.Save(); }
//Create public CategoryBTO Create(CategoryBTO bto) { UnitOfWork unitOfWork = new UnitOfWork(context); var response = unitOfWork.CategoryRepo.Create(bto.CategoryBTOToCategory()); unitOfWork.Save(); return(response.CategoryToCategoryBTO()); }
public static Category CategoryBTOToCategory(this CategoryBTO bto) { return(new Category { CategoryId = bto.Id, Name = bto.Name, ParentId = bto.ParentId }); }
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)); }
//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); }
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); }
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); }
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()); }