Blog.Web.Api.Controllers.CommunityController.Put C# (CSharp) Method

Put() private method

private Put ( [ community ) : IHttpActionResult
community [
return IHttpActionResult
        public IHttpActionResult Put([FromBody]Community community)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var tCommunity = _communityResource.Get(community.Id);
                var isAllowed = User.Identity.GetUserName() == tCommunity.Leader.UserName;

                if (isAllowed) return Ok(_communityResource.Update(community));

                var notAllowedResult = new Community
                {
                    Error = new Error
                    {
                        Id = (int)Common.Utils.Constants.Error.RequestNotAllowed,
                        Message = "Request not allowed. You cannot edit someone else's community."
                    }
                };
                return Ok(notAllowedResult);
            }
            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);
            }
        }