Ejemplo n.º 1
0
        public static AudioUpload[] Load(int? id, string username, bool? approved, bool? isPrivate)
        {
            List<AudioUpload> lAudioUpload = new List<AudioUpload>();
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader = (SqlDataReader) SqlHelper.GetDB().ExecuteReader( "LoadAudioUploads", id,
                                                               username, approved, isPrivate);

                while (reader.Read())
                {
                    AudioUpload audioUpload = new AudioUpload();

                    audioUpload.id = (int)reader["Id"];
                    audioUpload.username = (string)reader["Username"];
                    audioUpload.title = (string)reader["Title"];
                    audioUpload.approved = (bool)reader["Approved"];
                    audioUpload.isPrivate = (bool)reader["Private"];
                    lAudioUpload.Add(audioUpload);
                }
            }

            return lAudioUpload.ToArray();
        }
Ejemplo n.º 2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
                AudioUpload[] audioUploads = AudioUpload.Load(null, CurrentUserSession.Username, null, null);

                if (audioUploads.Length >= CurrentUserSession.BillingPlanOptions.MaxAudioUploads.Value
                    && (CurrentUserSession.Level != null && audioUploads.Length >= CurrentUserSession.Level.Restrictions.MaxAudioUploads))
                {
                    ((PageBase)Page).StatusPageMessage = Lang.Trans("You cannot upload more audio files!");
                    Response.Redirect("ShowStatus.aspx");
                    return;
                }

            if (!fileAudio.HasFile)
            {
                lblError.Text = Lang.Trans("Please select audio file!");
                return;
            }

            string title = txtTitle.Text.Length > 0 ? txtTitle.Text : Path.GetFileNameWithoutExtension(fileAudio.FileName);

            //string tempfile = Path.GetTempFileName();
            //fileAudio.SaveAs(tempfile);

            var audioUpload = new AudioUpload(CurrentUserSession.Username);
            if (CurrentUserSession != null)
            {
                if (CurrentUserSession.BillingPlanOptions.AutoApproveAudioUploads.Value
                    || CurrentUserSession.Level != null && CurrentUserSession.Level.Restrictions.AutoApproveAudioUploads)
                {
                    audioUpload.Approved = true;
                }
            }
            audioUpload.Title = title;
            audioUpload.IsPrivate = cbPrivateAudio.Checked;
            audioUpload.Save(); // Save to get new ID

            if (audioUpload.Approved && !audioUpload.IsPrivate)
            {
                #region Add NewFriendAudioUpload Event

                Event newEvent = new Event(audioUpload.Username);

                newEvent.Type = Event.eType.NewFriendAudioUpload;
                NewFriendAudioUpload newFriendAudioUpload = new NewFriendAudioUpload();
                newFriendAudioUpload.AudioUploadID = audioUpload.Id;
                newEvent.DetailsXML = Misc.ToXml(newFriendAudioUpload);

                newEvent.Save();

                string[] usernames = Classes.User.FetchMutuallyFriends(audioUpload.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        string text = String.Format("Your friend {0} has uploaded a new audio".Translate(),
                                              "<b>" + audioUpload.Username + "</b>");
                        int imageID = 0;
                        try
                        {
                            imageID = Photo.GetPrimary(audioUpload.Username).Id;
                        }
                        catch (NotFoundException)
                        {
                            User user = null;
                            try
                            {
                                user = User.Load(audioUpload.Username);
                                imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                            }
                            catch (NotFoundException) { break; }
                        }
                        string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                        User.SendOnlineEventNotification(audioUpload.Username, friendUsername,
                                                                 text, thumbnailUrl,
                                                                 UrlRewrite.CreateShowUserUrl(audioUpload.Username));
                    }
                }

                #endregion
            }

            string userFilesPath = "~/UserFiles/" + CurrentUserSession.Username;
            string userFilesDir = Server.MapPath(userFilesPath);
            if (!Directory.Exists(userFilesDir))
            {
                Directory.CreateDirectory(userFilesDir);
            }

            fileAudio.SaveAs(userFilesDir + @"\audio_" + audioUpload.Id + ".mp3");

            //File.Move(tempfile, userFilesDir + @"\audio_" + audioUpload.Id + ".mp3");
        }