public void CreateTest() { var group = new Group { Name = "TestGroup" + DateTime.Now.Ticks, Description = "test", Rights = new List<GroupRight> { new GroupRight{Name= "TEST.UPDATE"}, new GroupRight{Name="TEST.ADD" } } }; target.Create(group); using (var db = DbHelper.GetDataContext()) { var entity = db.Group.Where(e => e.Name == group.Name).FirstOrDefault(); Assert.AreNotEqual(null, entity); var rights = db.GroupRight.Where(e => e.GroupID == entity.GroupId).Select(e => e.Name).ToList(); Assert.AreEqual("TEST.UPDATE,TEST.ADD", string.Join(",", rights)); } }
public void Create(Group group) { using (var db = GetDataContext()) { db.Group.Add(group); db.SaveChanges(); AddRights(group); } }
public ActionResult Edit(Group group, string rights) { if (!string.IsNullOrEmpty(rights)) { group.Rights = rights.Replace("\r", "").Split('\n').Select(s => new GroupRight { Name = s, GroupID = group.GroupId }); } Core.GroupManager.Save(group); return JsonSuccess(); }
public void Update(Group group) { using (var db = GetDataContext()) { var toUpdate = db.Group.FirstOrDefault(e => e.GroupId == group.GroupId); if (toUpdate == null) { throw new ArgumentException("更新失败,没找到这个组!"); } RemoveRigths(toUpdate.GroupId); db.Entry(toUpdate).CurrentValues.SetValues(group); db.SaveChanges(); AddRights(group); } }
public void Save(Group group) { if (string.IsNullOrEmpty(group.Name)) { throw new ArgumentNullException("用户组名称没有填写!"); } if (group.GroupId > 0) { Dao.Update(group); } else { Dao.Create(group); } }
private void AddRights(Group group) { if (group.Rights == null) return; using (var db = GetDataContext()) { foreach (var right in group.Rights) { right.GroupID = group.GroupId; db.GroupRight.Add(right); } db.SaveChanges(); } }