Exemplo n.º 1
0
 public void AddUserToRol(SiteAddRol Model)
 {
     using (var _c = db)
     {
         var _Model = _c.SiteUserRoles.Where(m => m.UserID == Model.UserID && m.SiteID == Model.SiteID
             && m.SiteUserType == Model.SiteUserType).SingleOrDefault();
         if (_Model == null)
         {
             if (Model.Enabled)
             {
                 _Model = new SiteUserRol
                 {
                     SiteID = Model.SiteID,
                     SiteUserType = Model.SiteUserType,
                     UserID = Model.UserID
                 };
                 _c.SiteUserRoles.Add(_Model);
             }
         }
         else
         {
             if (!Model.Enabled)
             {
                 _c.SiteUserRoles.Remove(_Model);
             }
         }
         _c.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public void AddUserToAllRoles(AddUserInSiteBinding Model)
 {
     using (var _c = db)
     {
         var _AU = new UserBLL().Find(Model.Email);
         if (_AU == null)
         {
             if (string.IsNullOrEmpty(Model.Password))
                 throw new RuleException("User not exist you have to add a Password");
             if (string.IsNullOrEmpty(Model.Name))
                 throw new RuleException("User not exist you have to add a Name");
             _AU = new UserBLL().Create(Model.Name, Model.Email, Model.Password);
         }
         var _CU = _c.SiteUsers.Where(m => m.UserID == _AU.Id && m.SiteID == Model.SiteID).SingleOrDefault();
         if (_CU == null)
         {
             _CU = new SiteUser
             {
                 SiteID = Model.SiteID,
                 UserID = _AU.Id,
                 SiteUserRoles = new List<SiteUserRol>()
             };
             _c.SiteUsers.Add(_CU);
         }
         _c.SiteUserRoles.RemoveRange(_c.SiteUserRoles.Where(m => m.UserID == _AU.Id && m.SiteID == Model.SiteID));
         var _CR1 = new SiteUserRol
         {
             SiteID = Model.SiteID,
             UserID = _AU.Id,
             SiteUserType = SiteUserType.CONTENT
         };
         _c.SiteUserRoles.Add(_CR1);
         _c.SaveChanges();
     }
 }