public async Task <Response> InsertOrUpdateAsync(T item) { try { var existing = await this.tableHandler.GetItemAsync(item.PartitionKey, item.RowKey); var compareFactory = new CompareEntitiesFactory(existing, item, ChangeTypeValues.Modify); if (compareFactory.AreEqual()) { return(Response.Success()); } var response = await this.tableHandler.InsertOrUpdateAsync(item); if (response.Successful) { await this.LogChange(item, compareFactory); } return(response); } catch (Exception exp) { // this.insightsTracker.TrackException(exp, nameof(AuditTableHandler<T>), nameof(this.InsertOrUpdateAsync), this.TableName); return(Response.Failed(exp.Message)); } }
private async Task LogChange(T item, CompareEntitiesFactory compareEntitiesFactory) { var changeLogModel = new ChangeLogModel { Type = compareEntitiesFactory.GetChangeType(), TableName = this.TableName, Context = this.Context, ChangedDataType = item.GetType().Name, ChangeData = compareEntitiesFactory.GetChanges(), LogDate = DateTimeOffset.Now.Date, ItemPartitionKey = item.PartitionKey, ItemRowKey = item.RowKey, UserId = GetUserId(), UserEmail = GetUserEmail() }; if (changeLogModel.UserId == DefaultUnknownUser || string.IsNullOrWhiteSpace(changeLogModel.UserEmail)) { //this.insightsTracker.TrackEvent( // "InvalidUserClaims", // new Dictionary<string, string> // { // { nameof(ChangeLogEntity.UserId), changeLogModel.UserId }, // { nameof(ChangeLogEntity.UserEmail), changeLogModel.UserEmail }, // { nameof(ChangeLogEntity.Context), changeLogModel.Context }, // { nameof(ChangeLogEntity.TableName), changeLogModel.TableName }, // { nameof(ChangeLogEntity.Type), changeLogModel.Type } // }); } await this.changeRepository.LogChange(changeLogModel); }