public IHttpActionResult Post(Role role) { using (var fullStackContext = new FullStackContext()) { fullStackContext.Roles.Add(role); fullStackContext.SaveChanges(); return Ok(role); } }
public IHttpActionResult Delete(int id) { using (var fullStackContext = new FullStackContext()) { try { var user = fullStackContext.Users.Single(r => r.UserId == id); fullStackContext.Users.Remove(user); fullStackContext.SaveChanges(); return Ok(); } catch (InvalidOperationException) { return NotFound(); } catch (Exception) { return Conflict(); } } }
public IHttpActionResult Delete(int userId, int roleId) { using (var fullStackContext = new FullStackContext()) { try { var userRole = fullStackContext.UserRoles.Single(ur => ur.UserId == userId && ur.RoleId == roleId); fullStackContext.UserRoles.Remove(userRole); fullStackContext.SaveChanges(); return Ok(); } catch (InvalidOperationException) { return NotFound(); } catch (Exception) { return Conflict(); } } }
public IHttpActionResult Put(int id, Role role) { using (var fullStackContext = new FullStackContext()) { try { var dbRole = fullStackContext.Roles.Single(r => r.RoleId == id); dbRole.RoleName = role.RoleName; fullStackContext.SaveChanges(); return Ok(dbRole); } catch (InvalidOperationException) { return NotFound(); } catch (Exception) { return Conflict(); } } }
public IHttpActionResult Post(int userId, int roleId) { using (var fullStackContext = new FullStackContext()) { fullStackContext.UserRoles.Add(new UserRole { UserId = userId, RoleId = roleId }); fullStackContext.SaveChanges(); var retVal = fullStackContext.UserRoles .Include(ur => ur.Role) .Single(ur => ur.UserId == userId && ur.RoleId == roleId); return Ok(new { roleId = retVal.RoleId, role = new { roleId = retVal.RoleId, roleName = retVal.Role.RoleName } }); } }
public IHttpActionResult Put(int id, User user) { using (var fullStackContext = new FullStackContext()) { try { var dbUser = fullStackContext.Users.Single(r => r.UserId == id); dbUser.UserName = user.UserName; fullStackContext.SaveChanges(); return Ok(dbUser); } catch (InvalidOperationException) { return NotFound(); } catch (Exception) { return Conflict(); } } }
public IHttpActionResult Post(User user) { using (var fullStackContext = new FullStackContext()) { fullStackContext.Users.Add(user); fullStackContext.SaveChanges(); return Ok(user); } }