public ViewModels.CategoryViewModel GetByImg(int id) { Category category = _categoriesRepository.GetByImg(id); ViewModels.CategoryViewModel categoryViewModel = MapToViewModel(category); return(categoryViewModel); }
public JsonResult GetFirstCategory() { var model = new ViewModels.CategoryViewModel { Id = 1, Name = "ajax sdfadassda" }; return(Json(model, JsonRequestBehavior.AllowGet)); }
public IEnumerable <ViewModels.CategoryViewModel> GetAll() { List <ViewModels.CategoryViewModel> catViewModels = new List <ViewModels.CategoryViewModel>(); foreach (Category category in _categoriesRepository.GetAll()) { ViewModels.CategoryViewModel categoryViewModel = MapToViewModel(category); catViewModels.Add(categoryViewModel); } return(catViewModels); }
public void Edit(ViewModels.CategoryViewModel categoryViewModel) { try { Category category = MapFromViewModel(categoryViewModel); _categoriesRepository.Edit(category); } catch (Exception ex) { throw ex; } }
public void Add(ViewModels.CategoryViewModel categoryViewModel) { try { Category category = MapFromViewModel(categoryViewModel); _categoriesRepository.Add(category); categoryViewModel.CategoryID = category.CategoryID; } catch (Exception ex) { throw (ex); } }
public void Populate() { #region Fake Data foreach (var x in Enumerable.Range(0, 5)) { var ctg = new ViewModels.CategoryViewModel($"Category {x}"); Categories.Add(ctg); foreach (var y in Enumerable.Range(0, 5)) { ctg.SubCategories.Add(new ViewModels.SubCategoryViewModel($"Sub-Category {x}/{y}")); } } #endregion Fake Data }
public ActionResult Category(int Nid, string Title = "") { dataTransfer = new DataTransfer(); ViewModels.CategoryViewModel cvm = new ViewModels.CategoryViewModel(); var tmpCategory = dataTransfer.GetCategoryByNidCategory(Nid); cvm.CategoryBrands = dataTransfer.GetCategory_BrandByNidcategory(tmpCategory.NidCategory); cvm.CategoryTypes = dataTransfer.GetCategory_TypeByNidcategory(tmpCategory.NidCategory); cvm.Products = dataTransfer.GetProductsByNidcategory(tmpCategory.NidCategory); var minmax = dataTransfer.GetMinMaxCategoryPrice(tmpCategory.NidCategory); cvm.MinPrice = minmax.Item1; cvm.MaxPrice = minmax.Item2; cvm.Category = tmpCategory; ViewBag.Desc = tmpCategory.Description; return(View(cvm)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewModels.CategoryViewModel model = new ViewModels.CategoryViewModel(); model.Categories = db.Categories.ToList(); model.Category = db.Categories.Find(id); if (model.Categories == null) { return(HttpNotFound()); } return(View(model)); }
public ActionResult Edit(ViewModels.CategoryViewModel model) { if (ModelState.IsValid) { try { db.Entry(model.Category).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch { ModelState.AddModelError(string.Empty, "Someting went wrong."); } } return(View(new ViewModels.CategoryViewModel { Category = model.Category, Categories = db.Categories.ToList() })); }
private void GetParentCategoriesRecursive(ViewModels.CategoryViewModel request, ref List <KeyValuePair <Guid, string> > outCategories, int level) { string space = ""; for (int i = 0; i < level; i++) { space += "---"; } var model = GetCommand <GetParentCategoriesCommand>().ExecuteCommand(request); if (model.Count > 0) { foreach (var item in model) { outCategories.Add(new KeyValuePair <Guid, string>(item.Id, space + item.Name)); GetParentCategoriesRecursive(new ViewModels.CategoryViewModel { ParentId = item.Id }, ref outCategories, level + 1); } } }
private Category MapFromViewModel(ViewModels.CategoryViewModel categoryViewModel) { Category category = Mapper.Map <Category>(categoryViewModel); return(category); }
private ViewModels.CategoryViewModel MapToViewModel(Category category) { ViewModels.CategoryViewModel categoryViewModel = Mapper.Map <ViewModels.CategoryViewModel>(category); return(categoryViewModel); }
public ActionResult Index() { ViewModels.CategoryViewModel model = new ViewModels.CategoryViewModel(); model.Categories = db.Categories.OrderBy(p => p.Name).ToList(); return(View(model)); }