public IHttpActionResult Leave([FromBody]User user, int communityId)
{
try
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var community = _communityResource.Get(communityId);
if (community == null) throw new Exception("Cannot update community at the moment.");
var tempMembers = new List<User>();
foreach (var member in community.Members)
{
if (user.Id != member.Id)
{
tempMembers.Add(member);
}
}
community.Members = tempMembers;
return Ok(_communityResource.Update(community));
}
catch (Exception ex)
{
_errorSignaler.SignalFromCurrentContext(ex);
var errorResult = new Community
{
Error = new Error
{
Id = (int)Common.Utils.Constants.Error.InternalError,
Message = ex.Message
}
};
return Ok(errorResult);
}
}
}