public IHttpActionResult CreateRole(Role role) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Roles.Add(role); db.SaveChanges(); return Created<Role>("DefaultApi", role); }
public User(string _name, string _firstApe, string _secondApe, string _firstEmail, int _cedula, string _password, bool _active, Role _role) { name = _name; firstApe = _firstApe; secondApe = _secondApe; firstEmail = _firstEmail; cedula = _cedula; password = _password; datePassword = DateTime.Now; active = _active; role = _role; passwordChangeRequired = false; candidates = new HashSet<Candidate>(); events = new HashSet<Event>(); kpis = new HashSet<Kpi>(); }
public IHttpActionResult UpdateRole(Role role) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Role oldRole = db.Roles.Find(role.RoleID); if (oldRole != null) { db.Entry(oldRole).Collection(i => i.Permissions).Load(); oldRole.Permissions.Clear(); foreach (var permissionId in role.Permissions) { var permission = db.Permissions.Find(permissionId.PermissionID); oldRole.Permissions.Add(permission); } db.Entry(oldRole).State = EntityState.Modified; db.SaveChanges(); return Ok(); } else { return StatusCode(HttpStatusCode.NotFound); } }