public async Task <ActionResult> RemoveAllSharing(int idServiceDescription, ServiceDescription_RemoveAllSharing_MvcViewModel requestModel) { #region Set authorization to API calls SetAuthorizationToAPICalls(); #endregion Set authorization to API calls //Get the share invitations according to the service description var getShareInvitationsRequest = CreateApiRequest($"api/service-descriptions/{idServiceDescription}/share-invitations", HttpMethodENUM.GET, "application/x-www-form-urlencoded"); var getShareInvitationsResponse = await _apiRestClient.ExecuteAsync <List <ShareInvitation_ApiResponseViewModel> >(getShareInvitationsRequest); //If the response of geting the share invitations is Ok if (getShareInvitationsResponse.StatusCode == System.Net.HttpStatusCode.OK) { //Get the share invitation from the API response object var shareInvitations = getShareInvitationsResponse.Data; //For each share invitation gotten from the service description foreach (var shareInvitation in shareInvitations) { //Create the share invitation request body to revoke the invitation var updateShareInvitationRequestBody = new ShareInvitation_ApiRequestUpdateModel { Email = shareInvitation.Email, Id = shareInvitation.Id, IdServiceDescription = shareInvitation.IdServiceDescription, IdUserInviter = shareInvitation.IdUserInviter, InvitationStatus = Domain.Enums.InvitationStatusEnum.Revoked, InvitationSecurity = shareInvitation.InvitationSecurity }; //Revoke the share invitation by updating the share invitation var updateShareInvitationRequest = CreateApiRequest($"api/share-invitations/{shareInvitation.Id}", HttpMethodENUM.PUT, "application/x-www-form-urlencoded"); updateShareInvitationRequest.AddRequestBodyParameter(updateShareInvitationRequestBody); var updateShareInvitationResponse = await _apiRestClient.ExecuteAsync <ShareInvitation_ApiResponseViewModel>(updateShareInvitationRequest); } //Get the relations between the service description and the user var getServiceDescriptionUsersRequest = CreateApiRequest($"api/service-descriptions/{idServiceDescription}/service-description-users", HttpMethodENUM.GET, "application/x-www-form-urlencoded"); var getServiceDescriptionUsersResponse = await _apiRestClient.ExecuteAsync <List <ServiceDescription_User_ApiResponseViewModel> >(getServiceDescriptionUsersRequest); //If the response of geting the relations between the service description and the users is Ok if (getServiceDescriptionUsersResponse.StatusCode == System.Net.HttpStatusCode.OK) { //Get the relation between the service description and the users from the API response object var serviceDescriptionUsers = getServiceDescriptionUsersResponse.Data; //For each relation foreach (var serviceDescriptionUser in serviceDescriptionUsers) { //Remove the relation between the service description and the user var deleteServiceDescriptionUserRequest = CreateApiRequest($"api/service-description-users/{serviceDescriptionUser.Id}", HttpMethodENUM.DELETE, "application/x-www-form-urlencoded"); var deleteServiceDescriptionUserResponse = await _apiRestClient.ExecuteAsync <ShareInvitation_ApiResponseViewModel>(deleteServiceDescriptionUserRequest); } } } return(RedirectToAction("Index")); }
public IHttpActionResult PutShareInvitation(int id, ShareInvitation_ApiRequestUpdateModel shareInvitationRequestUpdateModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shareInvitationRequestUpdateModel.Id) { return(BadRequest()); } var shareInvitation = _mapper.Map <ShareInvitation>(shareInvitationRequestUpdateModel); var count = _shareInvitationService.Update(shareInvitation); var shareInvitationResponseModel = _mapper.Map <ShareInvitation_ApiResponseViewModel>(shareInvitation); return(Ok(shareInvitationResponseModel)); }
public async Task <ActionResult> RemoveSharing(ServiceDescription_RemoveSharing_MvcViewModel serviceDescriptionRemoveSharingViewModel) { var idServiceDescription = serviceDescriptionRemoveSharingViewModel.IdServiceDescription; #region Set authorization to API calls SetAuthorizationToAPICalls(); #endregion Set authorization to API calls //Get the share invitations according to the service description var getShareInvitationsRequest = CreateApiRequest($"api/service-descriptions/{idServiceDescription}/share-invitations", HttpMethodENUM.GET, "application/x-www-form-urlencoded"); var getShareInvitationsResponse = await _apiRestClient.ExecuteAsync <List <ShareInvitation_ApiResponseViewModel> >(getShareInvitationsRequest); //If the response of geting the share invitations is Ok if (getShareInvitationsResponse.StatusCode == System.Net.HttpStatusCode.OK) { //Get the share invitation from the API response object var shareInvitations = getShareInvitationsResponse.Data; //From all share invitations for the given service description, get the one for the specific user by the email var shareInvitation = shareInvitations.FirstOrDefault(x => x.Email == serviceDescriptionRemoveSharingViewModel.SharedUserEmail); //If the share invitation exists for the specific service description and also for the user (by the email) if (shareInvitation != null) { //Create the share invitation request body to revoke the invitation var updateShareInvitationRequestBody = new ShareInvitation_ApiRequestUpdateModel { Email = shareInvitation.Email, Id = shareInvitation.Id, IdServiceDescription = shareInvitation.IdServiceDescription, IdUserInviter = shareInvitation.IdUserInviter, InvitationStatus = Domain.Enums.InvitationStatusEnum.Revoked, InvitationSecurity = shareInvitation.InvitationSecurity }; //Revoke the share invitation by updating the share invitation var updateShareInvitationRequest = CreateApiRequest($"api/share-invitations/{shareInvitation.Id}", HttpMethodENUM.PUT, "application/x-www-form-urlencoded"); updateShareInvitationRequest.AddRequestBodyParameter(updateShareInvitationRequestBody); var updateShareInvitationResponse = await _apiRestClient.ExecuteAsync <ShareInvitation_ApiResponseViewModel>(updateShareInvitationRequest); //Get the relations between the service description and the user var getServiceDescriptionUsersRequest = CreateApiRequest($"api/service-descriptions/{idServiceDescription}/service-description-users", HttpMethodENUM.GET, "application/x-www-form-urlencoded"); var getServiceDescriptionUsersResponse = await _apiRestClient.ExecuteAsync <List <ServiceDescription_User_ApiResponseViewModel> >(getServiceDescriptionUsersRequest); //If the response of geting the relations between the service description and the users is Ok if (getServiceDescriptionUsersResponse.StatusCode == System.Net.HttpStatusCode.OK) { //Get the relation between the service description and the users from the API response object var serviceDescriptionUsers = getServiceDescriptionUsersResponse.Data; //From all users which the service description is shared with, given service description id, get the one for the specific user by the email var serviceDescriptionUser = serviceDescriptionUsers.FirstOrDefault(x => x.Email == serviceDescriptionRemoveSharingViewModel.SharedUserEmail); //If the user exists for the specific service description and also for the user (by the email) if (serviceDescriptionUser != null) { //Remove the relation between the service description and the user var deleteServiceDescriptionUserRequest = CreateApiRequest($"api/service-description-users/{serviceDescriptionUser.Id}", HttpMethodENUM.DELETE, "application/x-www-form-urlencoded"); var deleteServiceDescriptionUserResponse = await _apiRestClient.ExecuteAsync <ShareInvitation_ApiResponseViewModel>(deleteServiceDescriptionUserRequest); } } } } return(RedirectToAction("Index", "ServiceDescription_User", new { idServiceDescription = serviceDescriptionRemoveSharingViewModel.IdServiceDescription })); }