public async Task <IActionResult> Edit(AdminMenuEditViewModel model) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return(Forbid()); } var adminMenuList = await _adminMenuService.LoadAdminMenuListAsync(); var adminMenu = _adminMenuService.GetAdminMenuById(adminMenuList, model.Id); if (adminMenu == null) { return(NotFound()); } if (ModelState.IsValid) { adminMenu.Name = model.Name; await _adminMenuService.SaveAsync(adminMenu); _notifier.Success(H["Admin menu updated successfully"]); return(RedirectToAction(nameof(List))); } return(View(model)); }
public async Task <IActionResult> Edit(AdminMenuEditViewModel model) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return(Unauthorized()); } var tree = await _AdminMenuService.GetByIdAsync(model.Id); if (tree == null) { return(NotFound()); } if (ModelState.IsValid) { tree.Name = model.Name; await _AdminMenuService.SaveAsync(tree); _notifier.Success(H["Admin menu updated successfully"]); return(RedirectToAction(nameof(List))); } return(View(model)); }
private AdminMenuEditViewModel CreateEditMenuViewModel(Menu menu) { var viewModel = new AdminMenuEditViewModel { Id = menu.Id, ParentMenu = menu.Menu_Id, Name = menu.Name, Description = menu.Description, Colour = menu.Colour, iType = menu.iType, SortOrder = menu.SortOrder, AllMenus = _menuService.GetBaseSelectListMenus(_menuService.GetMenusParenMenu(menu)), AllType = GetTypeLink(), AllPage = GetPageLink(), AllCat = _categoryService.GetBaseSelectListCategories(_categoryService.GetAll()), }; switch (menu.iType) { case 0: viewModel.Link = menu.Link; break; case 1: viewModel.LinkPage = menu.Link; break; case 2: viewModel.LinkCat = menu.Link; break; case 3: if (!menu.Link.IsNullEmpty()) { var a = _topicService.Get(new Guid(menu.Link)); if (a != null) { viewModel.LinkNews = menu.Link; viewModel.TitleNews = a.Name; } } break; case 4: if (!menu.Link.IsNullEmpty()) { var b = _productSevice.Get(new Guid(menu.Link)); if (b != null) { viewModel.LinkProduct = menu.Link; viewModel.TitleProduct = b.Name; } } break; } return(viewModel); }
public ActionResult Create() { var ViewModel = new AdminMenuEditViewModel { AllMenus = _menuService.GetBaseSelectListMenus(_menuService.GetAll()), AllType = GetTypeLink(), AllPage = GetPageLink(), AllCat = _categoryService.GetBaseSelectListCategories(_categoryService.GetAll()), }; return(View(ViewModel)); }
public async Task <IActionResult> Edit(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return(Unauthorized()); } var tree = await _AdminMenuService.GetByIdAsync(id); if (tree == null) { return(NotFound()); } var model = new AdminMenuEditViewModel { Id = tree.Id, Name = tree.Name }; return(View(model)); }
public async Task <IActionResult> Edit(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return(Forbid()); } var adminMenuList = await _adminMenuService.GetAdminMenuListAsync(); var adminMenu = _adminMenuService.GetAdminMenuById(adminMenuList, id); if (adminMenu == null) { return(NotFound()); } var model = new AdminMenuEditViewModel { Id = adminMenu.Id, Name = adminMenu.Name }; return(View(model)); }
public ActionResult Create(AdminMenuEditViewModel viewModel) { if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var menu = new Menu { Menu_Id = viewModel.ParentMenu, Name = viewModel.Name, Description = viewModel.Description, Colour = viewModel.Colour, iType = viewModel.iType, SortOrder = viewModel.SortOrder }; switch (menu.iType) { case 0: menu.Link = viewModel.Link; break; case 1: menu.Link = viewModel.LinkPage; break; case 2: menu.Link = viewModel.LinkCat; break; case 3: menu.Link = viewModel.LinkNews; break; case 4: menu.Link = viewModel.LinkProduct; break; } // Sort image out first if (viewModel.Files != null) { // Before we save anything, check the user already has an upload folder and if not create one var uploadFolderPath = HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath, menu.Id)); if (!Directory.Exists(uploadFolderPath)) { Directory.CreateDirectory(uploadFolderPath); } // Loop through each file and get the file info and save to the users folder and Db var file = viewModel.Files[0]; if (file != null) { // If successful then upload the file var uploadResult = AppHelpers.UploadFile(file, uploadFolderPath, LocalizationService, true); if (!uploadResult.UploadSuccessful) { TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = uploadResult.ErrorMessage, MessageType = GenericMessages.danger }; return(View(viewModel)); } // Save avatar to user menu.Image = uploadResult.UploadedFileName; } } //if (categoryViewModel.ParentCategory != null) //{ // var parentCategory = _categoryService.Get(categoryViewModel.ParentCategory.Value); // category.ParentCategory = parentCategory; // SortPath(category, parentCategory); //} _menuService.Add(menu); unitOfWork.Commit(); // We use temp data because we are doing a redirect TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Thêm menu thành công", MessageType = GenericMessages.success }; return(RedirectToAction("Index")); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex.Message); ModelState.AddModelError("", "Có lỗi xảy ra khi thêm menu"); } } } else { ModelState.AddModelError("", "There was an error creating the category"); } viewModel.AllMenus = _menuService.GetBaseSelectListMenus(_menuService.GetAll()); viewModel.AllType = GetTypeLink(); viewModel.AllPage = GetPageLink(); viewModel.AllCat = _categoryService.GetBaseSelectListCategories(_categoryService.GetAll()); return(View(viewModel)); }
public ActionResult Edit(AdminMenuEditViewModel viewModel) { var menu = _menuService.Get(viewModel.Id); if (menu == null) { RedirectToAction("Index"); } if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { // Check they are not trying to add a subcategory of this category as the parent or it will break var cats = _menuService.GetMenusParenMenu(menu); var lst = cats.Where(x => x.Id == viewModel.ParentMenu).ToList(); if (lst.Count == 0) { viewModel.ParentMenu = null; } //categoryViewModel.AllCategories = _categoryService.GetBaseSelectListCategories(cats); viewModel.Image = menu.Image; // Sort image out first if (viewModel.Files != null) { // Before we save anything, check the user already has an upload folder and if not create one var uploadFolderPath = HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath, viewModel.Id)); if (!Directory.Exists(uploadFolderPath)) { Directory.CreateDirectory(uploadFolderPath); } // Loop through each file and get the file info and save to the users folder and Db var file = viewModel.Files[0]; if (file != null) { // If successful then upload the file var uploadResult = AppHelpers.UploadFile(file, uploadFolderPath, LocalizationService, true); if (!uploadResult.UploadSuccessful) { TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = uploadResult.ErrorMessage, MessageType = GenericMessages.danger }; return(View(viewModel)); } // Save avatar to user viewModel.Image = uploadResult.UploadedFileName; } } menu.Image = viewModel.Image; menu.Menu_Id = viewModel.ParentMenu; menu.Name = viewModel.Name; menu.Description = viewModel.Description; menu.Colour = viewModel.Colour; menu.iType = viewModel.iType; switch (menu.iType) { case 0: menu.Link = viewModel.Link; break; case 1: menu.Link = viewModel.LinkPage; break; case 2: menu.Link = viewModel.LinkCat; break; case 3: menu.Link = viewModel.LinkNews; break; case 4: menu.Link = viewModel.LinkProduct; break; } menu.SortOrder = viewModel.SortOrder; _menuService.Update(menu); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Cập nhật thành công", MessageType = GenericMessages.success }; unitOfWork.Commit(); } catch (Exception ex) { LoggingService.Error(ex); unitOfWork.Rollback(); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Có lỗi xảy ra khi cập nhật menu", MessageType = GenericMessages.danger }; } } } viewModel.AllMenus = _menuService.GetBaseSelectListMenus(_menuService.GetMenusParenMenu(menu)); viewModel.AllType = GetTypeLink(); viewModel.AllPage = GetPageLink(); viewModel.AllCat = _categoryService.GetBaseSelectListCategories(_categoryService.GetAll()); return(View(viewModel)); }
public ActionResult Edit(AdminMenuEditViewModel viewModel) { var menu = _menuService.Get(viewModel.Id); if (menu == null) { RedirectToAction("Index"); } if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { // Check they are not trying to add a subcategory of this category as the parent or it will break var cats = _menuService.GetMenusParenMenu(menu); var lst = cats.Where(x => x.Id == viewModel.ParentMenu).ToList(); if (lst.Count == 0) { viewModel.ParentMenu = null; } //categoryViewModel.AllCategories = _categoryService.GetBaseSelectListCategories(cats); menu.Image = viewModel.Image; menu.Menu_Id = viewModel.ParentMenu; menu.Name = viewModel.Name; menu.Description = viewModel.Description; menu.Colour = viewModel.Colour; menu.iType = viewModel.iType; switch (menu.iType) { case 0: menu.Link = viewModel.Link; break; case 1: menu.Link = viewModel.LinkPage; break; //case 2: // menu.Link = viewModel.LinkCat; // break; case 6: menu.Link = viewModel.LinkCatNews; break; case 7: menu.Link = viewModel.LinkCatProduct; break; case 3: menu.Link = viewModel.LinkNews; break; case 4: menu.Link = viewModel.LinkProduct; break; case 5: menu.Link = viewModel.LinkGroupProduct; break; } menu.SortOrder = viewModel.SortOrder; _menuService.Update(menu); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Cập nhật thành công", MessageType = GenericMessages.success }; unitOfWork.Commit(); } catch (Exception ex) { LoggingService.Error(ex); unitOfWork.Rollback(); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Có lỗi xảy ra khi cập nhật menu", MessageType = GenericMessages.danger }; } } } viewModel.AllMenus = _menuService.GetBaseSelectListMenus(_menuService.GetMenusParenMenu(menu)); viewModel.AllType = GetTypeLink(); viewModel.AllPage = GetPageLink(); //viewModel.AllCat = _categoryService.GetBaseSelectListCategories(_categoryService.GetAll()); viewModel.AllCatNews = _categoryService.GetBaseSelectListCategories(_categoryService.GetList(false)); viewModel.AllCatProduct = _categoryService.GetBaseSelectListCategories(_categoryService.GetList(true)); return(View(viewModel)); }
public ActionResult Create(AdminMenuEditViewModel viewModel) { if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var menu = new Menu { Menu_Id = viewModel.ParentMenu, Name = viewModel.Name, Description = viewModel.Description, Colour = viewModel.Colour, iType = viewModel.iType, SortOrder = viewModel.SortOrder, Image = viewModel.Image, }; switch (menu.iType) { case 0: menu.Link = viewModel.Link; break; case 1: menu.Link = viewModel.LinkPage; break; //case 2: // menu.Link = viewModel.LinkCat; // break; case 6: menu.Link = viewModel.LinkCatNews; break; case 7: menu.Link = viewModel.LinkCatProduct; break; case 3: menu.Link = viewModel.LinkNews; break; case 4: menu.Link = viewModel.LinkProduct; break; case 5: menu.Link = viewModel.LinkGroupProduct; break; } //if (categoryViewModel.ParentCategory != null) //{ // var parentCategory = _categoryService.Get(categoryViewModel.ParentCategory.Value); // category.ParentCategory = parentCategory; // SortPath(category, parentCategory); //} _menuService.Add(menu); unitOfWork.Commit(); // We use temp data because we are doing a redirect TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Thêm menu thành công", MessageType = GenericMessages.success }; return(RedirectToAction("Index")); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex.Message); ModelState.AddModelError("", "Có lỗi xảy ra khi thêm menu"); } } } else { ModelState.AddModelError("", "There was an error creating the category"); } viewModel.AllMenus = _menuService.GetBaseSelectListMenus(_menuService.GetAll()); viewModel.AllType = GetTypeLink(); viewModel.AllPage = GetPageLink(); //viewModel.AllCat = _categoryService.GetBaseSelectListCategories(_categoryService.GetAll()); viewModel.AllCatNews = _categoryService.GetBaseSelectListCategories(_categoryService.GetList(false)); viewModel.AllCatProduct = _categoryService.GetBaseSelectListCategories(_categoryService.GetList(true)); return(View(viewModel)); }