Пример #1
0
        private async void btnAddWatchList_Click(object sender, RoutedEventArgs e)
        {
            if (grdData.SelectedItems.Count == 0)
            {
                await this.ShowMessageAsync("오류", $"즐겨찾기에 추가할 영화를 선택하세요.",
                                            MessageDialogStyle.Affirmative, null);

                return;
            }

            // grdData.SelectedItem : MovieItem -> FavoriteMovies (Entity Framework) 로 클래스 변경
            List <FavoriteMovies> movies = new List <FavoriteMovies>();

            foreach (MovieItem item in grdData.SelectedItems)
            {
                FavoriteMovies temp = new FavoriteMovies()
                {
                    Title      = item.Title,
                    Link       = item.Link,
                    Image      = item.Image,
                    SubTitle   = item.SubTitle,
                    PubDate    = item.PubDate,
                    Director   = item.Director,
                    Actor      = item.Actor,
                    UserRating = item.UserRating,
                    RegDate    = DateTime.Now
                };
                movies.Add(temp);
            }

            using (var ctx = new OpenApiLabEntities())
            {
                try
                {
                    ctx.Set <FavoriteMovies>().AddRange(movies);
                    ctx.SaveChanges();
                    stsResult.Content = $"즐겨찾기 {movies.Count}건 추가 완료.";
                    await this.ShowMessageAsync("저장 성공", $"영화 {movies.Count}개를 즐겨찾기에 추가했습니다",
                                                MessageDialogStyle.Affirmative, null);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.InnerException.HResult == -2146232060)
                    {
                        await this.ShowMessageAsync("오류", $"이미 즐겨찾기에 있는 영화가 포함되어 있습니다.",
                                                    MessageDialogStyle.Affirmative, null);
                    }
                    else
                    {
                        await this.ShowMessageAsync("오류", $"예외 발생 : {ex.Message}",
                                                    MessageDialogStyle.Affirmative, null);

                        common.LOGGER.Error($"예외 발생 : {ex}");
                    }
                }
            }
        }
        private void BtnAddWatchList_Click(object sender, RoutedEventArgs e)
        {
            if (GrdData.SelectedItems.Count == 0)
            {
                Commons.showMessageAsync("오류", "즐겨찾기에 추가할 영화를 선택하세요(복수선택 가능)");
                return;
            }

            if (Commons.IsFavorite == true)
            {
                //이미 즐겨찾기한 내용을 막아주기 위한 것
                Commons.showMessageAsync("즐겨찾기", "즐겨찾기 조회내용을 다시 즐겨찾기 할 수 없습니다");
                return;
            }



            List <NaverFavoriteMovies> list = new List <NaverFavoriteMovies>();

            foreach (MovieItem item in GrdData.SelectedItems)
            {
                NaverFavoriteMovies temp = new NaverFavoriteMovies()
                {
                    Title      = item.Title,
                    Link       = item.Link,
                    Image      = item.Image,
                    SubTitle   = item.SubTitle,
                    PubDate    = item.PubDate,
                    Director   = item.Director,
                    Actor      = item.Actor,
                    UserRating = item.UserRating,
                    RegDate    = DateTime.Now
                };

                list.Add(temp);
            }


            try
            {
                using (var ctx = new OpenApiLabEntities())
                {
                    //ctx.NaverFavoriteMovies.AddRange(list); 아래와 차이없음
                    ctx.Set <NaverFavoriteMovies>().AddRange(list);
                    ctx.SaveChanges();
                }


                Commons.showMessageAsync("저장", $"즐겨찾기 추가");
            }
            catch (Exception ex)
            {
                Commons.showMessageAsync("예외", $"예외발생 : {ex}");
                Commons.LOGGER.Error($"예외발생 : {ex}");
            }
        }
        private void BtnAddWatchList_Click(object sender, RoutedEventArgs e)
        {
            if (GrdData.SelectedItems.Count == 0)
            {
                Commons.ShowMessageAsync("오류", "즐겨찾기에 추가할 영화를 선택하세요(복수선택 가능)");
                return;
            }

            if (Commons.IsFavorite)
            {
                Commons.ShowMessageAsync("즐겨찾기", "즐겨찾기 조회내용을 다시 즐겨찾기 할 수 없습니다.");
                return;
            }


            List <NaverFavoriteMovies> favoriteMovies = new List <NaverFavoriteMovies>();

            foreach (MovieItem item in GrdData.SelectedItems)
            {
                NaverFavoriteMovies temp = new NaverFavoriteMovies()
                {
                    Title      = item.Title,
                    Link       = item.Link,
                    Image      = item.Image,
                    SubTitle   = item.SubTitle,
                    PubDate    = item.PubDate,
                    Director   = item.Director,
                    Actor      = item.Actor,
                    UserRating = item.UserRating,
                    RegDate    = DateTime.Now
                };

                favoriteMovies.Add(temp);
            }

            try
            {
                using (var ctx = new OpenApiLabEntities())
                {
                    // AddRange
                    //     Adds the given collection of entities into context underlying the set with each
                    //     entity being put into the Added state such that it will be inserted into the
                    //     database when SaveChanges is called.
                    ctx.Set <NaverFavoriteMovies>().AddRange(favoriteMovies);
                    ctx.SaveChanges();
                }

                Commons.ShowMessageAsync("저장", "즐겨찾기에 추가했습니다.");
            }
            catch (Exception ex)
            {
                Commons.ShowMessageAsync("예외", $"예외발생 : {ex}");
                Commons.LOGGER.Error($"예외발생 : {ex}");
            }
        }
        private void BtnAddWatchList_Click(object sender, RoutedEventArgs e)
        {
            // Debug.WriteLine("Test"); //selecteItem 과 seletedItems 중 어떤 걸 넣을지에 대한 디버깅

            if (GrdData.SelectedItems.Count == 0)
            {
                Commons.ShowMessageAsync("오류", "즐겨찾기에 추가 할 영화를 선택하세요 (복수선택가능)");
                return;
            }

            if (Commons.IsFavorite)
            {
                Commons.ShowMessageAsync("즐겨찾기", "즐겨찾기 조회내용을 다시 즐겨찾기할 수 없습니다");
                return;
            }

            List <NaverFavoriteMovies> list = new List <NaverFavoriteMovies>();

            foreach (MovieItem item in GrdData.SelectedItems)
            {
                NaverFavoriteMovies temp = new NaverFavoriteMovies()
                {
                    // item 있는 값을 temp로 옮겨줌 Q1. 왜 옮겨 주는가?
                    // AS: 다른 메서드에서 데이터 불러오기 때문
                    Title      = item.Title,
                    Link       = item.Link,
                    Image      = item.Image,
                    SubTitle   = item.SubTitle,
                    PubDate    = item.PubDate,
                    Director   = item.Director,
                    Actor      = item.Actor,
                    UserRating = item.UserRating,
                    RegDate    = DateTime.Now
                };
                list.Add(temp);
            }

            //데이터베이스에 가서 메서드 생성한 것 뿐. 어렵지 않음
            try
            {
                using (var ctx = new OpenApiLabEntities())
                {
                    ctx.Set <NaverFavoriteMovies>().AddRange(list);
                    ctx.SaveChanges();
                }
                Commons.ShowMessageAsync("저장", "즐겨찾기 추가 완료");
            }
            catch (Exception ex)
            {
                Commons.ShowMessageAsync("예외", $"예외발생 : {ex}");
                Commons.LOGGER.Error($"예외발생 : {ex}");
            }
        }
Пример #5
0
        private void BtnAddWatchList_Click(object sender, RoutedEventArgs e)
        {
            if (GrdData.SelectedItems.Count == 0)
            {
                Commons.ShowMessageAsync("오류", "즐겨찾기에 추가할 영화를 선택하세요(복수선택 가능)");
                return;
            }

            if (Commons.IsFavorite == true)
            {
                Commons.ShowMessageAsync("즐겨찾기", "즐겨찾기 조회내용을 다시 즐겨찾기할 수 없습니다.");
                return;
            }

            List <NaverFavoriteMovies> list = new List <NaverFavoriteMovies>();

            foreach (MovieItem item in GrdData.SelectedItems)
            {
                NaverFavoriteMovies temp = new NaverFavoriteMovies()
                {
                    Title      = item.Title,
                    Link       = item.Link,
                    Image      = item.Image,
                    SubTitle   = item.SubTitle,
                    PubDate    = item.PubDate,
                    Director   = item.Director,
                    Actor      = item.Actor,
                    UserRating = item.UserRating,
                    RegDate    = DateTime.Now
                };

                list.Add(temp);
            }

            try
            {
                using (var ctx = new OpenApiLabEntities())
                {
                    //ctx.NaverFavoriteMovies.Add(list); 아래코드와동일
                    ctx.Set <NaverFavoriteMovies>().AddRange(list);
                    ctx.SaveChanges();
                }
                Commons.ShowMessageAsync("저장", "즐겨찾기에 추가했습니다");
            }
            catch (Exception ex)
            {
                Commons.ShowMessageAsync("오류", $"오류내용 : {ex}");
                Commons.LOGGER.Error($"예외발생 : {ex}");
            }
            //GrdData.SelectedItem = null;
            ImgPoster.Source = new BitmapImage(new Uri("No_Image.jpg", UriKind.RelativeOrAbsolute));
        }