Ejemplo n.º 1
0
Archivo: User.cs Proyecto: radtek/canon
        public static void UpdateRightsRelation(int userId, int rightId, bool relationExist)
        {
            CanonDataContext db = Cdb.Instance;

            try
            {
                UsersRight uc = db.UsersRights.First(u => u.UserId == userId && u.Rights == rightId);
                if (!relationExist)
                {
                    db.UsersRights.DeleteOnSubmit(uc);
                }
            }
            catch (Exception ex)
            {
                //there is no such relation
                if (relationExist)
                {
                    UsersRight newUc = new UsersRight();
                    newUc.Rights = rightId;
                    newUc.UserId = userId;
                    db.UsersRights.InsertOnSubmit(newUc);
                }
            }
            db.SubmitChanges();
        }
Ejemplo n.º 2
0
 public static void UpdateRightsRelation(int userId, int rightId, bool relationExist)
 {
     CanonDataContext db = Cdb.Instance;
     try
     {
         UsersRight uc = db.UsersRights.First(u => u.UserId == userId && u.Rights == rightId);
         if (!relationExist)
             db.UsersRights.DeleteOnSubmit(uc);
     }
     catch (Exception ex)
     {
         //there is no such relation
         if (relationExist)
         {
             UsersRight newUc = new UsersRight();
             newUc.Rights = rightId;
             newUc.UserId = userId;
             db.UsersRights.InsertOnSubmit(newUc);
         }
     }
     db.SubmitChanges();
 }