public async Task <Result <SystemValueDto> > AddAsync(SystemValueDto entity) { var response = new Result <SystemValueDto>(); try { var ctx = GetOpenConnection(); var systemValues = new GenericRepositoryEF <KntDbContext, SystemValue>(ctx); var newEntity = new SystemValue(); newEntity.SetSimpleDto(entity); var resGenRep = await systemValues.AddAsync(newEntity); response.Entity = resGenRep.Entity?.GetSimpleDto <SystemValueDto>(); response.ErrorList = resGenRep.ErrorList; await CloseIsTempConnection(ctx); } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, response.ErrorList); } return(ResultDomainAction(response)); }
public async Task <Result <SystemValueDto> > UpdateAsync(SystemValueDto entity) { var result = new Result <SystemValueDto>(); try { var db = GetOpenConnection(); var sql = @"UPDATE SystemValues SET Scope = @Scope, [Key] = @Key, [Value] = @Value WHERE SystemValueId = @SystemValueId"; var r = await db.ExecuteAsync(sql.ToString(), new { entity.SystemValueId, entity.Scope, entity.Key, entity.Value }); if (r == 0) { result.ErrorList.Add("Entity not updated"); } result.Entity = entity; await CloseIsTempConnection(db); } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, result.ErrorList); } return(ResultDomainAction(result)); }
public async Task <Result <SystemValueDto> > AddAsync(SystemValueDto entity) { var result = new Result <SystemValueDto>(); try { var db = GetOpenConnection(); var sql = @"INSERT INTO SystemValues (SystemValueId, Scope, [Key], [Value]) VALUES (@SystemValueId, @Scope, @Key, @Value)"; var r = await db.ExecuteAsync(sql.ToString(), new { entity.SystemValueId, entity.Scope, entity.Key, entity.Value }); if (r == 0) { result.ErrorList.Add("Entity not inserted"); } result.Entity = entity; await CloseIsTempConnection(db); } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, result.ErrorList); } return(ResultDomainAction(result)); }
public async Task <Result <SystemValueDto> > SaveAsync(SystemValueDto entity) { if (entity.SystemValueId == Guid.Empty) { entity.SystemValueId = Guid.NewGuid(); return(await _repository.SystemValues.AddAsync(entity)); } else { return(await _repository.SystemValues.UpdateAsync(entity)); } }
public async Task <Result <SystemValueDto> > UpdateAsync(SystemValueDto entity) { var resGenRep = new Result <SystemValue>(); var response = new Result <SystemValueDto>(); try { var ctx = GetOpenConnection(); var systemValues = new GenericRepositoryEF <KntDbContext, SystemValue>(ctx); var resGenRepGet = await systemValues.GetAsync(entity.SystemValueId); SystemValue entityForUpdate; if (resGenRepGet.IsValid) { entityForUpdate = resGenRepGet.Entity; entityForUpdate.SetSimpleDto(entity); resGenRep = await systemValues.UpdateAsync(entityForUpdate); } else { resGenRep.Entity = null; resGenRep.AddErrorMessage("Can't find entity for update."); } response.Entity = resGenRep.Entity?.GetSimpleDto <SystemValueDto>(); response.ErrorList = resGenRep.ErrorList; await CloseIsTempConnection(ctx); } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, response.ErrorList); } return(ResultDomainAction(response)); }