예제 #1
0
        public void Save(long idItem, long idVersion, long idSettings, EvaluationType evaluation, List <dtoScormItemEvaluationSettings> items)
        {
            if (!SessionTimeout())
            {
                ModuleRepository.ActionType uAction = ModuleRepository.ActionType.ScormSettingsUnableToSave;
                Int32 idCommunity = View.RepositoryIdCommunity;
                liteRepositoryItemVersion version = Service.ItemGetVersion(idItem, idVersion);
                if (version == null)
                {
                    uAction = ModuleRepository.ActionType.ScormSettingsLoaded;
                    View.DisplayUnknownItem();
                    View.AllowSave = false;
                }
                else
                {
                    ScormPackageSettings settings = Service.ScormPackageSettingsSave(idItem, idVersion, idSettings, evaluation, items);
                    if (settings == null)
                    {
                        uAction = ModuleRepository.ActionType.ScormSettingsUnableToSave;
                        View.DisplayMessage(version.DisplayName, version.Extension, version.Type, Domain.UserMessageType.scormSettingsUnableToSave, version.Availability);
                    }
                    else
                    {
                        View.IdSettings = settings.Id;
                        View.LoadSettings(version.UniqueIdVersion.ToString(), version.DisplayName, dtoScormPackageSettings.CreateFrom(settings, version), false, false);

                        uAction = ModuleRepository.ActionType.ScormSettingsSaved;
                        View.DisplayMessage(version.DisplayName, version.Extension, version.Type, Domain.UserMessageType.scormSettingsSaved, version.Availability);
                    }
                }
                View.SendUserAction(idCommunity, Service.GetIdModule(), uAction);
            }
        }
        public dtoScormPackageSettings ScormPackageGetDtoCompletionSettings(liteRepositoryItemVersion version, long idSettings = 0)
        {
            dtoScormPackageSettings item = null;

            try
            {
                ScormPackageSettings settings = (from s in Manager.GetIQ <ScormPackageSettings>()
                                                 where (idSettings == 0 || idSettings == s.Id) && s.IdItem == version.IdItem && s.IdVersion == version.Id select s).OrderByDescending(s => s.Id).Skip(0).Take(1).ToList().FirstOrDefault();
                if (settings != null)
                {
                    item = dtoScormPackageSettings.CreateFrom(settings, version);
                }
            }
            catch (Exception ex) {
            }
            return(item);
        }
        public ScormPackageSettings ScormPackageSettingsClone(long idSettings, long idItem, Guid uniqueId, long idVersion, Guid uniqueIdVersion, RepositoryIdentifier repository)
        {
            ScormPackageSettings clone = null;

            try
            {
                litePerson           person   = GetValidPerson(UC.CurrentUserID);
                ScormPackageSettings settings = Manager.Get <ScormPackageSettings>(idSettings);
                if (person != null && settings != null)
                {
                    Manager.BeginTransaction();
                    clone = settings.Copy(person.Id, UC.IpAddress, UC.ProxyIpAddress, idItem, uniqueId, idVersion, uniqueIdVersion, repository);
                    Manager.SaveOrUpdate(clone);
                    if (settings.Organizations.Any())
                    {
                        foreach (ScormOrganizationSettings o in settings.Organizations)
                        {
                            ScormOrganizationSettings organization = o.Copy(clone.Id);
                            Manager.SaveOrUpdate(organization);
                            foreach (ScormItemSettings source in o.Items.Where(i => i.IdParentItem == 0))
                            {
                                ScormItemSettings nItem = source.Copy(clone.Id, organization.Id, 0);
                                Manager.SaveOrUpdate(nItem);
                                ItemSettingsClone(nItem, source.Id, o.Items.Where(i => i.IdParentItem > 0));
                            }
                            clone.Organizations.Add(organization);
                        }
                    }
                    if (settings.IdItem == idItem && settings.IdVersion == idVersion)
                    {
                        settings.IsCurrent  = false;
                        settings.ValidUntil = DateTime.Now;
                        clone.IsCurrent     = true;
                        Manager.SaveOrUpdate(clone);
                        Manager.SaveOrUpdate(settings);
                    }
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                clone = null;
            }
            return(clone);
        }
        public ScormPackageSettings ScormPackageSettingsSave(long idItem, long idVersion, long idSettings, EvaluationType evaluation, List <dtoScormItemEvaluationSettings> items)
        {
            ScormPackageSettings aSettings = null;

            try
            {
                litePerson           person   = GetValidPerson(UC.CurrentUserID);
                ScormPackageSettings settings = Manager.Get <ScormPackageSettings>(idSettings);
                if (person != null && settings != null)
                {
                    liteRepositoryItemVersion version = Manager.Get <liteRepositoryItemVersion>(idVersion);
                    if (version != null && version.IdItem == idItem)
                    {
                        Manager.BeginTransaction();

                        aSettings = settings.CreateForUpdateSettings(
                            person.Id,
                            UC.IpAddress,
                            UC.ProxyIpAddress,
                            version,
                            evaluation,
                            items.Where(i => i.ForPackage).FirstOrDefault());



                        Manager.SaveOrUpdate(aSettings);
                        if (settings.Organizations.Any())
                        {
                            foreach (ScormOrganizationSettings o in settings.Organizations)
                            {
                                ScormOrganizationSettings organization = o.Copy(aSettings.Id);
                                Manager.SaveOrUpdate(organization);
                                foreach (ScormItemSettings source in o.Items.Where(i => i.IdParentItem == 0))
                                {
                                    ScormItemSettings nItem = source.CreateForUpdateSettings(aSettings.Id, organization.Id, 0, evaluation, items.Where(i => i.Id == source.Id).FirstOrDefault());
                                    Manager.SaveOrUpdate(nItem);
                                    organization.Items.Add(nItem);
                                    ItemSettingsClone(organization, nItem, source.Id, o.Items.Where(i => i.IdParentItem > 0), evaluation, items);
                                }
                                aSettings.Organizations.Add(organization);
                            }
                        }
                        List <ScormPackageSettings> pSettings = (from s in Manager.GetIQ <ScormPackageSettings>() where s.IdVersion == idVersion && s.IdItem == idItem && s.IsCurrent && s.Id != aSettings.Id select s).ToList();
                        if (pSettings.Any())
                        {
                            DateTime date = DateTime.Now;
                            foreach (ScormPackageSettings s in pSettings)
                            {
                                s.IsCurrent  = false;
                                s.ValidUntil = DateTime.Now;
                                s.UpdateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            }
                            Manager.SaveOrUpdateList(pSettings);
                        }
                    }
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
            }
            return(aSettings);
        }