Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates/Updates favorite distribution list data in table storage.
        /// </summary>
        /// <param name="favoriteDistributionListData">Instance of favoriteDistributionListData.</param>
        /// <returns>Returns data model.</returns>
        public async Task CreateOrUpdateFavoriteDistributionListDataAsync(
            FavoriteDistributionListData favoriteDistributionListData)
        {
            FavoriteDistributionListTableEntity favoriteDistributionListDataEntity = new FavoriteDistributionListTableEntity()
            {
                UserPrincipalName = favoriteDistributionListData.UserPrincipalName.ToLower(),
                GroupId           = favoriteDistributionListData.Id,
                PinStatus         = favoriteDistributionListData.IsPinned,
            };

            await this.CreateOrUpdateAsync(favoriteDistributionListDataEntity);
        }
        /// <summary>
        /// Creates/Updates favorite distribution list data in table storage.
        /// </summary>
        /// <param name="favoriteDistributionListData">Instance of favoriteDistributionListData.</param>
        /// <returns>Returns data model.</returns>
        public async Task CreateOrUpdateFavoriteDistributionListAsync(
            FavoriteDistributionListData favoriteDistributionListData)
        {
            FavoriteDistributionListTableEntity favoriteDistributionListDataEntity = new FavoriteDistributionListTableEntity()
            {
                GroupId      = favoriteDistributionListData.Id,
                PinStatus    = favoriteDistributionListData.IsPinned,
                UserObjectId = favoriteDistributionListData.UserObjectId,
            };

            await this.AddFavoriteDistributionListToStorageAsync(favoriteDistributionListDataEntity);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> UpdateFavoriteDistributionListDataAsync([FromBody] FavoriteDistributionListData favoriteDistributionListData)
        {
            try
            {
                favoriteDistributionListData.UserObjectId = this.UserObjectId;
                await this.favoriteDistributionListDataRepository.CreateOrUpdateFavoriteDistributionListAsync(favoriteDistributionListData);

                return(this.Ok());
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, $"An error occurred in UpdateFavoriteDistributionListDataAsync: {ex.Message}.");
                throw;
            }
        }
Ejemplo n.º 6
0
        public async Task UpdateFavoriteDistributionListData([FromBody] FavoriteDistributionListData favoriteDistributionListData)
        {
            try
            {
                string userPrincipalName = this.HttpContext.User.FindFirst(ClaimTypes.Upn)?.Value.ToLower();

                if (string.IsNullOrEmpty(userPrincipalName))
                {
                    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 = userPrincipalName;

                await this.favoriteDistributionListDataRepository.CreateOrUpdateFavoriteDistributionListDataAsync(favoriteDistributionListData);

                this.telemetryClient.TrackEvent($"Updated pin status for DL : {JsonConvert.SerializeObject(favoriteDistributionListData)}");

                this.HttpContext.Response.ContentType = "text/plain";
                this.HttpContext.Response.StatusCode  = (int)HttpStatusCode.OK;
                await this.HttpContext.Response.WriteAsync("Distribution List pin status updated.");
            }
            catch (MsalException ex)
            {
                this.telemetryClient.TrackTrace($"A msal error occurred in UpdateFavoriteDistributionListData: {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 UpdateFavoriteDistributionListData: {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);
            }
        }