Esempio n. 1
0
        public Boolean isValidTemplate(long idTemplate, long idVersion)
        {
            Boolean result = false;

            if (idTemplate > 0 || idVersion > 0)
            {
                try{
                    Manager.BeginTransaction();
                    ServiceExport.DTO_sTemplate        dTemplate = null;
                    ServiceExport.DTO_sTemplateVersion version   = null;

                    if (idVersion > 0)
                    {
                        version = (from v in Manager.GetIQ <TemplateVersion>()
                                   where v.Id == idVersion
                                   select new ServiceExport.DTO_sTemplateVersion()
                        {
                            Id = v.Id, Deleted = v.Deleted, IsActive = v.IsActive, IsSelected = v.IsDraft, IdTemplate = v.Template.Id
                        }).Skip(0).Take(1).ToList().FirstOrDefault();
                    }
                    if (version != null && version.IdTemplate != idTemplate)
                    {
                        idTemplate = version.IdTemplate;
                    }

                    if (idTemplate > 0)
                    {
                        dTemplate = (from t in Manager.GetIQ <Template>()
                                     where t.Id == idTemplate
                                     select new ServiceExport.DTO_sTemplate()
                        {
                            Id = t.Id, HasDefinitive = t.HasActive, HasActive = t.HasActive, Deleted = t.Deleted
                        }).Skip(0).Take(1).ToList().FirstOrDefault();
                    }
                    if (dTemplate != null)
                    {
                        result = (dTemplate.Deleted == BaseStatusDeleted.None && dTemplate.HasActive && dTemplate.HasDefinitive) && (version == null || (version != null && version.IsActive && version.IsDraft == false && version.Deleted == BaseStatusDeleted.None));
                    }

                    Manager.Commit();
                }
                catch (Exception ex) {
                    Manager.RollBack();
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Recupera la lista di tutti i template e relative versioni disponibili
        /// </summary>
        /// <returns>I template che hanno ALMENO una versione valida e tutte le relative varisoni valide: IsActive == TRUE && IsDRAFT == FALSE</returns>
        //public IList<ServiceExport.DTO_Template> TemplateGetAllAvailable()
        //{
        //    //Recupero da DTO_List
        //    IList<ServiceExport.DTO_Template> avTemplates = new List<ServiceExport.DTO_Template>();

        //    IList<DocTemplateVers.Domain.DTO.Management.DTO_ListTemplate> curTemplates = Manager.GetAll<Domain.DTO.Management.DTO_ListTemplate>().Where(tmp => tmp.IsActive == true && tmp.HasDefinitive == true).ToList();

        //    if (curTemplates != null && curTemplates.Count() > 0)
        //    {
        //        foreach (Domain.DTO.Management.DTO_ListTemplate template in curTemplates)
        //        {
        //            if (template.TemplateVersions != null && template.TemplateVersions.Count() > 0)
        //            {
        //                foreach (Domain.DTO.Management.DTO_ListTemplateVersion Version in template.TemplateVersions)
        //                {
        //                    ServiceExport.DTO_Template avTempl = new ServiceExport.DTO_Template();
        //                    avTempl.IsSystem = template.IsSystem;
        //                    avTempl.Name = template.Name;
        //                    avTempl.TemplateId = template.Id;
        //                    avTempl.UseSkinHeaderFooter = (template.Type == TemplateType.Skin);
        //                    avTempl.Version = Version.Version;
        //                    avTempl.VersionId = Version.Id;
        //                    avTemplates.Add(avTempl);
        //                }
        //            }
        //        }
        //    }

        //    // ORDINAMENTI vari...

        //    return avTemplates;
        //}
        /// <summary>
        /// Recupera la lista dei template e relative versioni disponibili associate ad un determinato servizio
        /// </summary>
        /// <param name="ServiceCode">Codice del servizio di riferimento</param>
        /// <returns>I template che hanno ALMENO una versione valida e tutte le relative varisoni valide: IsActive == TRUE && IsDRAFT == FALSE</returns>
        //public IList<ServiceExport.DTO_Template> TemplateGetAllAvailable(String ServiceCode)
        //{
        //    return null;
        //}

        /// <summary>
        /// Recupera una lista di DTO adatti all'inserimento in una DropDownList per la selezione del Template/Version
        /// </summary>
        /// <param name="filters">Filtri vari: DA DEFINIRE!!!</param>
        /// <returns>La lista di DTO</returns>
        /// <remarks>Controllare e verificare i vari parametri da passare per il recupero corretto delle varie liste</remarks>
        ///
        public List <ServiceExport.DTO_sTemplate> GetAvailableTemplates(long idTemplate, long idVersion, long idModule)
        {
            List <ServiceExport.DTO_sTemplate> items = new List <ServiceExport.DTO_sTemplate>();


            // Get all templates

            var         queryService = (from s in Manager.GetIQ <ServiceContent>() where s.Deleted == BaseStatusDeleted.None select s);
            List <long> idItems      = (from t in Manager.GetIQ <Template>()
                                        where t.Deleted == BaseStatusDeleted.None && t.IsActive && t.HasDefinitive
                                        select t.Id).ToList();

            //Modificato HasActive in IsActive (HasDefinitive = true "include" HasActive = true) - M.B.
            idItems = idItems.Where(id => (queryService.Where(s => s.ModuleId == idModule && s.Template.Id == id).Any() ||
                                           !queryService.Where(s => s.Template.Id == id).Any())).ToList();

            items = (from t in Manager.GetIQ <Template>()
                     where idItems.Contains(t.Id)
                     select new ServiceExport.DTO_sTemplate()
            {
                HasActive = t.HasActive,
                HasDefinitive = t.HasDefinitive,
                HasDraft = t.HasDraft,
                Id = t.Id,
                IsActive = t.IsActive,
                IsSystem = t.IsSystem,
                Name = t.Name
            }).ToList();

            items.ForEach(t => t.Versions = (from v in Manager.GetIQ <TemplateVersion>()
                                             where (v.Id == idVersion || (v.Deleted == BaseStatusDeleted.None && v.IsActive && !v.IsDraft)) && v.Template.Id == t.Id
                                             select new ServiceExport.DTO_sTemplateVersion()
            {
                Id = v.Id,
                IsActive = v.IsActive,
                IsDraft = v.IsDraft,
                Version = v.Version,
                IdTemplate = v.Template.Id,
                Lastmodify = (v.ModifiedOn == null) ? v.CreatedOn: v.ModifiedOn,
                IsSelected = (v.Id == idVersion && t.Id == idTemplate)
            }
                                             ).ToList().OrderByDescending(v => v.Version).ToList());

            ServiceExport.DTO_sTemplate template = items.Where(t => t.Versions.Count == 0 && t.Id == idTemplate).FirstOrDefault();
            if (template != null)
            {
                //ServiceExport.DTO_sTemplateVersion ver = (from v in Manager.GetIQ<TemplateVersion>()
                //                                          where (v.Id == idVersion || (v.Deleted == BaseStatusDeleted.None && v.IsActive && !v.IsDraft)) && v.Template.Id == template.Id
                //                             select new ServiceExport.DTO_sTemplateVersion() {
                //                                  Id = v.Id,
                //                                  IsActive = v.IsActive,
                //                                  IsDraft = v.IsDraft,
                //                                  Version = v.Version,
                //                                  IdTemplate = template.Id,
                //                                  Lastmodify = (v.ModifiedOn==null) ? v.CreatedOn: v.ModifiedOn,
                //                                  IsSelected = (v.Id == idVersion && template.Id == idTemplate)
                //                             }
                //                           ).OrderByDescending(v => v.Version).Skip(0).Take(1).ToList().FirstOrDefault();

                TemplateVersion tVer = Manager.Get <TemplateVersion>(idVersion);

                if (tVer != null && tVer.Deleted == BaseStatusDeleted.None && tVer.IsActive && tVer.IsDraft)
                {
                    ServiceExport.DTO_sTemplateVersion ver = new ServiceExport.DTO_sTemplateVersion()
                    {
                        Id         = tVer.Id,
                        IsActive   = tVer.IsActive,
                        IsDraft    = tVer.IsDraft,
                        Version    = tVer.Version,
                        IdTemplate = template.Id,
                        Lastmodify = (tVer.ModifiedOn == null) ? tVer.CreatedOn : tVer.ModifiedOn,
                        IsSelected = (tVer.Id == idVersion && template.Id == idTemplate)
                    };

                    template.Versions.Add(ver);
                }
            }

            DateTime lastVersion = DateTime.Now;

            items.Where(t => t.Versions.Count > 0).ToList().ForEach(t => t.Versions.Insert(0,
                                                                                           new ServiceExport.DTO_sTemplateVersion()
            {
                Id         = 0,
                IsActive   = true,
                IsDraft    = false,
                Lastmodify = lastVersion,
                Version    = 0,
                IdTemplate = t.Id,
                IsSelected = (idVersion == 0 && t.Id == idTemplate)
            }));


            //Add Selected: Solo se il TEMPLATE indicato NON è stato trovato!
            if (!items.Where(t => t.Versions.Where(v => v.IsSelected == true).Any()).Any() && (idTemplate > 0 || idVersion > 0))
            {
                ServiceExport.DTO_sTemplate        dtoTemplate = null;
                ServiceExport.DTO_sTemplateVersion dtoVersion  = null;

                if (idVersion <= 0) //LAST VERSION! Se non ci sono versioni "Definitive", recupero l'ultima "Deprecata"...
                {
                    dtoTemplate = (from t in Manager.GetIQ <Template>()
                                   where t.Id == idTemplate
                                   select new ServiceExport.DTO_sTemplate()
                    {
                        HasActive = t.HasActive,
                        HasDefinitive = t.HasDefinitive,
                        HasDraft = t.HasDraft,
                        Id = t.Id,
                        IsActive = t.IsActive,
                        IsSystem = t.IsSystem,
                        Name = t.Name
                    }).Skip(0).Take(1).ToList().FirstOrDefault();

                    if (dtoTemplate != null)
                    {
                        TemplateVersion tVersion = (from v in Manager.GetIQ <TemplateVersion>()
                                                    where (dtoTemplate.HasDefinitive && !v.IsDraft)
                                                    select v)
                                                   .OrderByDescending(v => v.IsActive)
                                                   .ThenBy(v => v.Version)
                                                   .Skip(0).Take(1).ToList().FirstOrDefault();

                        if (tVersion != null)
                        {
                            dtoVersion = new ServiceExport.DTO_sTemplateVersion()
                            {
                                Id         = tVersion.Id,
                                IsActive   = tVersion.IsActive,
                                IsDraft    = tVersion.IsDraft,
                                Version    = tVersion.Version,
                                IdTemplate = tVersion.Template.Id,
                                Lastmodify = (tVersion.ModifiedOn == null) ? tVersion.CreatedOn : tVersion.ModifiedOn
                            };
                        }

                        //dtoVersion = (from v in Manager.GetIQ<TemplateVersion>()
                        //                     where (dtoTemplate.HasDefinitive && v.IsDraft==false && v.IsActive ) || (!dtoTemplate.HasDefinitive && v.IsActive)
                        //                     select new ServiceExport.DTO_sTemplateVersion() {
                        //                          Id = v.Id,
                        //                          IsActive = v.IsActive,
                        //                          IsDraft = v.IsDraft,
                        //                          Version = v.Version,
                        //                           IdTemplate = v.Template.Id,
                        //                          Lastmodify = (v.ModifiedOn==null) ? v.CreatedOn: v.ModifiedOn
                        //                     }
                        //                   ).OrderByDescending(v => v.Version).Skip(0).Take(1).ToList().FirstOrDefault();
                    }
                }
                else
                {
                    dtoVersion = (from v in Manager.GetIQ <TemplateVersion>()
                                  where v.Id == idVersion
                                  select new ServiceExport.DTO_sTemplateVersion()
                    {
                        Id = v.Id,
                        IsActive = v.IsActive,
                        IsDraft = v.IsDraft,
                        Version = v.Version,
                        IdTemplate = v.Template.Id,
                        Lastmodify = (v.ModifiedOn == null) ? v.CreatedOn: v.ModifiedOn
                    }
                                  ).Skip(0).Take(1).ToList().FirstOrDefault();
                    if (dtoVersion != null)
                    {
                        dtoTemplate = (from t in Manager.GetIQ <Template>()
                                       where t.Id == idTemplate
                                       select new ServiceExport.DTO_sTemplate()
                        {
                            HasActive = t.HasActive,
                            HasDefinitive = t.HasDefinitive,
                            HasDraft = t.HasDraft,
                            Id = t.Id,
                            IsActive = t.IsActive,
                            IsSystem = t.IsSystem,
                            Name = t.Name
                        }).Skip(0).Take(1).ToList().FirstOrDefault();
                        //Controllo la versione recuperata da dB:
                        // Se NON soddisfa i requisiti, viene impostata a null
                        if (!(dtoTemplate != null && dtoTemplate.Id == dtoVersion.IdTemplate))
                        {
                            dtoVersion = null;
                        }
                    }
                }

                if (dtoTemplate != null && dtoVersion != null)
                {
                    if (dtoTemplate.Versions == null)
                    {
                        dtoTemplate.Versions = new List <ServiceExport.DTO_sTemplateVersion>();
                    }


                    dtoTemplate.Versions.Add(dtoVersion);


                    dtoTemplate.Versions.Insert(0,
                                                new ServiceExport.DTO_sTemplateVersion()
                    {
                        Id         = 0,
                        IsActive   = true,
                        IsDraft    = false,
                        Lastmodify = lastVersion,
                        Version    = 0,
                        IdTemplate = dtoTemplate.Id,
                        IsSelected = (idVersion == 0 && dtoTemplate.Id == idTemplate)
                    });

                    items.RemoveAll(t => t.Id == dtoTemplate.Id);

                    items.Add(dtoTemplate);
                }
            }



            items.ForEach(t => t.Services = queryService.Where(s => s.Template.Id == t.Id).Select(s => new ServiceExport.DTO_sServiceContent()
            {
                IdModule = s.ModuleId, IsActive = s.IsActive, ModuleCode = s.ModuleCode
            }).ToList());
            return(items);
        }