public async Task <Result <List <NoteTypeDto> > > GetAllAsync() { var response = new Result <List <NoteTypeDto> >(); try { var ctx = GetOpenConnection(); var noteTypes = new GenericRepositoryEF <KntDbContext, NoteType>(ctx); var resGenRep = await noteTypes.GetAllAsync(); response.Entity = resGenRep.Entity? .Select(t => t.GetSimpleDto <NoteTypeDto>()) .OrderBy(t => t.Name) .ToList(); response.ErrorList = resGenRep.ErrorList; await CloseIsTempConnection(ctx); } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, response.ErrorList); } return(ResultDomainAction(response)); }
public async Task <Result <List <KAttributeInfoDto> > > GetAllIncludeNullTypeAsync(Guid?typeId) { var resService = new Result <List <KAttributeInfoDto> >(); try { // TODO: pendiente de poblar la propiedad NoteTypeDto. Coger implementación de GetAllAsync(). var ctx = GetOpenConnection(); var kattributes = new GenericRepositoryEF <KntDbContext, KAttribute>(ctx); var resRep = await kattributes.GetAllAsync(_ => _.NoteTypeId == null || _.NoteTypeId == typeId); resService.Entity = resRep.Entity? .Select(a => a.GetSimpleDto <KAttributeInfoDto>()) .OrderBy(a => a.Order).ThenBy(a => a.Name) .ToList(); resService.ErrorList = resRep.ErrorList; await CloseIsTempConnection(ctx); } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, resService.ErrorList); } return(ResultDomainAction(resService)); }
public async Task <Result <List <KAttributeTabulatedValueDto> > > GetKAttributeTabulatedValuesAsync(Guid attributeId) { var result = new Result <List <KAttributeTabulatedValueDto> >(); try { var ctx = GetOpenConnection(); var kattributeTabulatedValues = new GenericRepositoryEF <KntDbContext, KAttributeTabulatedValue>(ctx); var resRep = await kattributeTabulatedValues.GetAllAsync(tv => tv.KAttributeId == attributeId); if (resRep.IsValid) { result.Entity = resRep.Entity.Select(_ => _.GetSimpleDto <KAttributeTabulatedValueDto>()).OrderBy(_ => _.Order).ToList(); } else { result.ErrorList = resRep.ErrorList; } await CloseIsTempConnection(ctx); } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, result.ErrorList); } return(ResultDomainAction(result)); }
public async Task <Result <List <SystemValueDto> > > GetAllAsync() { var resService = new Result <List <SystemValueDto> >(); try { var ctx = GetOpenConnection(); var systemValues = new GenericRepositoryEF <KntDbContext, SystemValue>(ctx); var resRep = await systemValues.GetAllAsync(); resService.Entity = resRep.Entity?.Select(sv => sv.GetSimpleDto <SystemValueDto>()).ToList(); resService.ErrorList = resRep.ErrorList; await CloseIsTempConnection(ctx); } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, resService.ErrorList); } return(ResultDomainAction(resService)); }
private async Task DeleteNoContainsTabulateValueAsync(KntDbContext ctx, Guid attributeId, List <Guid> guids) { var kattributeTabulatedValues = new GenericRepositoryEF <KntDbContext, KAttributeTabulatedValue>(ctx); var tabValuesForDelete = (await kattributeTabulatedValues.GetAllAsync(v => (v.KAttributeId == attributeId && !guids.Contains(v.KAttributeTabulatedValueId)))).Entity; var res = kattributeTabulatedValues.DeleteRange(tabValuesForDelete); }
public async Task <Result <KAttributeDto> > UpdateAsync(KAttributeDto entity) { var resGenRep = new Result <KAttribute>(); var response = new Result <KAttributeDto>(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var ctx = GetOpenConnection(); var kattributes = new GenericRepositoryEF <KntDbContext, KAttribute>(ctx); var resGenRepGet = await kattributes.GetAsync(entity.KAttributeId); KAttribute entityForUpdate; if (resGenRepGet.IsValid) { // Check notetype in notes. if (entity.NoteTypeId != null && resGenRepGet.Entity.NoteTypeId != entity.NoteTypeId) { var noteKAttributes = new GenericRepositoryEF <KntDbContext, NoteKAttribute>(ctx); var nAttributes = (await noteKAttributes.GetAllAsync(n => n.KAttributeId == entity.KAttributeId)).Entity; if (nAttributes.Count > 0) { response.AddErrorMessage("You can not change the note type for this attribute. This attribute is already being used by several notes. "); response.Entity = entity; } } if (response.IsValid) { entityForUpdate = resGenRepGet.Entity; entityForUpdate.SetSimpleDto(entity); resGenRep = await kattributes.UpdateAsync(entityForUpdate); response.Entity = resGenRep.Entity?.GetSimpleDto <KAttributeDto>(); var guidsUpdated = new List <Guid>(); foreach (var value in entity.KAttributeValues) { var res = await SaveTabulateValueAsync(ctx, response.Entity.KAttributeId, value); if (!res.IsValid) { response.ErrorList.Add(res.Message); } response.Entity.KAttributeValues.Add(res.Entity); guidsUpdated.Add(value.KAttributeTabulatedValueId); } await DeleteNoContainsTabulateValueAsync(ctx, response.Entity.KAttributeId, guidsUpdated); response.ErrorList = resGenRep.ErrorList; } } else { response.Entity = entity; response.AddErrorMessage("Can't find entity for update."); } scope.Complete(); await CloseIsTempConnection(ctx); } } catch (Exception ex) { AddExecptionsMessagesToErrorsList(ex, response.ErrorList); } return(ResultDomainAction(response)); }