/// <summary> /// Stores or update post data in user's private list. /// </summary> /// <param name="entity">Represents user private post entity object.</param> /// <returns>A task that represents user private post is saved or updated.</returns> private async Task <TableResult> StoreOrUpdatePrivatePostAsync(UserPrivatePostEntity entity) { await this.EnsureInitializedAsync(); TableOperation addOrUpdateOperation = TableOperation.InsertOrReplace(entity); return(await this.GoodReadsCloudTable.ExecuteAsync(addOrUpdateOperation)); }
public async Task <IActionResult> PostAsync([FromBody] UserPrivatePostEntity userPrivatePostEntity) { this.logger.LogInformation("Call to add private post."); try { var postIds = await this.userPrivatePostStorageProvider.GetUserPrivatePostsIdAsync(this.UserAadId); if (postIds.Count() < UserPrivatePostMaxCount) { UserPrivatePostEntity userPrivatePost = new UserPrivatePostEntity { UserId = this.UserAadId, CreatedByName = this.UserName, #pragma warning disable CA1062 // private post details are validated by model validations for null check and is responded with bad request status PostId = userPrivatePostEntity.PostId, #pragma warning restore CA1062 // private post details are validated by model validations for null check and is responded with bad request status CreatedDate = DateTime.UtcNow, }; var result = await this.userPrivatePostStorageProvider.UpsertUserPrivatPostAsync(userPrivatePost); if (result) { this.RecordEvent("Private posts - HTTP Post call succeeded"); } return(this.Ok(result)); } else { return(this.Ok(false)); } } catch (Exception ex) { this.logger.LogError(ex, "Error while saving private post."); throw; } }
/// <summary> /// Stores or update post data in user's private list. /// </summary> /// <param name="entity">Holds user post detail.</param> /// <returns>A boolean that represents user private post is successfully saved/updated or not.</returns> public async Task <bool> UpsertUserPrivatPostAsync(UserPrivatePostEntity entity) { var result = await this.StoreOrUpdatePrivatePostAsync(entity); return(result.HttpStatusCode == (int)HttpStatusCode.NoContent); }