public void SetConnectionRequestStatus([FromBody] ConnectionRequestUpdateStatusModel model) { var request = Program.ConnectionRequestsManager.Get(model.Id); if (request == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "Invalid Id" }); } if (request.ConnectToUserName.ToLower() != UserName.ToLower()) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized) { ReasonPhrase = "You are not authorised to update the specified request" }); } Program.ConnectionRequestsManager.SetStatus(model.Id, model.Status); #if DEBUG Console.WriteLine(string.Format("SetConnectionRequestStatus : ConnectionRequest status update to '{0}' by User '{1}', connecting to user '{2}.", model.Status, UserName, request.ConnectToUserName)); #endif if (model.Status == ConnectionRequestStatusEnum.Approved) { Program.ConnectionsManager.Add(request.RequestedByUserName, UserName); } UserCommandsLock.Wake(request.RequestedByUserName); UserCommandsLock.Wake(UserName); }
public async Task SetContactRequestStatus(ConnectionRequestUpdateStatusModel model) { try { if (string.IsNullOrEmpty(_accessToken)) { throw new Exception("Not logged in"); } using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var url = string.Format("{0}/api/connection/request/setstatus", _configuration.ServerBaseUrl); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken); var response = await client.PostAsJsonAsync <ConnectionRequestUpdateStatusModel>(url, model); if (!response.IsSuccessStatusCode) { throw new WebAPIException("An error occurred approving contact request", response.ReasonPhrase, response.StatusCode); } } } catch (Exception ex) { if (ex is WebAPIException) { throw; } throw new Exception("An error occurred approving contact request. " + ex.Message); } }