public IHttpActionResult PostAddUser(AddUserInSiteBinding Model)
 {
     SiteService.AddUserToAllRoles(Model);
     return Ok();
 }
Exemple #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();
     }
 }