public ActionResult Input(CategoryModel model) { if (ModelState.IsValid) { Category category = null; try { if (model.Id > 0) category = _categoryService.Find(model.Id); else category = new Category() { CreatedDate = DateTime.Now }; #region Set value for category entity category.Name = model.Name; category.Alias = model.Alias; category.Brief = model.Brief; category.Description = model.Description; category.IsActive = model.IsActive; category.IsFeature = model.IsFeature; category.DisplayOrder = model.DisplayOrder; category.Thumbnail = model.Thumbnail != null ? model.Thumbnail : "default.jpg"; category.RootId = model.RootId;// //category.HowIt = model.HowIt; //category.KeyBenefit = model.KeyBenefit; //category.Solution = model.Solution; category.EnableGallery = model.EnableGallery; //category.EnablePrintCapbility = model.EnablePrintCapbility; category.UpdatedDate = DateTime.Now; #endregion #region Perform save data if (model.Id <= 0) { using (TransactionScope scope = new TransactionScope()) { _categoryService.Insert(category); _unitOfWork.SaveChanges(); scope.Complete(); } } else { using (TransactionScope scope = new TransactionScope()) { _categoryService.Update(category); _unitOfWork.SaveChanges(); scope.Complete(); } } return Json(new { Status = ResultStatus.Success, Message = StringTable.DataSaveSuccess }); #endregion } catch { return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess }); } } else { return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess }); } }
public ActionResult Input(int id = 0) { var category = _categoryService.Find(id); if (category == null) { category = new Category() { DisplayOrder = 1000, IsActive = true, IsFeature = true, EnablePrintCapbility = true, EnableGallery = true }; } var model = category.ToModel(); var categories = GetListCategory(); if (id > 0) categories = categories.Where(x => x.Value != id.ToString()).ToList(); ViewData["ListCategory"] = categories; return View(model); }