Пример #1
0
        public void DeleteOrphandExerciseRecords(DeleteOldProfilesParam param)
        {
            Serie serie = null;
            ExerciseProfileData profileData = null;
            var unusedProfiles = NHibernateContext.Current().Session.QueryOver <ExerciseProfileData>().JoinAlias(x => x.Serie, () => serie)
                                 .JoinAlias(x => serie.ExerciseProfileData, () => profileData)
                                 .Where(x => profileData.GlobalId != x.GlobalId).List();

            if (!param.OnlyShowUsers)
            {
                using (var trans = NHibernateContext.Current().Session.BeginSaveTransaction())
                {
                    foreach (var unusedProfile in unusedProfiles)
                    {
                        try
                        {
                            if (unusedProfile.GlobalId != unusedProfile.Serie.ExerciseProfileData.GlobalId)
                            {
                                NHibernateContext.Current().Session.Delete(unusedProfile);
                            }
                        }
                        catch (Exception ex)
                        {
                            BodyArchitect.Logger.ExceptionHandler.Default.Process(ex);
                            throw;
                        }
                    }
                    trans.Commit();
                }
            }
        }
Пример #2
0
        public IList <UserDTO> DeleteOldProfiles(DeleteOldProfilesParam param)
        {
            //ProfileStatistics stat = null;
            //BAPoints point = null;
            //var unusedProfiles =
            //    NHibernateContext.Current().Session.QueryOver<Profile>().JoinAlias(x => x.Statistics, () => stat).JoinAlias(x => x.BAPoints, () => point)
            //        .Where(x => stat.TrainingDaysCount == 0 && stat.WorkoutPlansCount == 0 &&
            //            stat.SupplementsDefinitionsCount == 0 && stat.LastLoginDate < DateTime.Now.AddMonths(-8)
            //            && !x.IsDeleted && x.UserName != "Admin" && x.BAPoints.Count==0).List();
            var unusedProfiles = NHibernateContext.Current()
                                 .Session.Query <Profile>()
                                 .Where(x => x.Statistics.TrainingDaysCount == 0 && x.Statistics.WorkoutPlansCount == 0 &&
                                        x.Statistics.SupplementsDefinitionsCount == 0 &&
                                        x.Statistics.LastLoginDate < DateTime.Now.AddMonths(-8) &&
                                        !x.IsDeleted && x.UserName != "Admin" && !x.BAPoints.Any()).ToList();

            if (!param.OnlyShowUsers)
            {
                ServiceConfiguration configuration = new ServiceConfiguration();
                ProfileService       service       = new ProfileService(NHibernateContext.Current().Session, null, configuration, null, null, null);
                foreach (var unusedProfile in unusedProfiles)
                {
                    try
                    {
                        using (var trans = NHibernateContext.Current().Session.BeginSaveTransaction())
                        {
                            service.deleteProfile(NHibernateContext.Current().Session, unusedProfile);
                            if (unusedProfile.Picture != null)
                            {
                                PictureService pictureService = new PictureService(NHibernateContext.Current().Session, null, configuration);
                                pictureService.DeletePicture(unusedProfile.Picture);
                            }
                            trans.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        BodyArchitect.Logger.ExceptionHandler.Default.Process(ex);
                        throw;
                    }
                }
            }
            return(unusedProfiles.Map <IList <UserDTO> >());
        }
Пример #3
0
        public IList <PictureInfoDTO> DeleteUnusedImages(DeleteOldProfilesParam param)
        {
            var            profilesWithImages  = NHibernateContext.Current().Session.QueryOver <Profile>().Where(x => x.Picture != null).List();
            var            customersWithImages = NHibernateContext.Current().Session.QueryOver <Customer>().Where(x => x.Picture != null).List();
            List <Picture> pictures            = new List <Picture>();

            pictures.AddRange(profilesWithImages.Select(x => x.Picture));
            pictures.AddRange(customersWithImages.Select(x => x.Picture));

            List <PictureInfoDTO> notUsed      = new List <PictureInfoDTO>();
            var dictionaryImages               = pictures.ToDictionary(x => x.PictureId.ToString());
            ServiceConfiguration configuration = new ServiceConfiguration();
            var files = Directory.GetFiles(configuration.ImagesFolder);

            foreach (var file in files)
            {
                var filename = Path.GetFileName(file);
                if (string.IsNullOrEmpty(Path.GetExtension(filename)))
                {
                    bool isUsed = dictionaryImages.ContainsKey(filename);
                    if (!isUsed)
                    {
                        notUsed.Add(new PictureInfoDTO(new Guid(filename), ""));
                    }
                }
            }
            if (!param.OnlyShowUsers)
            {
                foreach (var pictureInfoDto in notUsed)
                {
                    PictureService pictureService = new PictureService(NHibernateContext.Current().Session, null, configuration);
                    pictureService.DeletePicture(pictureInfoDto.Map <Picture>());
                }
            }
            return(notUsed);
        }