public ActionResult AddCategory(int id = 0) { if (id == 0) { ItemCategoryMainViewModel model = new ItemCategoryMainViewModel(); return(View(model)); } else { ItemCategoryMainViewModel model = new ItemCategoryMainViewModel(); ItemCategoryMainRepository repository = new ItemCategoryMainRepository(); model = repository.GetCategoryByID(id); return(View(model)); } }
public ItemCategoryMainViewModel GetCategoryByID(int id) { ItemCategoryMainViewModel model = new ItemCategoryMainViewModel(); using (ERPContext context = new ERPContext()) { var company = context.ItemCategoryMain.Find(id); if (company != null) { model.CategoryId = company.CategoryId; model.CategoryName = company.CategoryName; model.Abb = company.Abb; return(model); } } return(null); }
public IEnumerable <ItemCategoryMainViewModel> GetCategories() { using (ERPContext context = new ERPContext()) { var categoryList = context.ItemCategoryMain.ToList(); if (categoryList != null) { List <ItemCategoryMainViewModel> _ICMainVMList = new List <ItemCategoryMainViewModel>(); foreach (var item in categoryList) { ItemCategoryMainViewModel model = new ItemCategoryMainViewModel(); model.CategoryId = item.CategoryId; model.CategoryName = item.CategoryName; model.Abb = item.Abb; _ICMainVMList.Add(model); } return(_ICMainVMList); } } return(null); }