// GET: api/Categories/5 public IHttpActionResult Get(int id) { GetCategoryDTO category = _categoryRepository.GetcategoryById(id); if(category!=null) return Ok<GetCategoryDTO>(category); return NotFound(); }
public ActionResult GetCategoryGood(int c_Id, int?page) { //var goodListCat=elasticmanager.GetByCategoryId(c_Id); var goodListCat = goodmanager.GetAll().Where(i => i.Category_Id == c_Id).ToList(); foreach (var item in goodListCat) { item.Category = categoryManager.Get(item.Category_Id); item.WebShop = webShopManager.GetById(item.WebShop_Id); } var categoryName = goodListCat.First().Category.Name; if (!goodListCat.Any()) { return(View("../Error/CategoryNotFound")); } else { ViewBag.cat_id = c_Id; int pageSize = 10; int pageNumber = (page ?? 1); var modelView = new GetCategoryDTO() { CategoryName = categoryName, GoodListCategory = goodListCat.ToPagedList(pageNumber, pageSize) }; return(View(modelView)); } }
public GetCategoryDTO GetcategoryById(int id) { Category category = _categoryRepository.GetById(id); GetCategoryDTO categoryDTO = null; if (id != 0) { categoryDTO = new GetCategoryDTO() { id = category.id, name = category.name, displayname = category.displayname }; } return(categoryDTO); }
public IList <GetCategoryDTO> GetCategories() { IList <Category> categories = _categoryRepository.Table.ToList <Category>(); IList <GetCategoryDTO> categoryList = new List <GetCategoryDTO>(); foreach (var category in categories) { GetCategoryDTO CategoryDTO = new GetCategoryDTO() { id = category.id, name = category.name, displayname = category.displayname }; categoryList.Add(CategoryDTO); } return(categoryList); }
public IHttpActionResult GetCategories(int id) { Cluster cluster = UnitOfWork.ClusterRepository.GetByID(id); if (cluster == null) { return(NotFound()); } else if (cluster.ApplicationUsers.FirstOrDefault(x => x.Id == UserRecord.Id) == null) { return(Unauthorized()); } var cat = cluster.ClusterGroceries.Select(x => x.Grocery.Category).GroupBy(x => x); List <GetCategoryDTO> cats = new List <GetCategoryDTO>(); foreach (IGrouping <Category, Category> group in cat) { if (group.Key == null) { var dto = new GetCategoryDTO() { Name = null, Id = null, Description = null }; dto.Quantity = group.Count(); cats.Add(dto); } else { var dto = Mapper.Map <GetCategoryDTO>(group.Key); dto.Quantity = group.Count(); cats.Add(dto); } } return(Ok(cats)); }
public ActionResult Delete(int id) { GetCategoryDTO category = _categoryRepository.GetcategoryById(id); return(View(category)); }