public async Task UpdateAsync(RegulatoryNorm regulatoryNorm) { var sql = @" UPDATE [dbo].[RegulatoryNorms] SET Description = @description, UpdateDate = @updateDate, CategoryId = @categoryId, ReleaseDate = @releaseDate WHERE Code = @code"; var param = new { code = regulatoryNorm.Code, description = regulatoryNorm.Description, updateDate = DateTime.UtcNow, categoryId = Convert.ToInt32(regulatoryNorm.Category), releaseDate = regulatoryNorm.ReleaseDate }; try { await this.UnitOfWork.DbConnector.Connection.ExecuteAsync(sql, param); } catch (Exception ex) { throw; } }
public async Task InsertAsync(RegulatoryNorm regulatoryNorm) { var sql = @" INSERT INTO [dbo].[RegulatoryNorms] (Code, Description, Active, CategoryId, ReleaseDate) VALUES (@code, @description, @active, @categoryId, @releaseDate)"; var param = new { code = regulatoryNorm.Code, description = regulatoryNorm.Description, active = true, categoryId = Convert.ToInt32(regulatoryNorm.Category), releaseDate = regulatoryNorm.ReleaseDate }; await this.UnitOfWork.DbConnector.Connection.ExecuteAsync(sql, param); }
public async Task <List <DataContracts.RegulatoryNormUpdate> > CheckRegulatoryNormsUpdateAsync() { List <DataContracts.RegulatoryNormUpdate> updatedRegulatoryNormsList; //TODO: implement dispose on externalRegulatoryNormsService // read external norms base var regulatoryNorms = await _externalRegulatoryNormsService.GetRegulatoryNormsAsync(DataContracts.RegulatoryNormCategory.WorkSafety); using (_regulatoryNormsRepository) { foreach (var regulatoryNorm in regulatoryNorms) { updatedRegulatoryNormsList = new List <DataContracts.RegulatoryNormUpdate>(); // get the regulatory norm from database var storedRegulatoryNorm = await _regulatoryNormsRepository.GetByCodeAsync(regulatoryNorm.Code); if (storedRegulatoryNorm != null) { // updates regulatory norms in database if (storedRegulatoryNorm.Description != regulatoryNorm.Description) { storedRegulatoryNorm.Description = regulatoryNorm.Description; storedRegulatoryNorm.ReleaseDate = Convert.ToDateTime(regulatoryNorm.ReleaseDate); storedRegulatoryNorm.Category = (Domain.Enums.RegulatoryNormCategory)Enum.Parse(typeof(Domain.Enums.RegulatoryNormCategory), regulatoryNorm.Category); await _regulatoryNormsRepository.UpdateAsync(storedRegulatoryNorm); regulatoryNorm.Updated = true; updatedRegulatoryNormsList.Add(regulatoryNorm); } } else { // inserts new regulatory norms in database // TODO: call mapper method here var newRegulatoryNorm = new RegulatoryNorm() { Code = regulatoryNorm.Code, Description = regulatoryNorm.Description, ReleaseDate = Convert.ToDateTime(regulatoryNorm.ReleaseDate), Category = (Domain.Enums.RegulatoryNormCategory)Enum.Parse(typeof(Domain.Enums.RegulatoryNormCategory), regulatoryNorm.Category) }; await _regulatoryNormsRepository.InsertAsync(newRegulatoryNorm); updatedRegulatoryNormsList.Add(regulatoryNorm); } if (updatedRegulatoryNormsList.Any()) { //Publishes norms' updates to queue this._queuePublisher.SendMessage(updatedRegulatoryNormsList); } } } // TODO: check logic of database initial population // TODO: implement a comparer to check norms diff return(regulatoryNorms); }