Exemple #1
0
        public async Task <IActionResult> DeleteFavoriteDistributionListDataAsync([FromBody] FavoriteDistributionListData favoriteDistributionListData)
        {
            try
            {
                favoriteDistributionListData.UserObjectId = this.UserObjectId;

                FavoriteDistributionListTableEntity favoriteDistributionListEntity = await this.favoriteDistributionListDataRepository
                                                                                     .GetFavoriteDistributionListFromStorageAsync(
                    favoriteDistributionListData.Id,
                    this.UserObjectId);

                if (favoriteDistributionListEntity != null)
                {
                    await this.favoriteDistributionListDataRepository.RemoveFavoriteDistributionListFromStorageAsync(favoriteDistributionListEntity);

                    return(this.Ok());
                }

                return(this.NotFound("Favorite distribution list to be deleted is not found."));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, $"An error occurred in DeleteFavoriteDistributionListDataAsync: {ex.Message}.");
                throw;
            }
        }
Exemple #2
0
        public async Task DeleteFavoriteDistributionListDataAsync([FromBody] FavoriteDistributionListData favoriteDistributionListData)
        {
            try
            {
                string userPrincipleName = this.HttpContext.User.FindFirst(ClaimTypes.Upn)?.Value.ToLower();

                if (string.IsNullOrEmpty(userPrincipleName))
                {
                    this.telemetryClient.TrackTrace($"There's no user principal name claim.", SeverityLevel.Error);
                    this.HttpContext.Response.ContentType = "text/plain";
                    this.HttpContext.Response.StatusCode  = (int)HttpStatusCode.Unauthorized;
                    await this.HttpContext.Response.WriteAsync("There's no user principal name claim.");
                }

                favoriteDistributionListData.UserPrincipalName = userPrincipleName;

                FavoriteDistributionListTableEntity favoriteDistributionListDataEntity = await this.favoriteDistributionListDataRepository.GetAsync(
                    userPrincipleName,
                    favoriteDistributionListData.Id);

                if (favoriteDistributionListDataEntity != null)
                {
                    await this.favoriteDistributionListDataRepository.DeleteAsync(favoriteDistributionListDataEntity);

                    this.telemetryClient.TrackEvent($"Deleted favorite DL : {JsonConvert.SerializeObject(favoriteDistributionListData)}");
                }
                else
                {
                    this.telemetryClient.TrackEvent($"Did not find favorite user to delete : {JsonConvert.SerializeObject(favoriteDistributionListData)}");
                }

                this.HttpContext.Response.ContentType = "text/plain";
                this.HttpContext.Response.StatusCode  = (int)HttpStatusCode.OK;
                await this.HttpContext.Response.WriteAsync("Deleted Favorite distribution list successfully.");
            }
            catch (MsalException ex)
            {
                this.telemetryClient.TrackTrace($"An error occurred in DeleteFavoriteDistributionListDataAsync: {ex.Message}. Parameters:{JsonConvert.SerializeObject(favoriteDistributionListData)}", SeverityLevel.Error);
                this.telemetryClient.TrackException(ex);
                this.HttpContext.Response.ContentType = "text/plain";
                this.HttpContext.Response.StatusCode  = (int)HttpStatusCode.Unauthorized;
                await this.HttpContext.Response.WriteAsync("An authentication error occurred while acquiring a token for downstream API\n" + ex.ErrorCode + "\n" + ex.Message);
            }
            catch (Exception ex)
            {
                this.telemetryClient.TrackTrace($"An error occurred in DeleteFavoriteDistributionListDataAsync: {ex.Message}. Parameters:{JsonConvert.SerializeObject(favoriteDistributionListData)}", SeverityLevel.Error);
                this.telemetryClient.TrackException(ex);
                this.HttpContext.Response.ContentType = "text/plain";
                this.HttpContext.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                await this.HttpContext.Response.WriteAsync("An error occurred while calling the downstream API\n" + ex.Message);
            }
        }