public void AddPhoto(IKatushaFileSystem fileSystem, IPhotoBackupService photoBackupService, Photo photo, HttpPostedFileBase hpf, byte[] thumbnailBytes)
 {
     foreach (var suffix in PhotoTypes.Versions.Keys) {
         var bytes = (suffix == (byte) PhotoType.Thumbnail) ? thumbnailBytes : BuildImage(hpf, suffix);
         fileSystem.WritePhoto(photo, (PhotoType)suffix, bytes);
         if (suffix == (byte)PhotoType.Original)
             photoBackupService.AddPhoto(new PhotoBackup { Guid = photo.Guid, Data = bytes });
     }
 }
 public string TestMail()
 {
     var user = _userRepository.GetByUserName("mertiko");
     user.Email = "*****@*****.**";
     var profile = _profileRepository.GetByGuid(user.Guid);
     profile.User = user;
     var conversation = new Conversation {FromName = "FROM Mert Sakarya", FromGuid = user.Guid, ToName = "TO Mert Sakarya", ToGuid = user.Guid};
     var photo = new Photo {Guid = profile.ProfilePhotoGuid, FileName = "PhotoFileName.jpg"};
     var sb = new StringBuilder();
     sb.AppendFormat("UserRegistered\r\n{0}\r\n", UserRegistered(user));
     sb.AppendFormat("\r\nSiteDeployed\r\n{0}\r\n", SiteDeployed(user));
     sb.AppendFormat("\r\nMessageSent\r\n{0}\r\n", MessageSent(conversation));
     sb.AppendFormat("\r\nMessageRead\r\n{0}\r\n", MessageRead(conversation));
     sb.AppendFormat("\r\nPurchase\r\n{0}\r\n", Purchase(user, new Product {Name = "SAMPLE PRODUCT"}));
     sb.AppendFormat("\r\nProfileCreated\r\n{0}\r\n", ProfileCreated(profile));
     sb.AppendFormat("\r\nPhotoAdded\r\n{0}\r\n", PhotoAdded(photo));
     return sb.ToString();
 }
 public string PhotoAdded(Photo photo)
 {
     return "";
     //try {
     //    return Mailer.Mailer.SendMail(_adminMailAddress, String.Format("[PHOTO ADDED] " + photo.FileName), PhotoAddedAdmin, _mailTemplatesFolder, photo);
     //} catch (Exception ex) {
     //    return ex.Message;
     //}
 }
        public ViewDataUploadFilesResult AddPhoto(long profileId, string description, HttpPostedFileBase hpf)
        {
            if (hpf.ContentLength <= 0) return null;
            var profile = _profileRepository.SingleAttached(p => p.Id == profileId);
            if (profile == null) return null;
            var guid = Guid.NewGuid();
            var photo = new Photo { Description = description, ProfileId = profileId, Status = (byte)PhotoStatus.Uploading, FileName = hpf.FileName, ContentType = "image/jpeg", Guid = guid };
            _photoRepository.Add(photo, photo.Guid);
            var bytes = PhotoManager.BuildImage(hpf, (byte)PhotoType.Thumbnail);

            if (profile.ProfilePhotoGuid == Guid.Empty) { //set first photo as default photo
                profile.ProfilePhotoGuid = photo.Guid;
                _profileRepository.FullUpdate(profile);
            }
            _profileService.UpdateRavenProfile(profile.Id);
            _notificationService.PhotoAdded(photo);
            (new PhotoManager()).AddPhoto(_fileSystem, _photoBackupService, photo, hpf, bytes);
            //(new AsyncAddPhotoCaller((new PhotoManager()).AddPhoto)).BeginInvoke(_fileSystem, _photoBackupService, photo, hpf, bytes, null, null);

            var id = (String.IsNullOrEmpty(profile.FriendlyName)) ? profile.Guid.ToString() : profile.FriendlyName;
            return new ViewDataUploadFilesResult {
                name = hpf.FileName,
                size = hpf.ContentLength,
                type = hpf.ContentType,
                url = _fileSystem.GetPhotoUrl(guid, PhotoType.Large),
                delete_url = String.Format("/Profiles/DeletePhoto/{0}/{1}", id, guid),
                delete_type = "GET",
                thumbnail_url = @"data:image/jpg;base64," + Convert.ToBase64String(bytes) //fileSystem.GetPhotoUrl(guid, PhotoType.Thumbnail)
            };
        }
        private bool _DeletePhoto(Photo entity)
        {
            var isProfilePhoto = false;
            if (entity != null)
            {
                var profileId = entity.ProfileId;
                var photoGuid = entity.Guid;
                _photoRepository.Delete(entity);
                if (!_conversationService.HasPhotoGuid(photoGuid))
                {
                    _fileSystem.DeletePhoto(photoGuid);
                    _photoBackupService.DeleteBackupPhoto(photoGuid);
                }

                var profile = _profileRepository.SingleAttached(p => p.Id == profileId, p => p.Photos);
                if (profile != null)
                {
                    if (profile.ProfilePhotoGuid == photoGuid)
                    {
                        isProfilePhoto = true;
                        profile.ProfilePhotoGuid = Guid.Empty;
                        _profileRepository.FullUpdate(profile);
                    }
                    _profileService.UpdateRavenProfile(profileId);
                }
            }
            return isProfilePhoto;
        }
 public void WritePhoto(Photo photo, PhotoType photoType, byte[] bytes)
 {
     var path = String.Format("{0}/{1}/{2}-{3}.jpg", _baseFolderName, Folders.Photos, (byte) photoType, photo.Guid);
     using(var writer = new FileStream(path, FileMode.Create, FileAccess.Write)) {
         writer.Write(bytes, 0, bytes.Length);
     }
 }