public async Task <IResultModel> Update(MenuUpdateModel model) { var entity = await _menuRepository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("菜单不存在!")); } entity = _mapper.Map(model, entity); using (var tran = _menuRepository.BeginTransaction()) { var result = await _menuRepository.UpdateAsync(entity); if (result) { //同步菜单权限 if (await SyncPermission(entity, model.Permissions, tran)) { //同步按钮 if (await SyncButton(entity, model.Buttons, tran)) { tran.Commit(); return(ResultModel.Success()); } } } } return(ResultModel.Failed()); }
public async Task <ActionResult> Insert(MenuUpdateModel model) { string msg = string.Empty; if (ModelState.IsValid) { var dto = _mapper.Map <MenuDto>(model); dto.CreatedBy = User.Identity.Name; dto.ModifiedBy = User.Identity.Name; var resultDict = await InsertAsync(dto); if (resultDict.ContainsKey(true)) { return(RedirectToAction(Constant.Action.Index, Constant.Controller.Menu, new { })); } msg = (" " + resultDict.Select(x => x.Value).FirstOrDefault()); } if (string.IsNullOrEmpty(msg)) { msg = string.Concat("Tạo mới không thành công. Vui lòng thử lại!", msg); } else { string.Concat(msg, ". Vui lòng thử lại!"); } ModelState.AddModelError("ErrSubmit", (msg)); return(View(model)); }
public async Task <IResultModel> Update(MenuUpdateModel model) { var entity = await _menuRepository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("菜单不存在!")); } entity = _mapper.Map(model, entity); using (var uow = _dbContext.NewUnitOfWork()) { var result = await _menuRepository.UpdateAsync(entity); if (result) { //同步菜单权限 if (await SyncPermission(entity, model.Permissions, uow)) { //同步按钮 if (await SyncButton(entity, model.Buttons, uow)) { await ClearAccountPermissionCache(entity); uow.Commit(); return(ResultModel.Success()); } } } } return(ResultModel.Failed()); }
public async Task <IResultModel> Update(MenuUpdateModel model) { var entity = await _menuRepository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("菜单不存在!")); } entity = _mapper.Map(model, entity); var result = await _menuRepository.UpdateAsync(entity); return(ResultModel.Result(result)); }
public async Task <ActionResult> Update(MenuUpdateModel model) { if (ModelState.IsValid) { var dto = _mapper.Map <MenuDto>(model); dto.ModifiedBy = User.Identity.Name; var result = await this.UpdateAsync(dto); if (result) { return(RedirectToAction(Constant.Action.Index, Constant.Controller.Menu, new { })); } } ModelState.AddModelError("ErrSubmit", "Lỗi! cập nhật chữ ký"); return(View(model)); }
public async Task <IResultModel> Update(MenuUpdateModel model) { var entity = await _menuRepository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("菜单不存在!")); } entity = _mapper.Map(model, entity); var result = await _menuRepository.UpdateAsync(entity); if (result) { await ClearAccountPermissionCache(entity); return(ResultModel.Success()); } return(ResultModel.Failed()); }
public ActionResult Insert() { var model = new MenuUpdateModel(); var lstMenu = _menuService.GetAllRecursive(); var roles = _menuService.GetAllRole(); model.LstMenu = lstMenu .Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }); model.ListRole = roles .Select(x => new SelectListItem { Text = x.Name, Value = x.ID.ToString() }); return(View(model)); }
private async Task UpdateMenu(SqlConnection connection1, MenuUpdateModel model) { String commandText1 = "update menu set menu = @menu, entitie = @entitie " + "where id = @id"; SqlCommand command1 = new SqlCommand(commandText1, connection1); SqlParameter parameter = new SqlParameter("@id", SqlDbType.VarChar); parameter.Value = model.id; command1.Parameters.Add(parameter); parameter = new SqlParameter("@menu", SqlDbType.VarChar); parameter.Value = model.menu; command1.Parameters.Add(parameter); parameter = new SqlParameter("@entitie", SqlDbType.VarChar); parameter.Value = model.entitie; command1.Parameters.Add(parameter); await command1.ExecuteNonQueryAsync(); }
private async Task SaveMenu(SqlConnection connection1, MenuUpdateModel model) { String commandText1 = "INSERT INTO menu " + "(id,menu,entitie,status) " + "values (@id,@menu,@entitie,1)"; SqlCommand command1 = new SqlCommand(commandText1, connection1); SqlParameter parameter = new SqlParameter("@id", SqlDbType.VarChar); parameter.Value = model.id; command1.Parameters.Add(parameter); parameter = new SqlParameter("@menu", SqlDbType.VarChar); parameter.Value = model.menu; command1.Parameters.Add(parameter); parameter = new SqlParameter("@entitie", SqlDbType.VarChar); parameter.Value = model.entitie; command1.Parameters.Add(parameter); await command1.ExecuteNonQueryAsync(); }
public async Task <IResultModel> Update(MenuUpdateModel model) { var entity = await _menuRepository.FirstAsync(model.Id); if (entity == null) { return(ResultModel.NotExists); } if (!string.IsNullOrEmpty(model.RouteName) && await _menuRepository.ExistsAsync(m => m.RouteName == model.RouteName && m.MenuName == model.MenuName && m.Id != entity.Id && m.IsDel == false)) { return(ResultModel.HasExists); } _mapper.Map(model, entity); if (!string.IsNullOrEmpty(entity.ParentId)) { var parent = await _menuRepository.FirstAsync(m => m.Id == entity.ParentId); if (parent != null) { entity.Level = parent.Level + 1; } } var result = await _menuRepository.UpdateAsync(entity); if (result) { await ClearCache(); return(ResultModel.Success(entity)); } return(ResultModel.Failed()); }
public async Task <IResultModel> Update(MenuUpdateModel model) { return(await _service.Update(model)); }
public Task <IResultModel> Update(MenuUpdateModel model) { return(_service.Update(model)); }
public async Task <ActionResult> Update(Guid id) { var model = new MenuUpdateModel(); var iquery = await _menuService.GetByIdAsync(id); if (iquery != null) { var lstMenu = _menuService.GetAllRecursive(); var roles = _menuService.GetAllRole(); model = new MenuUpdateModel { Id = iquery.Id, ParentId = iquery.ParentId, Layout = iquery.Layout, Status = iquery.Status, TypeModule = iquery.TypeModule, Name = iquery.Name, Code = iquery.Code, Target = iquery.Target, NavNodeId = iquery.NavNodeId, Icon = iquery.Icon, Order = iquery.Order, GroupOrUsers = iquery.GroupOrUsers, Action = Common.CommonValues.Action.Update, ListRole = roles.Select(x => new SelectListItem { Text = x.Name, Value = x.ID.ToString(), Selected = !string.IsNullOrEmpty(iquery.Roles) && iquery.Roles.Contains(x.ID.ToString()) ? true : false }), LstMenu = lstMenu .Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }) }; List <SelectListItem> listGroupOrUser = new List <SelectListItem>(); if (!string.IsNullOrEmpty(model.GroupOrUsers)) { var groupOrUsers = model.GroupOrUsers.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var item in groupOrUsers) { var listItem = new SelectListItem(); if (item.Contains("_User")) { var userId = new Guid(item.Replace("_User", "")); var user = _userServices.GetById(userId); listItem.Text = user.FullName + " (" + user.UserName + ")"; listItem.Value = item; } if (item.Contains("_Group")) { var groupId = new Guid(item.Replace("_Group", "")); var group = _groupServices.GetById(groupId); listItem.Text = group.Name; listItem.Value = item; } listGroupOrUser.Add(listItem); } } model.ListGroupOrUser = listGroupOrUser; if (iquery.NavNodeId.HasValue) { var iqueryNav = await _navNodeService.GetByIdAsync(iquery.NavNodeId.Value); if (iqueryNav != null) { StringBuilder _display = new StringBuilder(); if (!string.IsNullOrEmpty(iqueryNav.Areas)) { _display.Append(string.Concat("/", iqueryNav.Areas)); } if (!string.IsNullOrEmpty(iqueryNav.Controller)) { _display.Append(string.Concat("/", iqueryNav.Controller)); } if (!string.IsNullOrEmpty(iqueryNav.Action)) { _display.Append(string.Concat("/", iqueryNav.Action)); } if (!string.IsNullOrEmpty(iqueryNav.Params)) { _display.Append(string.Concat("?", iqueryNav.Params)); } model.Link = _display.ToString(); model.navAutocomplete = iqueryNav.Name; } } } return(View(model)); }
internal async Task Update(SqlConnection connection1, MenuUpdateModel model) { await UpdateMenu(connection1, model); }