Exemplo n.º 1
0
        public ActionResult Download(int id)
        {
            string         api      = ConfigurationManager.AppSettings["ApiServer"] + "/MusicProject/music/" + id;
            HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(api);
            WebResponse    response = request.GetResponse();

            MusicWebApp.Models.Music model = null;
            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                var          json   = reader.ReadToEnd();
                model = JsonConvert.DeserializeObject <MusicWebApp.Models.Music>(json);
            }

            return(Redirect(model.Link));
        }
Exemplo n.º 2
0
        // GET: Music/PlayMusic
        public ActionResult Index(int musicid)
        {
            string         api      = ConfigurationManager.AppSettings["ApiServer"] + "/MusicProject/music/" + musicid;
            HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(api);
            WebResponse    response = request.GetResponse();

            MusicWebApp.Models.Music model = null;
            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                var          json   = reader.ReadToEnd();
                model = JsonConvert.DeserializeObject <MusicWebApp.Models.Music>(json);
            }
            if (model != null)
            {
                BackgroundJob.Enqueue(() => Background.UpdateView((int)EnumProject.MUSIC, model.Id));
            }

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Upload(MusicUploadViewModel model)
        {
            string storageUrl = "musicproject-9f3c5.appspot.com";
            string message    = "Save failed";

            string date = DateTime.Now.ToString("yyyyMMddHHmmssffff");

            try
            {
                var stream1 = model.ImageBase.InputStream;
                var task1   = new FirebaseStorage(storageUrl)
                              .Child("MusicProject")
                              .Child("Images")
                              .Child(date + model.ImageBase.FileName)
                              .PutAsync(stream1);
                task1.Progress.ProgressChanged += (s, e) => ProgressHub.SendMessage("Uploading Image ... (" + Math.Round((e.Position * 1.0 / e.Length * 100), 0) + "%)");

                var stream2 = model.MusicBase.InputStream;
                var task2   = new FirebaseStorage(storageUrl)
                              .Child("MusicProject")
                              .Child("Musics")
                              .Child(date + model.MusicBase.FileName)
                              .PutAsync(stream2);
                task2.Progress.ProgressChanged += (s, e) => ProgressHub.SendMessage("Uploading Music ... (" + Math.Round((e.Position * 1.0 / e.Length * 100), 0) + "%)");

                MusicEntities en = new MusicEntities();

                var  name      = System.Web.HttpContext.Current.User.Identity.Name;
                var  login     = en.Logins.FirstOrDefault(a => a.Username.Equals(name));
                User userLogin = null;
                if (login != null)
                {
                    userLogin = login.User;
                }

                string imageUrl = await task1;
                string musicUrl = await task2;

                var music = new MusicWebApp.Models.Music
                {
                    Name       = model.Name,
                    AlbumId    = model.AlbumId,
                    Image      = imageUrl,
                    Link       = musicUrl,
                    SingerId   = model.SingerId,
                    UserId     = userLogin.Id,
                    GenresId   = model.GenresId,
                    Pending    = false,
                    UploadDate = DateTime.Now,
                    C_View     = 0,
                };

                en.Musics.Add(music);
                en.SaveChanges();
                message = "Save successful";
            }
            catch (Exception ex)
            {
                return(Json(new { succress = false, message = ex.Message }));
            }

            return(Json(new { success = true, message = message }));
        }