Exemplo n.º 1
0
 public ActionResult Edit(MusicUploadViewModels model)
 {
     if (ModelState.IsValid)
     {
         repository.EditMusic(model);
     }
     return(RedirectToAction("Index", "Music"));
 }
Exemplo n.º 2
0
        public ActionResult Insert()
        {
            MusicUploadViewModels mu = new MusicUploadViewModels();

            mu.SingerList        = repository.GetSelectListSinger();
            mu.MusicCategoryList = repository.GetSelectListMusicCategory();

            return(View(mu));
        }
Exemplo n.º 3
0
        public ActionResult Insert(MusicUploadViewModels model)
        {
            if (ModelState.IsValid)
            {
                string path = Server.MapPath("~/Content/Uploads/");

                repository.Insert(model, path);

                return(RedirectToAction("Index", "Music"));
            }
            else
            {
                MusicUploadViewModels mu = new MusicUploadViewModels();
                mu.SingerList        = repository.GetSelectListSinger();
                mu.MusicCategoryList = repository.GetSelectListMusicCategory();
                return(View(mu));
            }
        }
Exemplo n.º 4
0
        public void EditMusic(MusicUploadViewModels model)
        {
            Music mus = (from row in context.Musics
                         where row.Id == model.Id
                         select row).FirstOrDefault();

            if (mus != null)
            {
                mus.CategoryMusicId_Fk = model.SelectMusicCategory;
                mus.Description        = model.Description;
                mus.EngName            = model.EngName;
                mus.FarsiName          = model.FarsiName;
                mus.Lyrics             = model.Lyrics;
                mus.SingerId_Fk        = model.SelectSinger;
                mus.TimeAdded          = DateTime.Now;
                mus.Title = model.Title;
            }

            context.SaveChanges();
        }
Exemplo n.º 5
0
        public MusicUploadViewModels GetMusicUploadByMusicId(int id)
        {
            MusicUploadViewModels mv = (from row in context.Musics
                                        where row.Id == id
                                        select new MusicUploadViewModels
            {
                Id = row.Id,
                Description = row.Description,
                EngName = row.EngName,
                FarsiName = row.FarsiName,
                FileName = row.FileName,
                Lyrics = row.Lyrics,
                PictureName = row.PictureName,
                SelectMusicCategory = row.CategoryMusicId_Fk,
                SelectSinger = row.SingerId_Fk,
                Title = row.Title
            }).FirstOrDefault();

            mv.MusicCategoryList = GetSelectListMusicCategory();
            mv.SingerList        = GetSelectListSinger();


            return(mv);
        }
Exemplo n.º 6
0
        public void Insert(MusicUploadViewModels model, string path)
        {
            Music mus = new Music();

            mus.CategoryMusicId_Fk = model.SelectMusicCategory;
            mus.Description        = model.Description;
            mus.EngName            = model.EngName;
            mus.FarsiName          = model.FarsiName;
            mus.Lyrics             = model.Lyrics;
            mus.SingerId_Fk        = model.SelectSinger;
            mus.TimeAdded          = DateTime.Now;
            mus.Title = model.Title;

            string fileMusicName = model.UpMusicFile.FileName;

            fileMusicName = fileMusicName.Replace(" ", "");

            string musicPath = path + @"\Music\" + fileMusicName;

            if (System.IO.File.Exists(musicPath))
            {
                int    number  = 1;
                string exmusic = Path.GetExtension(musicPath);
                string mnmusic = Path.GetFileNameWithoutExtension(musicPath);
                while (System.IO.File.Exists(musicPath))
                {
                    musicPath = musicPath.Replace("_" + number, "");
                    musicPath = path + @"\Music\" + mnmusic + "_" + number + exmusic;
                    number++;
                }
            }

            mus.FileName = Path.GetFileName(musicPath);

            model.UpMusicFile.SaveAs(musicPath);

            string fileMusicPictureName = model.UpMusicPictureFile.FileName;

            fileMusicPictureName = fileMusicPictureName.Replace(" ", "");

            string musicPicturePath = path + @"\MusicPicture\" + fileMusicPictureName;


            if (System.IO.File.Exists(musicPicturePath))
            {
                int    number  = 1;
                string exmusic = Path.GetExtension(musicPicturePath);
                string mnmusic = Path.GetFileNameWithoutExtension(musicPicturePath);
                while (System.IO.File.Exists(musicPicturePath))
                {
                    musicPicturePath = musicPicturePath.Replace("_" + number, "");
                    musicPicturePath = path + @"\MusicPicture\" + mnmusic + "_" + number + exmusic;
                    number++;
                }
            }

            model.UpMusicPictureFile.SaveAs(musicPicturePath);

            mus.PictureName = Path.GetFileName(musicPicturePath);

            context.Musics.Add(mus);
            context.SaveChanges();
        }
Exemplo n.º 7
0
        public ActionResult Edit(int id)
        {
            MusicUploadViewModels mu = repository.GetMusicUploadByMusicId(id);

            return(View(mu));
        }