예제 #1
0
        /// <summary>
        /// Removing author from the static list on button click
        /// </summary>
        /// <param name="sender">The source of the event</param>
        /// <param name="e">The instance containing the event data</param>
        private void RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            if (Authors.AuthorsList.Count < 1)
            {
                MessageBox.Show("No authors to remove.");
                return;
            }

            AuthorDetailViewModel viewmodel = (AuthorDetailViewModel)DataContext;
            Author author = Authors.GetAuthor(viewmodel.MyAuthor.AuthorId);

            if (author.BooksList.Count > 0)
            {
                MessageBox.Show("Author cannot be removed. Associated books must be removed first.");
            }
            else if (MessageBox.Show("Are you sure you want to remove the author?", "Remove author", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                Authors.RemoveAuthor(author.AuthorId);
                Authors.AreRemovedItems = true;
                var mw = Application.Current.Windows
                         .Cast <Window>()
                         .FirstOrDefault(window => window is MainWindow) as MainWindow;

                mw.DataContext = new
                {
                    collection = new AuthorsListViewModel(),
                    detail     = new AuthorDetailViewModel(Authors.GetAuthor(Authors.AuthorsList.Count))
                };
            }
        }
예제 #2
0
        /// <summary>
        /// Setting author to be updated, if user has clicked the input field
        /// </summary>
        /// <param name="sender">The source of the event</param>
        /// <param name="e">The instance containing the event data</param>
        private void txtBox_GotFocus(object sender, RoutedEventArgs e)
        {
            AuthorDetailViewModel viewmodel = (AuthorDetailViewModel)DataContext;
            Author author = viewmodel.MyAuthor;

            author.IsUpdated  = true;
            Authors.IsUpdated = true;
        }
예제 #3
0
 /// <summary>
 /// Checking that the author's last name is not empty
 /// </summary>
 /// <param name="sender">The source of the event</param>
 /// <param name="e">The instance containing the event data</param>
 private void TxtLastName_LostFocus(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(txtLastName.Text))
     {
         MessageBox.Show("Field cannot be empty!");
         AuthorDetailViewModel viewmodel = (AuthorDetailViewModel)DataContext;
         Author author = viewmodel.MyAuthor;
         txtLastName.Text = author.LastName;
     }
 }
예제 #4
0
 /// <summary>
 /// View the information about the individual Author
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public async Task <IActionResult> Details(int?id)
 {
     if (id.HasValue)
     {
         return(View(await AuthorDetailViewModel.FromIDAsync(id.Value, _context)));
     }
     else
     {
         return(RedirectToAction("Index"));
     }
 }
        public AuthorDetailViewModelTests()
        {
            eventAggregatorMock              = new Mock <IEventAggregator>();
            metroDialogServiceMock           = new Mock <IMetroDialogService>();
            authorsRepoMock                  = new Mock <IRepository <Author> >();
            nationalityLookupDataServiceMock = new Mock <INationalityLookupDataService>();

            viewModel = new AuthorDetailViewModel(eventAggregatorMock.Object,
                                                  metroDialogServiceMock.Object,
                                                  authorsRepoMock.Object,
                                                  nationalityLookupDataServiceMock.Object);
        }
예제 #6
0
 /// <summary>
 /// Checking if the input in author's year's field is valid
 /// </summary>
 /// <param name="sender">The source of the event</param>
 /// <param name="e">The instance containing the event data</param>
 private void TxtYear_LostFocus(object sender, RoutedEventArgs e)
 {
     if (int.TryParse(txtYear.Text, out int year))
     {
         if (year < 1 || year > 2050)
         {
             MessageBox.Show("Year field not valid.");
             AuthorDetailViewModel viewmodel = (AuthorDetailViewModel)DataContext;
             Author author = viewmodel.MyAuthor;
             txtYear.Text = author.YearBirth.ToString();
         }
     }
 }
예제 #7
0
        public async Task <ActionResult <AuthorEntity> > Update(Guid id, AuthorDetailViewModel author)
        {
            author.Id = id;
            dynamic updating = await _updateService.Update(author);

            if (updating.status == true)
            {
                return(Ok(_helpers.SuccessResponse(updating.message, updating.data)));
            }
            else
            {
                return(StatusCode(500, _helpers.ErrorResponse("Error To create", new string[] { updating.message })));
            }
        }
        public AuthorDetailViewModelTests()
        {
            var repoMock      = new Mock <IRepository <Author> >();
            var natMock       = new Mock <INationalityLookupDataService>();
            var authorService = new AuthorService(repoMock.Object, natMock.Object);
            var dialogService = new DialogService();

            var eventAggregatorMock = new Mock <IEventAggregator>();
            var loggerMock          = new Mock <ILogger>();

            viewModel = new AuthorDetailViewModel(eventAggregatorMock.Object,
                                                  loggerMock.Object,
                                                  authorService,
                                                  dialogService);
        }
        public async Task <IActionResult> Details(Guid?Id, Tab tabname)
        {
            if (Id == null)
            {
                throw new ArgumentNullException(nameof(Id));
            }

            var author = await authorsRepository.GetSelectedAsync((Guid)Id);

            var vm = new AuthorDetailViewModel(author);

            vm.ActiveTab = tabname;

            return(View(vm));
        }
예제 #10
0
        public IActionResult AuthorDetails(int id)
        {
            var model = new AuthorDetailViewModel
            {
                Author   = AuthorRepository.Get(id),
                Articles = ArticleRepository.GetAll().ToList()
                           .Where(a => a.AuthorId == id)
            };

            if (model == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
 public ActionResult Create(AuthorDetailViewModel viewModel)
 {
     try
     {
         this.authorsUseCase.Create(new AuthorDto
         {
             FirstName = viewModel.FirstName,
             LastName  = viewModel.LastName,
             Email     = viewModel.Email
         });
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult Edit(int id, AuthorDetailViewModel viewModel)
 {
     try
     {
         this.authorsUseCase.Update(new AuthorDto
         {
             Id        = viewModel.Id,
             FirstName = viewModel.FirstName,
             LastName  = viewModel.LastName,
             Email     = viewModel.Email
         });
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
예제 #13
0
        public ActionResult AuthorDetails(int?id)
        {
            if (id == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
            Author author = context_.Authors.Find(id);

            if (author == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            var    userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            string currentrole;

            if (User.IsInRole("Admin"))
            {
                currentrole = "Admin";
            }
            else
            {
                currentrole = "User";
            }
            var documents       = context_.Documents.ToList();
            var authors         = context_.Authors.ToList();
            var documentauthors = context_.DocumentAuthors.ToList();
            var viewmodel       = new AuthorDetailViewModel
            {
                Author          = author,
                CurrentUserId   = userId,
                CurrentUserRole = currentrole,
                Authors         = authors,
                DocumentAuthors = documentauthors,
                Documents       = documents
            };

            return(View(viewmodel));
        }
        public async Task <IActionResult> Edit(Guid?Id)
        {
            if (ModelState.IsValid)
            {
                if (Id == null)
                {
                    throw new ArgumentNullException(nameof(Id));
                }

                var author = await authorsRepository.GetSelectedAsync((Guid)Id);

                var nationalities = await nationalityLookupDataService.GetNationalityLookupAsync(nameof(AuthorDetailViewModel));

                var vm = new AuthorDetailViewModel(author);

                vm.Nationalities = nationalities.ToList();

                return(View(vm));
            }

            return(Redirect("/"));
        }
예제 #15
0
        public AuthorDetailPage()
        {
            this.InitializeComponent();

            this.videoMediaPlayer.AutoPlay = SettingsStore.GetValueOrDefault <bool>(AppCommonConst.IS_AUTOPLAY_TOGGLLESWITCH_ON, true);

            if (authorDetailViewModel == null)
            {
                if (!SimpleIoc.Default.IsRegistered <AuthorDetailViewModel>())
                {
                    SimpleIoc.Default.Register <AuthorDetailViewModel>();
                }

                authorDetailViewModel = SimpleIoc.Default.GetInstance <AuthorDetailViewModel>();
            }

            this.DataContext = authorDetailViewModel;

            this.navigationHelper = new NavigationHelper(this);

            this.videoMediaPlayer.ControlPanelTemplate = AppEnvironment.IsPhone ? Application.Current.Resources["ControlPanelControlTemplatePhone"] as ControlTemplate : Application.Current.Resources["ControlPanelControlTemplatePC"] as ControlTemplate;

            this.szListView.ItemContainerStyle = AppEnvironment.IsPhone ? Application.Current.Resources["PhoneListViewItemStyle"] as Style : Application.Current.Resources["PCPastCategoryListViewItemStyle"] as Style;
            this.szListView.Padding            = AppEnvironment.IsPhone ? new Thickness(0, 0, 0, 0) : new Thickness(0, 0, 0, 3);

            this.Loaded += (ss, ee) =>
            {
                if (AppEnvironment.IsPhone)
                {
                    videoMediaPlayer.IsFullScreenVisible = false;
                    this.videoMediaPlayer.DoubleTapped  += videoMediaPlayer_DoubleTapped;

                    TopTapGuestureBox.Instance.ShowTopTapGuestureUIControl();
                }
                else
                {
                    videoMediaPlayer.IsFullScreenVisible = true;

                    this.KeyUp += PastDetailPage_KeyUp;
                    //szPCDailyFlipView.SelectionChanged += szPCDailyFlipView_SelectionChanged;
                }

                szListPC.IsZoomedInViewActive = true;

                szListPC.ViewChangeStarted   -= szListPC_ViewChangeStarted;
                szListPC.ViewChangeCompleted -= szListPC_ViewChangeCompleted;
                szListPC.ViewChangeStarted   += szListPC_ViewChangeStarted;
                szListPC.ViewChangeCompleted += szListPC_ViewChangeCompleted;

                if (authorDetailViewModel != null)
                {
                    authorDetailViewModel.GetAthorDetailCollection(authorDetailViewModel.AuthorDetailCollection, ApiAuthorRoot.Instance.AuthorDetailUrl);
                }
            };

            this.Unloaded += (ss, ee) =>
            {
                //这里是用来即可激发ZoomSemanticButtonMessenger,使zoomSemanticButton马上隐藏
                if (!AppEnvironment.IsPhone)
                {
                    Messenger.Default.Send <bool>(false, AppMessengerTokenConst.IS_ZOOMSEMANTIC_BUTTON_VISIBLE);
                }

                if (AppEnvironment.IsPhone)
                {
                    videoMediaPlayer.IsFullScreenVisible = false;
                    this.videoMediaPlayer.DoubleTapped  -= videoMediaPlayer_DoubleTapped;

                    //TopTapGuestureBox.Instance.HideTopTapGuestureUIControl();
                }
                else
                {
                    videoMediaPlayer.IsFullScreenVisible = true;

                    this.KeyUp -= PastDetailPage_KeyUp;

                    //szPCDailyFlipView.SelectionChanged -= szPCDailyFlipView_SelectionChanged;
                    //szPCDailyFlipView.SelectedIndex = -1;
                }

                szListPC.IsZoomedInViewActive = true;
            };
        }