/// <summary> /// Store or update nominated details in Azure table storage. /// </summary> /// <param name="nominateEntity">Represents nominate entity used for storage and retrieval.</param> /// <returns><see cref="Task"/>Returns nominate entity.</returns> public async Task <NominationEntity> StoreOrUpdateAwardNominationAsync(NominationEntity nominateEntity) { await this.EnsureInitializedAsync(); nominateEntity = nominateEntity ?? throw new ArgumentNullException(nameof(nominateEntity)); nominateEntity.NominationId = Guid.NewGuid().ToString(); TableOperation addOrUpdateOperation = TableOperation.InsertOrReplace(nominateEntity); var result = await this.CloudTable.ExecuteAsync(addOrUpdateOperation); return(result.Result as NominationEntity); }
public async Task <IActionResult> SaveAwardNominationAsync([FromBody] NominationEntity nominateDetails) { try { if (nominateDetails == null) { return(this.BadRequest(new { message = "Nomination details can not be null." })); } var userClaim = this.GetUserClaims(); // Validate nominee and nominator belongs to same team. IEnumerable <TeamsChannelAccount> teamsChannelAccounts = new List <TeamsChannelAccount>(); teamsChannelAccounts = await this.teamsInfoHelper.GetTeamMembersAsync(nominateDetails.TeamId); var nominees = nominateDetails.NomineeObjectIds.Split(",").ToList(); if (!(nominees.TrueForAll(nomineeAadObjectId => teamsChannelAccounts.Select(row => row.AadObjectId).Contains(nomineeAadObjectId.Trim())) && teamsChannelAccounts.Select(row => row.AadObjectId).Contains(nominateDetails.NominatedByObjectId) && userClaim.FromId == nominateDetails.NominatedByObjectId)) { return(this.BadRequest(new { message = "Invalid nomination details, nominee and nominator must be from a same team." })); } // Check for duplicate award nomination. var isAlreadyNominated = await this.storageProvider.CheckDuplicateNominationAsync(nominateDetails.TeamId, nominateDetails.NomineeObjectIds, nominateDetails.RewardCycleId, nominateDetails.AwardId, nominateDetails.NominatedByObjectId); if (isAlreadyNominated) { return(this.BadRequest(new { message = "You have already nominated selected team member(s) for this award. Feel free to nominate others!" })); } this.logger.LogInformation("Initiated call to on storage provider service."); var result = await this.storageProvider.StoreOrUpdateAwardNominationAsync(nominateDetails); this.logger.LogInformation("POST call for nominated award details in storage is successful."); return(this.Ok(result)); } catch (Exception ex) { this.logger.LogError(ex, "Error while saving nominated award details."); throw; } }