public ActionResult Create(FormCollection collection) { var model = new Role(); TryUpdateModel(model, collection.ToValueProvider()); if (!ModelState.IsValid) { return View(model); } using (var session = new SessionFactory().OpenSession()) { if (session.Load<Role>(m => m.Name.Equals(model.Name)) != null) { FlashFailure("角色名称[{0}]已经存在,创建失败!", model.Name); return View(model); } model.CreatedAt = DateTime.Now; model.CreatedBy = CurrentAccountNo; ViewData.Model = model; if (session.Create(model)) { FlashSuccess("角色[{0}]创建成功", model.Name); return Close(); } FlashFailure("创建角色[{0}]失败!", model.Name); return View(model); } }
public static SelectList RoleList() { var ds = new SessionFactory().OpenSession(); var d = ds.Find<Role>(); var item = new Role() { Id = 0, Name = "无" }; d.Add(item); return new SelectList(d, "Id", "Name"); }
//public bool AddOrganization(Organization organization) //{ // if (organization == null || organization.Id <= 0) return false; // if (Id <= 0) return false; // var q = new Criteria<AccountOrganizationRef>().Where(m => m.AccountId.Equals(Id) && m.OrganizationId.Equals(organization.Id)); // if (q.Count() > 0) return true; // var r = new AccountOrganizationRef { AccountId = Id, OrganizationId = organization.Id }; // var db = new SessionFactory().OpenSession(); // return db.Create(r); //} public bool AddRole(Role role) { if (role == null || role.Id <= 0) return false; if (Id <= 0) return false; Criteria<AccountRoleRef> q = new Criteria<AccountRoleRef>().Where(m => m.AccountId.Equals(Id) && m.RoleId.Equals(role.Id)); if (q.Count() > 0) return true; Session db = new SessionFactory().OpenSession(); var r = new AccountRoleRef { AccountId = Id, RoleId = role.Id }; return db.Create(r); }