Пример #1
0
        public async Task<ActionResult> View(int ChannelID)
        {
            this.LoginCheck("Channel");

            Favorite favo = new Favorite();
            Channel channel = new Channel();
            List<Music> list = new List<Music>();
            using (var context = new SharedPlayerContext())
            {
                channel = await context.Channels.Where(x => x.ChannelID == ChannelID).FirstOrDefaultAsync().ConfigureAwait(false) ?? new Channel();
                list = await context.Musics.Where(x => x.ChannelID == ChannelID).OrderBy(x => x.Seq).ToListAsync().ConfigureAwait(false) ?? new List<Music>();
                favo = await context.Favorites.Where(x => x.ChannelID == ChannelID).Where(x => x.MemberID == this.LoginMember.MemberID).FirstOrDefaultAsync().ConfigureAwait(false) ?? new Favorite();
            }
;
            ViewBag.channel = channel;
            ViewBag.list = list;
            ViewBag.favo = favo;

            return View(this);
        }
Пример #2
0
        public JsonResult AddFavorite(int ChannelID)
        {
            ReturnResult result = new ReturnResult();

            this.LoginCheck();

            using (var context = new SharedPlayerContext())
            {
                Channel channel = context.Channels.Where(x => x.ChannelID == ChannelID).FirstOrDefault();
                if (channel != null && channel.ChannelID > 0)
                {
                    Favorite favo = context.Favorites.Where(x => x.MemberID == this.LoginMember.MemberID).Where(x => x.ChannelID == ChannelID).FirstOrDefault();

                    if (favo != null && favo.FavoriteID > 0)
                    {
                        result.Fail("이미 있습니다.");
                    }
                    else
                    {
                        favo = new Favorite();
                        favo.ChannelID = ChannelID;
                        favo.MemberID = this.LoginMember.MemberID;
                        context.Favorites.Add(favo);
                        context.SaveChanges();
                        result.Success();
                    }
                }
                else
                {
                    result.Fail("대상을 찾을 수 없습니다.");
                }
            }

            return Json(result);
        }