예제 #1
0
        // DELETE api/PlaylistDetail/5
        public HttpResponseMessage DeletePlaylistDetail(int id)
        {
            PlaylistDetail PlaylistDetail = db.PlaylistDetails.Where(gw => gw.ID == id).FirstOrDefault();
            Playlist       playlist       = db.Playlists.Single(pl => pl.ID == PlaylistDetail.PlaylistID);

            if (PlaylistDetail == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            List <PlaylistDetail> lpld = new List <PlaylistDetail>();

            lpld.AddRange(db.PlaylistDetails.Where(le => le.PlaylistID == PlaylistDetail.PlaylistID && le.ID != id).OrderBy(ob => ob.SortOrder).ToList());

            for (int i = 0; i < lpld.Count; i++)
            {
                lpld[i].SortOrder = i + 1;
            }
            db.SaveChanges();

            db.PlaylistDetails.DeleteObject(PlaylistDetail);

            try
            {
                db.SaveChanges();

                Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(Playlist), Utilities.Action_Flag.DELETION, playlist.ID.ToString(), playlist.Name, "Deleted Group/Game from Playlist \"" + playlist.Name + "\"", true);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, PlaylistDetail));
        }
예제 #2
0
        public async Task <OperationResponse <PlaylistDetail> > UpdateAsync(PlaylistDetail model)
        {
            var playlist = await _unitOfWork.Playlists.GetByIdAsync(model.Id);

            if (playlist == null)
            {
                return new OperationResponse <PlaylistDetail>
                       {
                           IsSuccess = false,
                           Data      = null,
                           Message   = "Playlist not found"
                       }
            }
            ;

            playlist.Name        = model.Name;
            playlist.Description = model.Description;

            await _unitOfWork.CommitChangesAsync(_identity.UserID);

            return(new OperationResponse <PlaylistDetail>
            {
                IsSuccess = true,
                Message = "Playlist has been updated",
                Data = model
            });
        }
예제 #3
0
        // PUT api/PlaylistDetail/5
        public HttpResponseMessage PutPlaylistDetail(int id, PlaylistDetail PlaylistDetail)
        {
            if (ModelState.IsValid && id == PlaylistDetail.ID)
            {
                PlaylistDetail.SDMLeagueCode = db.PlaylistDetails.Where(p => p.ID == id).Select(p => p.SDMLeagueCode).FirstOrDefault();
                //db.Entry(PlaylistDetail).State = EntityState.Modified;
                db.PlaylistDetails.Attach(PlaylistDetail);
                db.ObjectStateManager.ChangeObjectState(PlaylistDetail, EntityState.Modified);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
예제 #4
0
        public async Task <IActionResult> Update(PlaylistDetail model)
        {
            var result = await _playlistsService.UpdateAsync(model);

            if (result.IsSuccess)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
        public async Task <IActionResult> GetPlaylistById(int playlistId)
        {
            PlaylistDetail playlist = await _mediator.Send(new GetPlaylistQuery(playlistId));

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

            return(Ok(playlist));
        }
예제 #6
0
        public async Task <IActionResult> InsertSongToPlaylist(int IdPlaylist, List <int> IdSong)
        {
            var playlistExist = _context.Playlist.Find(IdPlaylist);

            if (playlistExist != null)
            {
                foreach (var item in IdSong)
                {
                    PlaylistDetail playlistDetail = new PlaylistDetail();
                    playlistDetail.IdPlaylist = IdPlaylist;
                    playlistDetail.IdSong     = item;
                    _context.Add(playlistDetail);
                    await _context.SaveChangesAsync();
                }
            }
            var DetailPlaylist = _context.PlaylistDetail.Where(m => m.IdPlaylist == IdPlaylist).ToList();
            List <SongModel> SongFromPlaylist = new List <SongModel>();

            foreach (var item in DetailPlaylist)
            {
                SongModel songModel = new SongModel();
                songModel = _context.Song.Find(item.IdSong);
                //var singer = _context.Singer.Find(songModel.IdSinger);
                //songModel.Singer = singer;
                SongFromPlaylist.Add(songModel);
            }
            return(RedirectToAction("DetailPlaylist", "Playlist", new { area = "Admin", id = IdPlaylist }));

            //return PartialView("_GetSongFromPlaylist", SongFromPlaylist);

            #region Logic cũ
            //foreach (var item in IdSong)
            //{
            //    var PlaylistDetailExist = _context.PlaylistDetail.Where(m => m.IdSong == item).ToList();
            //      if (PlaylistDetailExist.Count == 0)
            //    {
            //        PlaylistDetail playlistDetail = new PlaylistDetail();
            //        playlistDetail.IdPlaylist = IdPlaylist;
            //        playlistDetail.IdSong = item;
            //        _context.Add(playlistDetail);
            //        await _context.SaveChangesAsync();
            //    }
            //}
            #endregion
        }
예제 #7
0
        public HttpResponseMessage PutPlaylistDetail(int id, int SortOrder) //new sort order
        {
            PlaylistDetail PlaylistDetail = db.PlaylistDetails.Where(le => le.ID == id).Single();
            Playlist       playlist       = db.Playlists.Single(pl => pl.ID == PlaylistDetail.PlaylistID);

            int newRank = SortOrder;
            int?oldRank = PlaylistDetail.SortOrder;

            if (newRank > oldRank)
            {
                newRank++;
            }

            List <PlaylistDetail> lpld = new List <PlaylistDetail>();

            lpld.AddRange(db.PlaylistDetails.Where(le => le.PlaylistID == PlaylistDetail.PlaylistID && le.SortOrder < newRank && le.ID != id).OrderBy(ob => ob.SortOrder).ToList());
            lpld.Add(db.PlaylistDetails.Where(le => le.ID == id).Single());
            foreach (PlaylistDetail l in db.PlaylistDetails.Where(le => le.PlaylistID == PlaylistDetail.PlaylistID).OrderBy(ob => ob.SortOrder))
            {
                if (lpld.Where(le => le.ID == l.ID).Count() == 0)
                {
                    lpld.Add(l);
                }
            }

            for (int i = 0; i < lpld.Count; i++)
            {
                lpld[i].SortOrder = i + 1;
            }

            try
            {
                db.SaveChanges();

                Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(Playlist), Utilities.Action_Flag.CHANGE, playlist.ID.ToString(), playlist.Name, "Updated Game/Group Order in Playlist \"" + playlist.Name + "\"", true);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #8
0
        // POST api/PlaylistDetail
        public HttpResponseMessage PostPlaylistDetail(PlaylistDetail PlaylistDetail)
        {
            if (ModelState.IsValid)
            {
                db.PlaylistDetails.AddObject(PlaylistDetail);
                db.SaveChanges();

                var correctedResponse        = new { Data = new[] { PlaylistDetail } };
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, correctedResponse);

                //HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, PlaylistDetail);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = PlaylistDetail.ID }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
예제 #9
0
        public async Task <OperationResponse <PlaylistDetail> > CreateAsync(PlaylistDetail model)
        {
            var playlist = new Playlist
            {
                Name        = model.Name,
                Description = model.Description
            };

            await _unitOfWork.Playlists.CreateAsync(playlist);

            await _unitOfWork.CommitChangesAsync(_identity.UserID);

            model.Id = playlist.Id;

            return(new OperationResponse <PlaylistDetail>
            {
                IsSuccess = true,
                Message = "Playlist created",
                Data = model
            });
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("Name")] Playlist model, List <int> idSong, IFormFile ful)
        {
            if (ModelState.IsValid)
            {
                if (idSong.Count != 0)
                {
                    //Add Master để lấy id
                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    if (ful != null)
                    {
                        var path = Path.Combine(
                            Directory.GetCurrentDirectory(), "wwwroot/img/playlist", model.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]);
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await ful.CopyToAsync(stream);
                        }
                        model.Image = model.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                        _context.Update(model);
                        await _context.SaveChangesAsync();
                    }

                    //Lưu tất cả bài hát đã chọn vào playlistDetail
                    foreach (var item in idSong)
                    {
                        PlaylistDetail playlistDetail = new PlaylistDetail();
                        playlistDetail.IdPlaylist = model.Id;
                        playlistDetail.IdSong     = item;
                        _context.Add(playlistDetail);
                        await _context.SaveChangesAsync();
                    }

                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["IdSong"] = new SelectList(_context.Song, "Id", "Name");
            return(View("CreatePlaylist"));
        }
예제 #11
0
        public HttpResponseMessage PutPlaylistDetail(int id, byte?RipCount, byte?NotesTypeID)   //new rip info
        {
            PlaylistDetail PlaylistDetail = db.PlaylistDetails.Where(le => le.ID == id).Single();
            Playlist       playlist       = db.Playlists.Single(pl => pl.ID == PlaylistDetail.PlaylistID);


            PlaylistDetail.RipCount    = RipCount;
            PlaylistDetail.NotesTypeID = NotesTypeID;

            try
            {
                db.SaveChanges();

                Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(Playlist), Utilities.Action_Flag.CHANGE, playlist.ID.ToString(), playlist.Name, "Updated Game/Group Rip in Playlist \"" + playlist.Name + "\"", true);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #12
0
        // PUT api/PlaylistDetail/5
        public HttpResponseMessage PutPlaylistDetail(int id, PlaylistDetail PlaylistDetail)
        {
            if (ModelState.IsValid && id == PlaylistDetail.ID)
            {
                //db.Entry(PlaylistDetail).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
예제 #13
0
        // DELETE api/PlaylistDetail/5
        public HttpResponseMessage DeletePlaylistDetail(int id)
        {
            PlaylistDetail PlaylistDetail = db.PlaylistDetails.Where(gw => gw.ID == id).FirstOrDefault();

            if (PlaylistDetail == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.PlaylistDetails.DeleteObject(PlaylistDetail);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, PlaylistDetail));
        }
예제 #14
0
        // POST api/PlaylistDetail
        public HttpResponseMessage PostPlaylistDetail(PlaylistDetail PlaylistDetail)
        {
            Playlist playlist = db.Playlists.Single(pl => pl.ID == PlaylistDetail.PlaylistID);

            if (ModelState.IsValid)
            {
                if (PlaylistDetail.HiveID != null)
                {
                    if (PlaylistDetail.HiveID != "undefined")
                    {
                        //PlaylistDetail.EntryID = db.Sports.Single(s => s.HivePrefix == PlaylistDetail.OnAirName).ID;
                    }
                    //if (PlaylistDetail.HiveID == "undefined")
                    else
                    {
                        PlaylistDetail.HiveID = null;
                    }
                }


                db.PlaylistDetails.AddObject(PlaylistDetail);
                db.SaveChanges();

                int?newRank = PlaylistDetail.SortOrder;
                //int? oldRank;

                //if (newRank > oldRank) newRank++;

                List <PlaylistDetail> lpld = new List <PlaylistDetail>();
                lpld.AddRange(db.PlaylistDetails.Where(le => le.PlaylistID == PlaylistDetail.PlaylistID && le.SortOrder < newRank && le.ID != PlaylistDetail.ID).OrderBy(ob => ob.SortOrder).ToList());

                //if (lpld.Count != newRank )
                //{
                lpld.Add(db.PlaylistDetails.Where(le => le.ID == PlaylistDetail.ID).Single());
                foreach (PlaylistDetail l in db.PlaylistDetails.Where(le => le.PlaylistID == PlaylistDetail.PlaylistID).OrderBy(ob => ob.SortOrder))
                {
                    if (lpld.Where(le => le.ID == l.ID).Count() == 0)
                    {
                        lpld.Add(l);
                    }
                }

                for (int i = 0; i < lpld.Count; i++)
                {
                    lpld[i].SortOrder = i + 1;
                }
                db.SaveChanges();
                //}

                var correctedResponse        = new { Data = new[] { PlaylistDetail } };
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, correctedResponse);

                //HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, PlaylistDetail);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = PlaylistDetail.ID }));

                Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(Playlist), Utilities.Action_Flag.ADDITION, playlist.ID.ToString(), playlist.Name, "Added Game/Group to Playlist \"" + playlist.Name + "\"", true);
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }