Ejemplo n.º 1
0
 public void Update(long roleId, string roleName)
 {
     using (Dbcontext ctx = new Dbcontext())
     {
         BaseService <Role> roleBS = new BaseService <Role>(ctx);
         bool exists = roleBS.GetAll().Any(r => r.Name == roleName && r.Id != roleId);
         if (exists)
         {
             throw new ArgumentException("角色名字已存在" + roleName);
         }
         Role role = new Role();
         role.Id = roleId;
         ctx.Entry(role).State = System.Data.Entity.EntityState.Unchanged;
         role.Name             = roleName;
         ctx.SaveChanges();
     }
 }