public VmServiceOutput GetService(VmServiceBasic model) { VmServiceOutput result = null; ContextManager.ExecuteReader(unitOfWork => { result = GetService(model, unitOfWork); }); return(result); }
private VmServiceOutput GetService(VmServiceBasic model, IUnitOfWork unitOfWork) { VmServiceOutput result = null; SetTranslatorLanguage(model); ServiceVersioned entity = null; result = GetModel <ServiceVersioned, VmServiceOutput>(entity = GetEntity <ServiceVersioned>(model.Id, unitOfWork, q => q.Include(x => x.ServiceNames) .Include(x => x.ServiceDescriptions) .Include(x => x.OrganizationServices) .Include(x => x.ServiceRequirements) .Include(x => x.AreaMunicipalities) .Include(x => x.Areas).ThenInclude(x => x.Area) .Include(x => x.LanguageAvailabilities) .Include(x => x.Versioning) .Include(x => x.ServiceLanguages) .Include(x => x.ServiceKeywords).ThenInclude(x => x.Keyword) .Include(x => x.ServiceServiceClasses) //.ThenInclude(x => x.ServiceClass).ThenInclude(x => x.Names) .Include(x => x.ServiceOntologyTerms).ThenInclude(x => x.OntologyTerm).ThenInclude(x => x.Names) // to cache .Include(x => x.ServiceLifeEvents).ThenInclude(x => x.LifeEvent).ThenInclude(x => x.Names) // to cache .Include(x => x.ServiceIndustrialClasses) //.ThenInclude(x => x.IndustrialClass).ThenInclude(x => x.Names) .Include(x => x.ServiceTargetGroups) .Include(x => x.ServiceWebPages).ThenInclude(x => x.WebPage) .Include(x => x.ServiceProducers).ThenInclude(x => x.Organizations) .Include(x => x.ServiceProducers).ThenInclude(x => x.AdditionalInformations) .Include(x => x.ServiceLaws).ThenInclude(j => j.Law).ThenInclude(k => k.Names) .Include(x => x.ServiceLaws).ThenInclude(j => j.Law).ThenInclude(k => k.WebPages) .Include(x => x.ServiceLaws).ThenInclude(j => j.Law).ThenInclude(k => k.WebPages).ThenInclude(l => l.WebPage) .Include(x => x.UnificRoot).ThenInclude(j => j.ServiceServiceChannels).ThenInclude(j => j.ServiceServiceChannelDescriptions) .Include(x => x.UnificRoot).ThenInclude(j => j.ServiceServiceChannels).ThenInclude(j => j.ServiceServiceChannelDigitalAuthorizations).ThenInclude(j => j.DigitalAuthorization) .Include(x => x.UnificRoot).ThenInclude(j => j.ServiceServiceChannels).ThenInclude(j => j.ServiceServiceChannelExtraTypes).ThenInclude(j => j.ServiceServiceChannelExtraTypeDescriptions) ), unitOfWork); AddConnectionsInfo(result, entity.UnificRoot.ServiceServiceChannels, unitOfWork); result.PreviousInfo = result.Id.HasValue ? Utilities.CheckIsEntityEditable <ServiceVersioned, Service>(result.Id.Value, unitOfWork) : null; if (result.GeneralDescriptionId != null) { result.GeneralDescriptionOutput = generalDescriptionService.GetGeneralDescription( new VmGeneralDescriptionGet() { Id = result.GeneralDescriptionId, Language = model.Language, OnlyPublished = true }, unitOfWork); result.GeneralDescriptionOutput.Id = result.GeneralDescriptionOutput.UnificRootId; } return(result); }
private void AddConnectionsInfo(VmServiceOutput result, ICollection <ServiceServiceChannel> connections, IUnitOfWork unitOfWork) { var serviceUnificId = result.UnificRootId; var psPublished = typesCache.Get <PublishingStatusType>(PublishingStatus.Published.ToString()); var psDraft = typesCache.Get <PublishingStatusType>(PublishingStatus.Draft.ToString()); var psModified = typesCache.Get <PublishingStatusType>(PublishingStatus.Modified.ToString()); var connectedChannelsUnificIds = result.ConnectedChannels.Select(i => i.ChannelId).ToList(); var channelRep = unitOfWork.CreateRepository <IServiceChannelVersionedRepository>(); var connectedChannels = channelRep.All().Where(i => (connectedChannelsUnificIds.Contains(i.UnificRootId)) && (i.PublishingStatusId == psPublished || i.PublishingStatusId == psDraft || i.PublishingStatusId == psModified)) .Include(i => i.ServiceChannelNames).Include(i => i.LanguageAvailabilities) .ToList() // could be done on db when it will be implemented in EF .GroupBy(i => i.UnificRootId) .Select(i => i.FirstOrDefault(x => x.PublishingStatusId == psPublished) ?? i.FirstOrDefault()) .Select(i => { var modifiedData = result.ConnectedChannels.FirstOrDefault(m => m.ChannelId == i.UnificRootId); var originalConnection = connections.FirstOrDefault(x => x.ServiceId == serviceUnificId && x.ServiceChannelId == i.UnificRootId); return(new ServiceServiceChannel() { ServiceChannelId = i.UnificRootId, ServiceId = serviceUnificId, ServiceServiceChannelDescriptions = originalConnection?.ServiceServiceChannelDescriptions ?? new List <ServiceServiceChannelDescription>(), ServiceServiceChannelDigitalAuthorizations = originalConnection?.ServiceServiceChannelDigitalAuthorizations ?? new List <ServiceServiceChannelDigitalAuthorization>(), IsASTIConnection = originalConnection?.IsASTIConnection ?? false, ServiceServiceChannelExtraTypes = originalConnection?.ServiceServiceChannelExtraTypes ?? new List <ServiceServiceChannelExtraType>(), ChargeTypeId = originalConnection?.ChargeTypeId, ServiceChannel = new ServiceChannel() { Id = i.UnificRootId, Versions = new List <ServiceChannelVersioned>() { i } }, Modified = modifiedData?.Modified ?? DateTime.MinValue, ModifiedBy = modifiedData?.ModifiedBy ?? string.Empty }); }).ToList(); result.Connections = TranslationManagerToVm.TranslateAll <ServiceServiceChannel, VmConnectionOutput>(connectedChannels).InclusiveToList(); result.NumberOfConnections = result.Connections.Count; }
private IVmBase GetServiceData(Domain.Model.Models.V2.Service.VmServiceInput model) { VmServiceOutput result = null; switch (model.Action) { case ActionTypeEnum.Save: result = serviceService.SaveService(model); break; case ActionTypeEnum.SaveAndValidate: result = serviceService.SaveAndValidateService(model); break; default: result = serviceService.SaveService(model); break; } serviceService.UnLockService(result.Id.Value); return(result); }