public IActionResult AddUserToChannel([FromBody] User user, string ChannelId) { //first search for the channel in which user needs to be added var searchedChannel = iservice.GetChannelById(ChannelId).Result; // check if user is already inside channel var userAlreadyAddedInChannel = searchedChannel.Users.Find(u => u.UserId == user.UserId); if (userAlreadyAddedInChannel != null) { //return error message if user already inside channel return(NotFound("User already added in Channel")); } // search for the workspace in the channel exists var searchedWorkspace = iservice.GetWorkspaceById(searchedChannel.WorkspaceId).Result; // search if user is inside workspace or not var searchedUser = searchedWorkspace.Users.Find(u => u.UserId == user.UserId); if (searchedUser == null) { // return error if user is not onboarding workspace return(NotFound("User is not added in Workspace. First complete onboarding process")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // call service to add user to channel iservice.AddUserToChannel(user, ChannelId); return(new ObjectResult(user)); }
public IActionResult AddUserToChannel([FromBody] User user, string ChannelId) // frombody workspace object or string name { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } iservice.AddUserToChannel(user, ChannelId); return(new ObjectResult(user)); }