Beispiel #1
0
 public int AssignRolesToUser(int RoleId, int UserId)
 {
     try
     {
         var query = from o in obj.UserRolesContainers where o.userId == UserId select o;
         DB.UserRolesContainer urc = new DB.UserRolesContainer();
         if (query.Count() == 0)
         {
             urc.RolesId = RoleId;
             urc.userId  = UserId;
             obj.UserRolesContainers.InsertOnSubmit(urc);
             obj.SubmitChanges();
         }
         else
         {
             foreach (var item in query)
             {
                 item.RolesId = RoleId;
                 item.userId  = UserId;
             }
             obj.SubmitChanges();
         }
         return(1);
     }
     catch
     {
         return(-1);
     }
 }
Beispiel #2
0
        public int Save(Models.MUserRolesContainer model)
        {
            Common.Logger l         = new Common.Logger();
            string        ClassName = "CUserRolesContainer";

            try
            {
                DB.UserRolesContainer bs = new DB.UserRolesContainer();
                bs.id     = int.Parse(model.id);
                bs.userId = int.Parse(model.userId);


                l.Print(ClassName, Common.LogPointer.Info.ToString(), "Model Values id[" + model.id + "] userId[" + model.userId + "] RolesId[" + model.Rolesid + "] ");
                obj.UserRolesContainers.InsertOnSubmit(bs);
                obj.SubmitChanges();
                l.Print(ClassName, Common.LogPointer.Info.ToString(), "Record Inserted Successfully");
                return(1);
            }
            catch (Exception ex)
            {
                l.Print(ClassName, Common.LogPointer.Error.ToString(), ex.ToString());
                return(-1);
            }
        }