Пример #1
0
        public void CreateRootGallery(User owner, bool isTrashGallery)
        {
            string galleryName;
            string galleryDescription;

            if(isTrashGallery)
            {
                galleryName = "Trash";
                galleryDescription = "Use for photos that does not belong to any gallery";
            }
            else
            {
                galleryName = "Root gallery";
                galleryDescription = "Root gallery for user, cannot be deleted.";
            }

            var gal = new Gallery
                {
                    DateCreated = DateTime.Now,
                    ParentId = ObjectId.Empty,
                    OwnerId = owner.Id,
                    Name = galleryName,
                    Description = galleryDescription,
                    Order = 1,
                    IsTrashGallery = isTrashGallery
                };
            Save(gal);
        }
Пример #2
0
 public User RegisterNewUser(Register regModel)
 {
     var cryptedPassword = new Crypto().Encrypt(regModel.Password);
     var newUser = new User { Email = regModel.Email, PasswordCrypted = cryptedPassword, UserName = regModel.Name };
     Save(newUser);
     return newUser;
 }
Пример #3
0
        public Gallery ClearTrashGallery(User owner)
        {
            var trash = GetTrashGallery(owner);
            if(trash != null && trash.Photos != null && trash.Photos.Any())
            {
                trash.Photos.Clear();
                Save(trash);
            }

            return trash;
        }
Пример #4
0
 public void Save(User user)
 {
     _users.Collection.Save(user);
 }
Пример #5
0
 public void Delete(User user)
 {
     _users.Collection.Remove(Query.EQ("_id", user.Id));
 }
Пример #6
0
 public static bool IsPasswordOK(string password, User user)
 {
     var cryptedPassword = new Crypto().Encrypt(password);
     return cryptedPassword.Equals(user.PasswordCrypted);
 }
Пример #7
0
 public bool IsTrashGalleryExistForUser(User owner)
 {
     return _galleries.Collection.AsQueryable().Any(g => g.OwnerId == owner.Id && g.IsTrashGallery);
 }
Пример #8
0
 public Gallery GetTrashGallery(User owner)
 {
     return _galleries.Collection.AsQueryable().First(g => g.OwnerId == owner.Id && g.IsTrashGallery);
 }
Пример #9
0
 public bool IsRootGalleryExistForUser(User owner)
 {
     return _galleries.Collection.AsQueryable().Any(g => g.OwnerId == owner.Id && g.ParentId == ObjectId.Empty);
 }
Пример #10
0
 public Gallery GetRootGallery(User owner)
 {
     return _galleries.Collection.AsQueryable().First(g => g.OwnerId == owner.Id && !g.IsTrashGallery && g.ParentId == ObjectId.Empty);
 }
Пример #11
0
 public List<Gallery> GetGalerieForUser(User owner)
 {
     return _galleries.Collection.Find(Query.EQ("OwnerId", owner.Id)).ToList();
 }
Пример #12
0
 private void LoginUser(User user)
 {
     FormsAuthentication.SetAuthCookie(user.Id.ToString(), true);
 }
Пример #13
0
        public void MovePhotoSiblingsToTrash(User owner)
        {
            var photos = _photos.Collection.FindAll();
            if(photos != null && photos.Any())
            {
                var galleryManager = new GalleryManager();
                var trashGallery = galleryManager.GetTrashGallery(owner);
                var siblings = (from photo in photos where !galleryManager.IsPhotoInGallery(photo.Id) select photo.Id.ToString()).ToList();

                if (siblings.Count > 0)
                {
                    galleryManager.AddPhotosToGallery(trashGallery.Id.ToString(), siblings.ToArray());
                }
            }
        }
Пример #14
0
        public List<OrigPhotosWaiting> GetWaitingPhotos(User user)
        {
            var retColl = new List<OrigPhotosWaiting>();
            var currentUserDir = user.UserNameSEO;
            var files = GetFilesInUploadDirectory(currentUserDir);
            if (files.Length > 0)
            {
                var typeManager = new PhotoTypeManager();
                var uploadTempType = typeManager.GetBySystemName("minithumb");
                var uploadType = typeManager.GetBySystemName("upload");

                for (int i = 0; i < files.Length; i++)
                {
                    var photoAlreadyInDb = GetPhotoByFileName(files[i].Name);

                    string fileName;
                    ObjectId id;
                    if (photoAlreadyInDb == null) //fotku sme jeste nezpracovavali
                    {
                        fileName = RenameToSystemFileName(files[i].FullName);
                        var fotka = new Photo { FileName = fileName, User = user, DateUploaded = files[i].CreationTime };

                        Save(fotka);
                        AddPhotoTypeToPhoto(fotka, uploadType);
                        try
                        {
                            ImageProcessingManager.ResizeImage(fotka, uploadType, uploadTempType);
                            AddPhotoTypeToPhoto(fotka, uploadTempType);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        id = fotka.Id;
                    }
                    else
                    {
                        fileName = photoAlreadyInDb.FileName;
                        id = photoAlreadyInDb.Id;
                    }

                    var photoWaiting = new OrigPhotosWaiting { FileName = fileName, UploadedDate = files[i].CreationTime, Id = id.ToString() };

                    //X,Y dimensions of originally uploaded photo - uncomment if you need to diplay it on ProcessUploadPhotos view.
                    /*
                    var origPath = HttpContext.Current.Server.MapPath(string.Format("/{0}/{1}/{2}/{3}", ConfigurationManager.AppSettings["GalleryRootDirVirtualPath"], currentUserDir, uploadType.Adresar, fileName));
                    var origDimensions = ImageProcessingManager.GetImageDimensions(origPath);
                    photoWaiting.X = origDimensions[0];
                    photoWaiting.Y = origDimensions[1];
                    */

                    photoWaiting.ThumbPath = string.Format("/{0}/{1}/{2}/{3}", ConfigurationManager.AppSettings["GalleryRootDirVirtualPath"], currentUserDir, uploadTempType.Directory, fileName);

                    retColl.Add(photoWaiting);
                }
            }
            return retColl;
        }