public async Task <IActionResult> Create(DefaultModel model, CPRoleEntity item) { ViewBag.Title = "Thêm mới"; if (!string.IsNullOrEmpty(model.ID) || !string.IsNullOrEmpty(item.ID)) { return(RedirectToAction("Edit", new { model.ID })); } else { if (string.IsNullOrEmpty(item.Name)) { ViewBag.Message = "Bạn chưa điện tên của nhóm"; return(View()); } else { item.Code = UnicodeName.ConvertUnicodeToCode(item.Name, "-", true); if (_service.GetItemByCode(item.Code) == null) { await _service.AddAsync(item); ViewBag.Message = "Thêm thành công"; } else { ViewBag.Message = "Nhóm người đã tồn tại"; return(View()); } } } return(View()); }
public async Task <IActionResult> Edit(DefaultModel model, CPRoleEntity item) { ViewBag.Title = "Chỉnh sửa"; if (string.IsNullOrEmpty(model.ID) && string.IsNullOrEmpty(item.ID)) { ViewBag.Message = "Chưa chọn đối tượng đê sửa"; } else { string ID = !string.IsNullOrEmpty(model.ID) ? model.ID : item.ID; var _item = _service.GetByID(ID); if (!_item.Lock) { item.ID = _item.ID; if (string.IsNullOrEmpty(item.Name)) { item.Name = _item.Name; } if (string.IsNullOrEmpty(item.Code)) { item.Code = UnicodeName.ConvertUnicodeToCode(item.Name, "-", true); } await _service.AddAsync(item); } ViewBag.Data = _service.GetByID(ID); } ViewBag.Model = model; return(RedirectToAction("index")); }
public static string ShowDDLMenuByType(string type, int langID, int selectID) { List <ListItem.Item> list = ListItem.List.GetList(WebMenuService.Instance, langID, type); int userId = CPLogin.CurrentUser.ID; CPUserRoleEntity userRole = CPUserRoleService.Instance.CreateQuery().Where(o => o.UserID == userId).ToSingle(); CPRoleEntity role = null; if (userRole != null) { role = CPRoleService.Instance.CreateQuery().Where(o => o.ID == userRole.RoleID).ToSingle(); } string s = string.Empty; for (int i = 0; list != null && i < list.Count; i++) { if (type == "News" && role != null && role.MenuIDs != null && role.MenuIDs.Contains(list[i].Value)) { s += "<option " + (list[i].Value == selectID.ToString() ? "selected" : string.Empty) + " value=\"" + list[i].Value + "\"> " + list[i].Name + "</option>"; } if (type != "News") { s += "<option " + (list[i].Value == selectID.ToString() ? "selected" : string.Empty) + " value=\"" + list[i].Value + "\"> " + list[i].Name + "</option>"; } } return(s); }
public static string GetRoleByLoginName(string loginName) { string role = string.Empty; CPUserEntity u = CPUserService.Instance.CreateQuery().Where(o => o.Activity == true && o.LoginName == loginName).ToSingle(); if (u == null) { return(role); } CPUserRoleEntity r = CPUserRoleService.Instance.CreateQuery().Where(o => o.UserID == u.ID).ToSingle(); if (r == null) { return(role); } CPRoleEntity ur = CPRoleService.Instance.CreateQuery().Where(o => o.ID == r.RoleID).ToSingle(); if (ur == null) { return(role); } role = ur.Code; return(role); }
public void ActionAdd(SysRoleModel model) { if (model.RecordID > 0) { item = CPRoleService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { item = new CPRoleEntity(); // khoi tao gia tri mac dinh khi insert item.Order = GetMaxOrder(model); } ViewBag.Data = item; ViewBag.Model = model; }
public void ActionAdd(SysRoleModel model) { if (model.RecordID > 0) { entity = CPRoleService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { entity = new CPRoleEntity(); // khoi tao gia tri mac dinh khi insert entity.Order = GetMaxOrder(model); } listCPModule = CPModuleService.Instance.CreateQuery().ToList(); ViewBag.Data = entity; ViewBag.Model = model; ViewBag.CPModule = listCPModule; }
public override void ActionDelete(int[] arrID) { for (int i = 0; i < arrID.Length; i++) { int id = arrID[i]; CPRoleEntity _Item = CPRoleService.Instance.GetByID(id); if (_Item.Lock) { continue; } //thuc thi CPUserRoleService.Instance.Delete(o => o.RoleID == id); CPAccessService.Instance.Delete(o => o.RoleID == id); CPRoleService.Instance.Delete(id); } //thong bao CPViewPage.SetMessage("Đã xóa thành công."); CPViewPage.RefreshPage(); }