public ActionResult Update(int Id) { CategoryModel model = new CategoryModel(); if (Id <= 0) { model.Category = new Entities.Category(); model.Category.Display = true; } else { model.Category = _service.GetById(Id); } model.ListCategory = _service.ListItem(); model.ListCategory.Insert(0, new Entities.Item() { Text = "", Id = 0 }); model.ListCategoryType = DefaultData.ListCategoryType(); return(View(model)); }
public ActionResult Update(CategoryModel model) { var listCategoryType = DefaultData.ListCategoryType(); if (ModelState.IsValid) { model.Category.TypeText = listCategoryType.Where(x => x.Id == model.Category.Type).Select(x => x.Text).First(); int result = _service.Save(model.Category); if (result > 0) { TempData[AdminConfigs.TEMP_MESSAGE] = AdminConfigs.MESSAGE_UPDATE_SUCCESS; TempData[AdminConfigs.TEMP_REDIRECT] = @Url.Action("Index", "Category"); } else { TempData[AdminConfigs.TEMP_MESSAGE] = AdminConfigs.MESSAGE_UPDATE_ERROR; } } model.ListCategory = _service.ListItem(); model.ListCategoryType = listCategoryType; return(View(model)); }