Esempio n. 1
0
        public async Task <ActionResult <Music> > PostMusic(MusicDTO musicDTO)
        {
            /*_context.Music.Add(musicDTO);
             * await _context.SaveChangesAsync();
             *
             * return CreatedAtAction(nameof(GetMusic), new { id = musicDTO.Id }, musicDTO);*/


            var music = new Music
            {
                Title       = musicDTO.Title,
                Artist      = musicDTO.Artist,
                ReleaseDate = musicDTO.ReleaseDate,
                Genre       = musicDTO.Genre,
                Price       = musicDTO.Price,
                Rating      = musicDTO.Rating,
            };

            _context.Music.Add(music);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetMusic),
                       new { id = music.Id },
                       ItemToDTO(music)));
        }
Esempio n. 2
0
        public async Task DeleteMusic(MusicDTO music)
        {
            var NewMusic = _mapper.Map <MusicDTO, Music>(music);

            uow.Musics.Remove(NewMusic);
            await uow.CommitAsync();
        }
Esempio n. 3
0
        /// <summary>
        /// 单个音乐删除(软删除)
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public async Task DeleteBySoftAsync(MusicDTO t)
        {
            var music = MusicDTOMapperToModel.Map(t);
            await musicDAL.DeleteBySoftAsync(music);

            await musicDAL.CommitAsync();
        }
Esempio n. 4
0
        /// <summary>
        /// 单个音乐新增
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public async Task AddAsync(MusicDTO t)
        {
            var music = MusicDTOMapperToModel.Map(t);
            await musicDAL.AddAsync(music);

            await musicDAL.CommitAsync();
        }
Esempio n. 5
0
 //admin create new
 public void AdminCreateMusic(MusicDTO music)
 {
     //Save the Byte Array as File.
     try
     {
         var data = new MusicDao().Create(new Music()
         {
             MusicDayCreate       = DateTime.Now,
             MusicName            = music.MusicName,
             MusicDownloadAllowed = true,
             SongOrMV             = music.SongOrMV,
             CategoryId           = music.CategoryId,
             MusicImage           = music.MusicImage,
             MusicNameUnsigned    = ConvertString.convertToUnSign2(music.MusicName),
             MusicView            = 0,
             UserID       = music.UserID,
             MusicRelated = music.MusicRelated
         });
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Esempio n. 6
0
        //update music
        public bool AdminUpdateMusic(MusicDTO music)
        {
            var data = new Music()
            {
                ID                   = music.ID,
                MusicDayCreate       = DateTime.Now,
                MusicName            = music.MusicName,
                MusicDownloadAllowed = music.MusicDownloadAllowed,
                SongOrMV             = music.SongOrMV,
                UserID               = music.UserID,
                CategoryId           = music.CategoryId,
                MusicImage           = music.MusicImage,
                MusicRelated         = music.MusicRelated,
                MusicNameUnsigned    = ConvertString.convertToUnSign2(music.MusicName),
            };

            try
            {
                new MusicDao().Update(data);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
        public async Task <IActionResult> UpdateMusic(int id, MusicDTO musicDTO)
        {
            if (id != musicDTO.Id)
            {
                return(BadRequest());
            }

            var music = await _context.Music.FindAsync(id);

            if (music == null)
            {
                return(NotFound());
            }

            music.Title       = musicDTO.Title;
            music.ReleaseDate = musicDTO.ReleaseDate;
            music.Genre       = musicDTO.Genre;
            music.Rating      = musicDTO.Rating;
            music.Price       = musicDTO.Price;
            music.isValid     = musicDTO.isValid;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!MusicExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
Esempio n. 8
0
        public ActionResult Create(MusicDTO music)
        {
            try
            {
                var UserId = (UserDTO)Session[CommonConstants.USER_SESSION];
                music.UserID = UserId.ID;
                //music.UserID = 31;
                if (music.FileImage != null)
                {
                    music.MusicImage = DateTime.Now.Ticks + music.MusicName + ".png";
                    music.FileImage.SaveAs(Server.MapPath(path + music.MusicImage));
                    music.FileImage = null;
                }
                else
                {
                    music.MusicImage = "default.png";
                }
                var res = ApiService.CreateMusic(music);
                if (res)
                {
                    var data = ApiService.GetAllMusic();
                    return(RedirectToAction("Index", "Music", data));
                }

                return(RedirectToAction("Create"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(RedirectToAction("Create"));
            }
        }
Esempio n. 9
0
        public async Task AddMusicToAlbum(MusicDTO musicDTO)
        {
            var album = await _context.Albums.FindAsync(musicDTO.Album.Id);

            var music = _mapper.Map <Music>(musicDTO);

            album.Music.Add(music);
        }
Esempio n. 10
0
        public async Task <IActionResult> PutMusic(int id, MusicDTO musicDTO)
        {
            /* if (id != MusicDTO.Id)
             * {
             *   return BadRequest();
             * }
             *
             * _context.Entry(music).State = EntityState.Modified;
             *
             * try
             * {
             *   await _context.SaveChangesAsync();
             * }
             * catch (DbUpdateConcurrencyException)
             * {
             *   if (!MusicExists(id))
             *   {
             *       return NotFound();
             *   }
             *   else
             *   {
             *       throw;
             *   }
             * }
             *
             * return NoContent();*/

            if (id != musicDTO.Id)
            {
                return(BadRequest());
            }

            var todoItem = await _context.Music.FindAsync(id);

            if (todoItem == null)
            {
                return(NotFound());
            }

            todoItem.Title       = musicDTO.Title;
            todoItem.Artist      = musicDTO.Artist;
            todoItem.ReleaseDate = musicDTO.ReleaseDate;
            todoItem.Genre       = musicDTO.Genre;
            todoItem.Price       = musicDTO.Price;
            todoItem.Rating      = musicDTO.Rating;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!MusicExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
Esempio n. 11
0
        public ActionResult Post([FromBody] MusicDTO musicDTO)
        {
            var music = _mapper.Map <Music>(musicDTO);

            _uof.MusicRepository.Add(music);
            _uof.Commit();
            var musicDTOReturn = _mapper.Map <MusicDTO>(music);

            return(new CreatedAtRouteResult("GetMusic", new { id = music.Id }, musicDTOReturn));
        }
Esempio n. 12
0
        public ActionResult Edit(MusicDTO music)
        {
            try
            {
                //get Image have exist
                var currentFileName = ApiService.GetMusicById(music.ID).MusicImage;
                //check name have deafault if exist ==> dont delete
                if (currentFileName == "default.png")
                {
                    //save file
                    if (music.FileImage != null)
                    {
                        music.MusicImage = DateTime.Now.Ticks.ToString() + music.MusicName + ".png";
                        music.FileImage.SaveAs(Server.MapPath(path + music.MusicImage));
                        music.FileImage = null;
                    }
                    else
                    {
                        music.MusicImage = "default.png";
                    }
                }
                else
                {
                    if (music.FileImage != null)
                    {
                        //delete file
                        var filePath = Server.MapPath(path + currentFileName);
                        if (System.IO.File.Exists(filePath))
                        {
                            System.IO.File.Delete(filePath);
                        }
                        music.MusicImage = DateTime.Now.Ticks + music.MusicName + ".png";
                        music.FileImage.SaveAs(Server.MapPath(path + music.MusicImage));
                        music.FileImage = null;
                    }
                    else
                    {
                        music.MusicImage = currentFileName;
                    }
                }

                var res = ApiService.UpdateMusic(music);
                if (res)
                {
                    return(RedirectToAction("Index", "Music"));
                }
                return(RedirectToAction("Edit"));
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return(RedirectToAction("Edit"));
            }
        }
Esempio n. 13
0
        public ActionResult Put(int Id, [FromBody] MusicDTO musicDTO)
        {
            if (Id != musicDTO.Id)
            {
                return(BadRequest());
            }
            var music = _mapper.Map <Music>(musicDTO);

            _uof.MusicRepository.Update(music);
            _uof.Commit();
            return(Ok());
        }
Esempio n. 14
0
        public List <MusicDTO> GetListMusicAll()
        {
            var list = new List <MusicDTO>();

            var dataList = new MusicDao().GetAll();

            foreach (var music in dataList)
            {
                var newMusic = new MusicDTO()
                {
                    UserID               = music.UserID,
                    MusicName            = music.MusicName,
                    MusicImage           = music.MusicImage,
                    SongOrMV             = music.SongOrMV,
                    MusicDownloadAllowed = music.MusicDownloadAllowed,
                    MusicRelated         = music.MusicRelated,
                    MusicDayCreate       = music.MusicDayCreate,
                    MusicNameUnsigned    = music.MusicNameUnsigned,
                    CategoryId           = music.CategoryId,
                    MusicView            = music.MusicView,
                    ID               = music.ID,
                    LinkImage        = baseUrl + music.MusicImage,
                    QualityMusicDTOs = new QualityMusicBus()
                                       .GetAllQM()
                                       .Where(s => s.QualityID == 1 && s.QualityID == 3)
                                       .Select(s => new QualityMusicDTO()
                    {
                        ID             = s.ID,
                        LinkFile       = s.LinkFile,
                        MusicFile      = s.MusicFile,
                        QMusicApproved = s.QMusicApproved,
                    }),
                    //need User
                    UserDto         = new UserBus().GetUserDtoById(music.UserID),
                    SingerMusicDtOs = new SingerMusicDao()
                                      .GetAll()
                                      .Where(x => x.MusicID == music.ID)
                                      .Select(x => new SingerMusicDTO()
                    {
                        ID       = x.ID,
                        MusicID  = x.MusicID,
                        SingerID = x.SingerID,
                        UserDto  = new UserBus().GetUserDtoById(x.SingerID)
                    }).ToList(),
                    CategoryDto = new CategoryBus().GetAllListCategories().SingleOrDefault(x => x.ID == music.CategoryId)
                };

                list.Add(newMusic);
            }

            return(list);
        }
Esempio n. 15
0
        public async Task <MusicDTO> UpdateMusic(MusicDTO musicToBeUpdated, SaveMusicDTO music)
        {
            var newmusic      = _mapper.Map <SaveMusicDTO, Music>(music);
            var newmusicBacis = _mapper.Map <MusicDTO, Music>(musicToBeUpdated);

            newmusicBacis.Name     = newmusic.Name;
            newmusicBacis.ArtistId = newmusic.ArtistId;
            await uow.CommitAsync();

            var updatedMusic = await GetMusicById(newmusic.Id);

            return(updatedMusic);
        }
Esempio n. 16
0
        public async Task <ActionResult <Music> > Post([FromBody] MusicDTO model)
        {
            Music music = _mapper.Map <Music>(model);

            Music response = await _musicService.InsertMusicAsync(music);

            if (response == null)
            {
                return(NotFound());
            }

            return(CreatedAtAction(nameof(Get), new { id = response.Id }, response));
        }
Esempio n. 17
0
        public IHttpActionResult Post(MusicDTO s)
        {
            var item = new Music {
                CategoryId = s.CategoryId, ID = s.ID, MusicDayCreate = s.MusicDayCreate, MusicDownloadAllowed = s.MusicDownloadAllowed, MusicImage = s.MusicImage, MusicName = s.MusicName, MusicNameUnsigned = s.MusicNameUnsigned, MusicRelated = s.MusicRelated, SongOrMV = s.SongOrMV, UserID = s.UserID, MusicView = s.MusicView
            };
            var res = new Repositories().CreateMusic(item);

            if (res > 0)
            {
                return(Ok(res));
            }
            return(InternalServerError());
        }
Esempio n. 18
0
        public async Task <OperationDetails> Delete(MusicDTO musicDTO)
        {
            var music = Database.MusicManager.Get(musicDTO.Id);

            if (music != null)
            {
                Database.MusicManager.Delete(music.Id);
                await Database.SaveAsync();

                return(new OperationDetails(true, "Music deleted successfully", ""));
            }
            return(new OperationDetails(false, "Music is not exist", "Name"));
        }
Esempio n. 19
0
        // POST: api/Music
        public IHttpActionResult Post([FromBody] MusicDTO music)
        {
            var httpContext = HttpContext.Current;

            try
            {
                new Repositories().CreateMusic(music);
                return(Ok());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(InternalServerError());
            }
        }
Esempio n. 20
0
        public IActionResult GetPage(int page)
        {
            try
            {
                if (page < 1)
                {
                    throw new DataException("Page Number must be at least 1 (" + where + ") (GETPAGE)");
                }
                int       jump, records, maxpages = 1;
                Code_Mstr cdm = S.ServiceLocator.Instance.CodeMstrService.Get(new Code_Mstr("CONFIGURATION", "JUMP_MUSIC", ""));
                if (cdm is null)
                {
                    jump = 50;
                }
                else if (!int.TryParse(cdm.Code_Desc, out jump))
                {
                    jump = 50;
                }

                records = S.ServiceLocator.Instance.GeneralTypeService.IsUsed(1);
                IEnumerable <SM.Music> mus = null;
                if (records > 0)
                {
                    if (records > jump)
                    {
                        maxpages = records / jump;
                        if (records % jump > 0)
                        {
                            maxpages += 1;
                        }
                    }

                    // int pages = S.ServiceLocator.Instance.MusicService.GetPageCount(jump);
                    if (page <= maxpages)
                    {
                        mus = S.ServiceLocator.Instance.MusicService.GetPage(page, jump);
                    }
                    if (mus != null && mus.OfType <SM.Music>().Count() == 0)
                    {
                        mus = null;
                    }
                }

                MusicDTO mdto = new MusicDTO(records, maxpages, page, jump, mus);
                return(ApiControllerHelper.SendOk(this, new ApiResult <MusicDTO>(HttpStatusCode.OK, null, mdto), true));
            }
            catch (Exception ex) { return(ApiControllerHelper.SendError(this, ex)); }
        }
Esempio n. 21
0
        public async Task <string> Update(MusicDTO musicDTO)
        {
            try
            {
                await musicBLL.UpdateAsync(musicDTO);

                return(JsonConvert.SerializeObject(new ResponseClassDTO()
                {
                    State = "success", Message = ""
                }));
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(new ResponseClassDTO()
                {
                    State = "fail", Message = ex.Message
                }));
            }
        }
Esempio n. 22
0
        public async Task <string> Add(MusicDTO musicDTO)
        {
            try
            {
                musicDTO.CreateTime = DateTime.Now;
                musicDTO.IsDeleted  = false;
                await musicBLL.AddAsync(musicDTO);

                return(JsonConvert.SerializeObject(new ResponseClassDTO()
                {
                    State = "success"
                }));
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(new ResponseClassDTO()
                {
                    State = "fail", Message = ex.Message
                }));
            }
        }
Esempio n. 23
0
        //select by name

        public List <MusicDTO> SearchMusic(string namekey)
        {
            var list     = new List <MusicDTO>();
            var dataList = new MusicDao()
                           .GetAll()
                           .Where(x => x.MusicName == namekey || x.MusicNameUnsigned == namekey)
                           .ToList();

            foreach (var music in dataList)
            {
                var newMusic = new MusicDTO()
                {
                    UserID               = music.UserID,
                    MusicName            = music.MusicName,
                    MusicImage           = music.MusicImage,
                    SongOrMV             = music.SongOrMV,
                    MusicDownloadAllowed = music.MusicDownloadAllowed,
                    MusicRelated         = music.MusicRelated,
                    MusicDayCreate       = music.MusicDayCreate,
                    MusicNameUnsigned    = music.MusicNameUnsigned,
                    MusicView            = music.MusicView,
                    ID = music.ID,
                    //need User
                    SingerMusicDtOs = new SingerMusicDao()
                                      .GetAll()
                                      .Where(x => x.MusicID == music.ID)
                                      .Select(x => new SingerMusicDTO()
                    {
                        ID       = x.ID,
                        MusicID  = x.MusicID,
                        SingerID = x.SingerID,
                        UserDto  = new UserBus().GetUserDtoById(x.SingerID)
                    }).ToList(),
                    UserDto = new UserBus().GetUserDtoById(music.UserID),
                };
                list.Add(newMusic);
            }

            return(list);
        }
Esempio n. 24
0
        public async Task <OperationDetails> Update(MusicDTO musicDTO)
        {
            var music = Database.MusicManager.Get(musicDTO.Id);

            if (music != null)
            {
                music = new Music
                {
                    Id       = musicDTO.Id,
                    Name     = musicDTO.Name,
                    Path     = musicDTO.Path,
                    GenreId  = musicDTO.GenreId,
                    SingerId = musicDTO.SingerId,
                    UserId   = musicDTO.UserId
                };
                Database.MusicManager.Update(music);
                await Database.SaveAsync();

                return(new OperationDetails(true, "Music update successfully", ""));
            }
            return(new OperationDetails(false, "Music is not exist", "Name"));
        }
Esempio n. 25
0
        public async Task <IActionResult> PutMusic(int id, MusicDTO musicDTO)
        {
            if (id != musicDTO.Id)
            {
                return(BadRequest());
            }

            var music = await _context.Music.FindAsync(id);

            if (music == null)
            {
                return(NotFound());
            }

            music.Title       = musicDTO.Title;
            music.Artist      = musicDTO.Artist;
            music.ReleaseDate = musicDTO.ReleaseDate;
            music.Genre       = musicDTO.Genre;
            music.Price       = musicDTO.Price;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MusicExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 26
0
        public async Task <OperationDetails> Create(MusicDTO musicDTO)
        {
            var musics = Database.MusicManager.GetAll().ToList();
            var music  = musics.Find(x => x.Name == musicDTO.Name);

            if (music == null && musicDTO.Name != null && musicDTO.UserId != null)
            {
                music = new Music
                {
                    Id       = Guid.NewGuid().ToString(),
                    Name     = musicDTO.Name,
                    Path     = musicDTO.Path,
                    GenreId  = musicDTO.GenreId,
                    SingerId = musicDTO.SingerId,
                    UserId   = musicDTO.UserId
                };
                Database.MusicManager.Create(music);
                await Database.SaveAsync();

                return(new OperationDetails(true, "Music added successfully", ""));
            }
            return(new OperationDetails(false, "Music is exist or empty", "Name"));
        }
Esempio n. 27
0
 public bool UpdateMusic(MusicDTO music)
 {
     return(new MusicBus().AdminUpdateMusic(music));
 }
Esempio n. 28
0
 public static Note ToNoteObject(MusicDTO.Note musicNote)
 {
     return new Note(
         new NotePosition(musicNote.LPB, musicNote.num, musicNote.block),
         musicNote.type == 1 ? NoteTypes.Single : NoteTypes.Long);
 }
Esempio n. 29
0
 private async void updateList()
 {
     dataGridView1.DataSource = await MusicDTO.GetMusicsAsync();
 }
Esempio n. 30
0
 // PUT: api/Music/5
 public void Put(int id, [FromBody] MusicDTO music)
 {
     new Repositories().UpdateMusic(music);
 }
Esempio n. 31
0
        public ActionResult CreateMusicUser(MusicDTO m, HttpPostedFileBase fileMusic, HttpPostedFileBase imgMusic)
        {
            //Session["singer"] = ApiService.GetAllSinger();
            var user = (UserDTO)Session[CommonConstants.USER_SESSION];

            if (Session["singer"] != null)
            {
                List <int> arrSinger = new List <int>();
                var        list      = Session["singer"] as List <int>;
                arrSinger              = list;
                m.MusicNameUnsigned    = RemoveUnicode.RemoveSign4VietnameseString(m.MusicName);
                m.MusicDownloadAllowed = true;
                m.MusicView            = 0;
                m.UserID = user.ID;
                //img music
                if (imgMusic == null)
                {
                    m.MusicImage = "default.png";
                }
                else
                {
                    try
                    {
                        string FileNameMusic = DateTime.Now.Ticks + ".png";
                        imgMusic.SaveAs(Server.MapPath("~/File/ImageMusic/" + FileNameMusic));
                        m.MusicImage = FileNameMusic;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
                //quality music
                QualityMusicDTO quality = new QualityMusicDTO()
                {
                    NewFile        = true,
                    QMusicApproved = false
                };
                string FileName = DateTime.Now.Ticks + Path.GetFileName(fileMusic.FileName);
                string path;
                if (FileName.EndsWith("mp3"))
                {
                    quality.QualityID = 1; //file normal of song
                    m.SongOrMV        = true;
                    path = Path.Combine(Server.MapPath("~/File/mp3-mp4/"), FileName);
                }
                else
                {
                    quality.QualityID = 3; //file mormal of mv
                    m.SongOrMV        = false;
                    path = Path.Combine(Server.MapPath("~/File/mp3-mp4/"), FileName);
                }
                fileMusic.SaveAs(path);
                quality.MusicFile = FileName;
                // music
                int idMusic = ApiService.CreateMusicUpload(m);
                if (idMusic > 0)
                {
                    quality.MusicID = idMusic;
                    var dataQM = ApiService.CreateQualityMusic(quality);
                    if (dataQM != null)
                    {
                        //singer
                        foreach (var number in arrSinger)
                        {
                            ApiService.AddSingerToMusic(new SingerMusicDTO()
                            {
                                MusicID  = idMusic,
                                SingerID = number
                            });
                        }
                        SetAlert("Update success!", "success");
                        TempData["success"] = "Upload file thành công";
                    }
                }
            }
            else
            {
                SetAlert("Update fail!", "warning");
                TempData["error"] = "Upload file xảy ra lỗi";
            }
            Session.Remove("singer");
            return(RedirectToAction("UploadFile"));
        }