public HttpResponseMessage AddTag([FromUri] int id, [FromBody] TagCreateApiModel tag) { var response = new HttpResponseMessage(); ResponseFormat responseData = new ResponseFormat(); //AuthorizationService _authorizationService = new AuthorizationService().SetPerm((int)EnumPermissions.LEAD_MODIFY); //read jwt IEnumerable <string> headerValues; if (Request.Headers.TryGetValues("Authorization", out headerValues)) { string jwt = headerValues.FirstOrDefault(); //validate jwt var payload = JwtTokenManager.ValidateJwtToken(jwt); if (payload.ContainsKey("error")) { if ((string)payload["error"] == ErrorMessages.TOKEN_EXPIRED) { response.StatusCode = HttpStatusCode.Unauthorized; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.TOKEN_EXPIRED; } if ((string)payload["error"] == ErrorMessages.TOKEN_INVALID) { response.StatusCode = HttpStatusCode.Unauthorized; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.TOKEN_INVALID; } } else { var userId = Convert.ToInt32(payload["id"]); var owner = _taskTemplateService.GetMeetingOwner(id); if ((userId == owner) || (new AuthorizationService().SetPerm((int)EnumPermissions.TASK_DELETE_ANY).Authorize(userId))) { //check if a tag exist //if it is, create a tag item with current lead // else create a new tag and a new tag item var isAdded = _taskTemplateService.AddTagToMeeting(id, tag.name); if (isAdded) { response.StatusCode = HttpStatusCode.OK; responseData = ResponseFormat.Success; responseData.message = SuccessMessages.TAG_ADDED; } else { response.StatusCode = HttpStatusCode.InternalServerError; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.SOMETHING_WRONG; } } else { response.StatusCode = HttpStatusCode.Forbidden; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.UNAUTHORIZED; } } } else { response.StatusCode = HttpStatusCode.Unauthorized; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.UNAUTHORIZED; } var json = JsonConvert.SerializeObject(responseData); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); return(response); }