public IHttpActionResult PostAddRol(SiteAddRol Model) { SiteService.AddUserToRol(Model); return Ok(); }
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(); } }