public static ChapterViewModel GetChapterViewModel () { if (ChapterModel == null ) { ChapterModel = new ChapterViewModel(); } return ChapterModel; }
private void okButton_Click(object sender, RoutedEventArgs e) { ChapterViewModel originalChapter = SceneToMove.ChapterVm; ChapterViewModel newChapter = (ChapterViewModel)chapterListBox.SelectedItem; if (originalChapter != newChapter) { originalChapter.Scenes.Remove(SceneToMove); newChapter.Scenes.AddToEnd(SceneToMove); SceneToMove.ChapterVm = newChapter; SceneToMove.Model.ChapterId = newChapter.Model.id; SceneToMove.Model.Save(); } DialogResult = true; Close(); }
public ActionResult Edit(ChapterViewModel model) { if (ModelState.IsValid) { var chapter = db.Chapters .FirstOrDefault(a => a.Id.Equals(model.Id)); chapter.Title = model.Title; db.Entry(chapter).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", "Course", new { @id = chapter.CourseId })); } return(View(model)); }
public void LoadBook(int bookId, bool append = false) { var epubBook = bookModel.OpenBook(bookId); Contents = Contents.AddRange(bookModel.GetChapters(epubBook)); images = images.AddRange(epubBook.Content.Images.ToDictionary(imageFile => imageFile.Key, imageFile => imageFile.Value.Content)); styleSheets = styleSheets.AddRange(epubBook.Content.Css.ToDictionary(cssFile => cssFile.Key, cssFile => cssFile.Value.Content)); fonts = fonts.AddRange(epubBook.Content.Fonts.ToDictionary(fontFile => fontFile.Key, fontFile => fontFile.Value.Content)); selectChapterCommand = null; selectedChapter = null; selectedChapterContent = null; if (Contents.Any()) { SelectChapter(Contents.First()); } }
public ActionResult ViewChapter(string Chapter) { string[] slugs = Chapter.Split('-'); Story story = uow.StoryRepository.GetBySlug(slugs[0]); ChapterViewModel model = new ChapterViewModel(story.Chapters.Where(c => c.Slug == slugs[1]).FirstOrDefault()); if (LoginUserSession.Current.IsAuthenticated) { User user = uow.UserRepository.GetByID(LoginUserSession.Current.UserID); Chapter chapter = uow.ChapterRepository.GetByID(model.ID); model.LikesThis = user.Likes.Contains(chapter) ? true : false; } return(View(model)); }
public IActionResult SaveEntity(ChapterViewModel chapterViewModel) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (chapterViewModel.Id == 0) { _chapterService.Add(chapterViewModel); } else { _chapterService.Update(chapterViewModel); } _chapterService.SaveChanges(); return(new OkObjectResult(chapterViewModel)); }
public async Task <ActionResult> UpdateChapter([FromBody] ChapterViewModel chapter) { try { if (chapter == null) { logger.LogError($"Chapter object sent from client is null"); return(BadRequest("Chapter object is null")); } await chapterAdapter.UpdateChapter(chapter).ConfigureAwait(false); logger.LogInformation($"Chapter {chapter.ChapterTitle} is successfully updated"); return(Ok()); } catch (Exception ex) { logger.LogError($"Something went wrong inside UpdateChapter action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public ActionResult Delete(ChapterViewModel viewModel) { if (ModelState.IsValid) { var result = _chapterService.Delete(viewModel.ChapterId); if (result.Success) { var bodySubject = "Web portal changes - Chapter delete"; var message = "ClassName :" + viewModel.ClassName + ", SubjectName :" + viewModel.SubjectName + " deleted Successfully"; SendMailToAdmin(message, viewModel.Name, bodySubject); Success(result.Results.FirstOrDefault().Message); ModelState.Clear(); } else { _logger.Warn(result.Results.FirstOrDefault().Message); Warning(result.Results.FirstOrDefault().Message, true); } } return(RedirectToAction("Index")); }
public async void AddChapterToHistory(IChapter chapter) { var model = new ChapterViewModel { Url = chapter.Url, ChapterName = chapter.ChapterName }; chapter.InHistory = true; var historyChapterModel = await GetChapterListOfManga(chapter.Manga); var modelInHistory = historyChapterModel.ChapterHistoryViewModels.FirstOrDefault(x => x.Url == model.Url); if (modelInHistory != null) { historyChapterModel.ChapterHistoryViewModels.Remove(modelInHistory); } historyChapterModel.ChapterHistoryViewModels.Add(model); await BlobCache.UserAccount.InsertObject($"MangaChapterHistory_{chapter.Manga.Url}", historyChapterModel); }
public ActionResult Edit(ChapterViewModel viewModel) { if (ModelState.IsValid) { var chapter = _repository.Project <Chapter, bool>(chapters => (from chap in chapters where chap.ChapterId == viewModel.ChapterId select chap).Any()); if (!chapter) { _logger.Warn(string.Format("Chapter name not exists '{0}'.", viewModel.Name)); Danger(string.Format("Chapter name not exists '{0}'.", viewModel.Name)); } var result = _chapterService.Update(new Chapter { ChapterId = viewModel.ChapterId, SubjectId = viewModel.SubjectId, Name = viewModel.Name, Weightage = viewModel.Weightage }); if (result.Success) { var bodySubject = "Web portal changes - Chapter update"; var message = "ClassName :" + viewModel.ClassName + "<br/>SubjectName :" + viewModel.SubjectName + "<br/>Updated Successfully"; SendMailToAdmin(message, viewModel.Name, bodySubject); Success(result.Results.FirstOrDefault().Message); ModelState.Clear(); return(RedirectToAction("Index")); } else { _logger.Warn(result.Results.FirstOrDefault().Message); Warning(result.Results.FirstOrDefault().Message, true); } } ViewBag.SelectedClass = from mt in _classService.GetClasses() select new SelectListItem { Value = mt.ClassId.ToString(), Text = mt.Name }; ViewBag.SubjectId = viewModel.SubjectId; ViewBag.ClassId = viewModel.ClassId; return(View(viewModel)); }
public ActionResult Create(ChapterViewModel viewModel) { if (ModelState.IsValid) { var WeightageTotal = _chapterService.GetCountWeightage(viewModel.ClassId, viewModel.SubjectId); ViewBag.Weightage = WeightageTotal.ToString(); var wChk = WeightageTotal + viewModel.Weightage; var result = _chapterService.Save(new Chapter { Name = viewModel.Name, SubjectId = viewModel.SubjectId, Weightage = viewModel.Weightage }); if (result.Success) { if (wChk > 100) { Warning("Weightage more than 100."); } var bodySubject = "Web portal changes - Chapter Create"; var message = ", ClassName :" + viewModel.ClassName + ", SubjectName :" + viewModel.SubjectName + " Created Successfully"; SendMailToAdmin(message, viewModel.Name, bodySubject); Success(result.Results.FirstOrDefault().Message); ModelState.Clear(); viewModel = new ChapterViewModel(); ViewBag.Weightage = '0'; } else { _logger.Warn(result.Results.FirstOrDefault().Message); Warning(result.Results.FirstOrDefault().Message, true); } } ViewBag.SubjectId = viewModel.SubjectId; ViewBag.ClassId = viewModel.ClassId; var classes = _classService.GetClasses().ToList(); viewModel.Classes = new SelectList(classes, "ClassId", "Name"); return(View(viewModel)); }
public IActionResult Chapter(int id, int idC) { Chapter chapter = _repo.GetChapterOnPost(id, idC); if (chapter == null) { return(RedirectToAction("Index")); } ChapterViewModel vm = new ChapterViewModel { Id = idC, Body = chapter.Body, Note = chapter.Note, PostId = id, Title = chapter.Title, Likes = chapter.Likes, LikeReady = chapter.Likes.FirstOrDefault(x => x.Author == _user.GetIdByName(User.Identity.Name)) != null ? true : false }; return(View(vm)); }
public SurveyViewModel Umfrage_Kontrollieren(SurveyViewModel Umfrage_View) { ChapterViewModel testKapitel = new ChapterViewModel(); testKapitel.ID = Guid.NewGuid(); testKapitel.position = 0; testKapitel.text = "SfWA/DFcqYls7ZHjnK7JUODE057RVnr66GxTcxX05b2kwdoHHtTlVQ+CyH4oMm4khThHr+HHpFhuvk2+3LkfJOSt67vIGbCknaw3haS1oqZ2t9sEbPYDrEOE7UUibu9d"; testKapitel.questionViewModels = Umfrage_View.questionViewModels; var fragenOhneKapitel = Umfrage_View.questionViewModels.Where(z => z.chapterViewModel == null); testKapitel.questionViewModels = fragenOhneKapitel.ToList(); if (fragenOhneKapitel.Count() != 0) { Umfrage_View.chapterViewModels.Add(testKapitel); foreach (var frage in fragenOhneKapitel) { frage.chapterViewModel = testKapitel; } } return(Umfrage_View); }
public async Task <IActionResult> Index(ChapterViewModel model) { IActionResult result = RedirectToAction("AccessDenied", "Notifications"); if (await _rightService.CheckRights(model.CompositionId, await _userManager.GetUserAsync(HttpContext.User))) { var chapter = await _chapterService.FindByIdAsync(model.ChapterId); if (chapter != null) { chapter.Text = model.Text; _chapterService.UpdateChapter(chapter); var url = Url.Action("Main", "Chapter", new { id = model.CompositionId }); result = Redirect(url); } else { result = BadRequest(); } } return(result); }
private List <ChapterViewModel> GetChapters(List <EpubChapter> epubChapters, List <EpubChapter> epubChapters1, List <EpubChapter> epubChapters2) { List <ChapterViewModel> result = new List <ChapterViewModel>(); for (int index = 0; index < epubChapters.Count; index++) { EpubChapter epubChapter1 = epubChapters1[index]; List <ChapterViewModel> subChapters1 = GetChapters(epubChapter1.SubChapters); EpubChapter epubChapter2 = epubChapters2[index]; List <ChapterViewModel> subChapters2 = GetChapters(epubChapter2.SubChapters); EpubChapter epubChapter0 = epubChapters[index]; List <ChapterViewModel> subChapters0 = GetChapters(epubChapter0.SubChapters, epubChapter1.SubChapters, epubChapter2.SubChapters); ChapterViewModel chapterViewModel1 = new ChapterViewModel(epubChapter1.Title, subChapters1, epubChapter1.HtmlContent, epubChapter1.HtmlId); ChapterViewModel chapterViewModel2 = new ChapterViewModel(epubChapter2.Title, subChapters2, epubChapter2.HtmlContent, epubChapter2.HtmlId); ChapterViewModel chapterViewModel = new ChapterViewModel(epubChapter0.Title, subChapters0, epubChapter0.HtmlContent, epubChapter0.HtmlId, new List <ChapterViewModel> { chapterViewModel1, chapterViewModel2 }); result.Add(chapterViewModel); } return(result); }
private void doChapterTitleSearch(List <SearchResult> results) { _cmdSearchChapterNames.Parameters["@searchTerm"].Value = _searchTerm; using (SQLiteDataReader reader = _cmdSearchChapterNames.Command.ExecuteReader()) { while (reader.Read()) { ChapterSearchResult result = new ChapterSearchResult(reader); // Search scenes for owner. ChapterViewModel chapter = _selectedUniverse.Stories.SelectMany(i => i.Chapters.Where(i => i.Model.id == result.rowid)).SingleOrDefault(); if (chapter != null) { result.Owner = chapter; } if (result.Owner != null) { results.Add(result); } } } }
// GET: Chapter/Edit public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var chapter = db.Chapters .Where(a => a.Id == id) .First(); if (chapter == null) { return(HttpNotFound()); } var model = new ChapterViewModel(); model.Id = chapter.Id; model.Title = chapter.Title; return(View(model)); }
public ActionResult EditChapter(ChapterViewModel chapter) { Chapter dbChapter = uow.ChapterRepository.GetByID(chapter.ID); if (dbChapter == null) { dbChapter = new Chapter(); } dbChapter.ChapterName = chapter.ChapterName; dbChapter.ChapterNum = chapter.ChapterNum; dbChapter.Slug = chapter.Slug; dbChapter.Text = chapter.Text; dbChapter.DateCreated = DateTime.Now; dbChapter.StoryID = chapter.StoryID; uow.ChapterRepository.Save(dbChapter); uow.Save(); TempData["Message"] = "The chapter was saved successfully"; return(RedirectToAction("EditStories", "Stories")); }
public void Update(ChapterViewModel chapterViewModel) { var chapter = Mapper.Map <ChapterViewModel, Chapter>(chapterViewModel); _chapterRepository.Update(chapter); }
private void doMarkdownDocumentSearch(List <SearchResult> results) { _cmdSearchMarkdownDocuments.Parameters["@searchTerm"].Value = _searchTerm; using (SQLiteDataReader reader = _cmdSearchMarkdownDocuments.Command.ExecuteReader()) { while (reader.Read()) { MarkdownDocumentSearchResult result = new MarkdownDocumentSearchResult(reader); MarkdownDocumentViewModel mdvm = _selectedUniverse.MarkdownTree.Items.SingleOrDefault(i => i is MarkdownDocumentViewModel && (i as MarkdownDocumentViewModel).Model.id == result.rowid) as MarkdownDocumentViewModel; if (mdvm == null) { // "Special" documents don't have a viewmodel loaded at all times. MarkdownDocument doc = new MarkdownDocument(_cmdSearchMarkdownDocuments.Connection); doc.id = result.rowid; doc.Load(); mdvm = new MarkdownDocumentViewModel(doc, this.SelectedUniverse); } if (mdvm != null) { // If the document is "special", it is attached to an item such as a ticket, chapter, scene, etc. if (mdvm.Model.IsSpecial) { // Ticket search. TicketViewModel ticketVm = _selectedUniverse.TicketTrackerViewModel.Tickets.SingleOrDefault(i => i.Model.MarkdownDocumentId == mdvm.Model.id); if (ticketVm != null) { result.Owner = ticketVm; } // Category search. CategoryViewModel catVm = _selectedUniverse.Categories.SingleOrDefault(i => i.Model.MarkdownDocumentId == mdvm.Model.id); if (catVm != null) { result.Owner = catVm; } // Story search. StoryViewModel storyVm = _selectedUniverse.Stories.SingleOrDefault(i => i.Model.MarkdownDocumentId == mdvm.Model.id); if (storyVm != null) { result.Owner = storyVm; } // Chapter search. ChapterViewModel chapterVm = _selectedUniverse.Stories.SelectMany(i => i.Chapters).SingleOrDefault(i => i.Model.MarkdownDocumentId == mdvm.Model.id); if (chapterVm != null) { result.Owner = chapterVm; } // Scene search. SceneViewModel sceneVm = _selectedUniverse.Stories.SelectMany(i => i.Chapters).SelectMany(i => i.Scenes).SingleOrDefault(i => i.Model.MarkdownDocumentId == mdvm.Model.id); if (sceneVm != null) { result.Owner = sceneVm; } } else { // Not special. This is a normal note in the universe's tree of markdown documents. result.Owner = mdvm; } if (result.Owner != null) { results.Add(result); } } } } }
public ChapterDisplay(TopicViewModel _curTopic) { ChapterViewModel curChapterVM = new ChapterViewModel(_curTopic); ListView lvAllChapters = new ListView(); Label lblPageTitle = new Label { Text = "Vos Chapitres", FontSize = 40, }; Label lblUserConnected = new Label { Text = "Bon apprentissage, " + _curTopic.CurrentUserVM.LoginName + " !", FontSize = 15, FontAttributes = FontAttributes.Italic, TextColor = Color.FromHex("#607d8b") }; Label lblTopicSelected = new Label { Text = _curTopic.TopicName, FontSize = 15, FontAttributes = FontAttributes.Italic, TextColor = Color.FromHex("#607d8b") }; List <ChapterViewModel> AllChaptersVM = curChapterVM.GetChaptersForTopicVM(_curTopic); if (AllChaptersVM == null || (AllChaptersVM != null) && AllChaptersVM.Count() == 0) { //SDI: If there is no chapter yet,we add a "fake" chapter which is a link to open the CreateChapter page ChapterViewModel fakeToAdd = new ChapterViewModel(_curTopic); fakeToAdd.ChapterName = "Créer un chapitre"; AllChaptersVM = new List <ChapterViewModel>(); AllChaptersVM.Add(fakeToAdd); } else { //SDI: we just add the fake chapter at the end of the list ChapterViewModel fakeToAdd = new ChapterViewModel(_curTopic); fakeToAdd.ChapterName = "Créer un chapitre"; AllChaptersVM.Add(fakeToAdd); } lvAllChapters.ItemsSource = AllChaptersVM; lvAllChapters.ItemTemplate = new DataTemplate(typeof(CustomChapterCell));//lvAllChapters.ItemTemplate = new DataTemplate(typeof(ImageCell)); lvAllChapters.ItemTemplate.SetBinding(ImageCell.ImageSourceProperty, "ChapterImage"); lvAllChapters.ItemTemplate.SetBinding(ImageCell.TextProperty, "ChapterName"); lvAllChapters.ItemTemplate.SetValue(ImageCell.TextColorProperty, Color.FromHex("#795548")); lvAllChapters.ItemTapped += async(sender, e) => { ChapterViewModel cvm = (ChapterViewModel)e.Item; if (cvm.ChapterName.Trim().ToLower().Equals("créer un chapitre")) { //SDI: if element tapped is to create a new chapter, we go to the CreateChapter page //Le modal ne marche pas bien car le retour à la page precedente ne rafraichis pas les données: A revoir //await Navigation.PushModalAsync(new CreateTopic(_curUserVM)); await Navigation.PushAsync(new CreateChapter(_curTopic)); } else //SDI:An existing chapter has been selected, we open the contextual menu { //ChapterViewModel test = new ChapterViewModel(_curTopic); ; //test.DeleteAllChapters(); await Navigation.PushAsync(new ChapterSelected(cvm)); //await DisplayAlert("Tapped", cvm.ChapterName.ToString() + " was selected.", "OK","Cancel"); } ((ListView)sender).SelectedItem = null; }; lvAllChapters.IsPullToRefreshEnabled = true;//To enable the refreshment of the listview when pulled var stackLayout = new StackLayout { Children = { lblPageTitle, lblUserConnected, lblTopicSelected, lvAllChapters }, BackgroundColor = Color.White }; this.Content = stackLayout; this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); this.BackgroundColor = Color.Gray; }
public async Task UpdateChapter(ChapterViewModel chapter) { var updatedChapter = mapper.Map <Chapter>(chapter); await chapterService.UpdateAsync(updatedChapter).ConfigureAwait(false); }
public async Task CreateChapter(ChapterViewModel chapter) { await chapterService.CreateAsync(mapper.Map <Chapter>(chapter)).ConfigureAwait(false); }
public void Add(ChapterViewModel chapterVm) { var chapter = Mapper.Map <ChapterViewModel, Chapter>(chapterVm); _chapterRepository.Add(chapter); }
public ChapterEdition(TopicViewModel curTopic, ChapterViewModel curChapter) { Chapter oldChapter = new Chapter(); oldChapter.ID = curChapter.ChapterId; oldChapter.Name = curChapter.ChapterName; oldChapter.TopicId = curChapter.ChapterTopicId; ChapterViewModel chapterVM = new ChapterViewModel(curTopic, oldChapter); Label lblPageTitle = new Label { Text = "Modifier le chapitre", FontSize = 40, }; Entry EntryChapter = new Entry() { HorizontalOptions = LayoutOptions.Center, Keyboard = Keyboard.Text, WidthRequest = 400 }; EntryChapter.BindingContext = chapterVM; EntryChapter.SetBinding(Entry.TextProperty, new Binding("ChapterName")); Button btnOk = new Button() { Text = "Valider", HorizontalOptions = LayoutOptions.Center, BackgroundColor = Color.Silver }; btnOk.Clicked += async(sender, args) => { chapterVM.SaveChapterVM(); await DisplayAlert("Information", "Le chapitre:" + chapterVM.ChapterName + " a été modifié!", "OK"); //Le modal ne marche pas bien car le retour à la page precedente ne rafraichis pas les données: A revoir //await Navigation.PopModalAsync(); await Navigation.PushAsync(new ChapterDisplay(curTopic));//SDI:We go back to the full chapter list }; Button btnCancel = new Button() { Text = "Annuler", HorizontalOptions = LayoutOptions.Center, BackgroundColor = Color.Silver }; btnCancel.Clicked += async(sender, args) => { await Navigation.PushAsync(new ChapterDisplay(curTopic));//SDI:We go back to the full chapter list }; var stackLayout = new StackLayout { Children = { lblPageTitle, EntryChapter, btnCancel, btnOk }, BackgroundColor = Color.White }; this.Content = stackLayout; this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); this.BackgroundColor = Color.Gray; }
public ActionResult EditChapter(int id, ChapterViewModel chapter) { novelService.UpdateChapter(id, chapter); return(RedirectToAction("ReadChapter", "Home", new { id })); }
public ChapterSelected(ChapterViewModel _curChapter) { Label lblUserConnected = new Label { Text = "Bon apprentissage, " + _curChapter.CurrentTopic.CurrentUserVM.LoginName + " !", FontSize = 15, FontAttributes = FontAttributes.Italic, TextColor = Color.FromHex("#607d8b") }; Label lblTopicSelected = new Label { Text = _curChapter.CurrentTopic.TopicName, FontSize = 15, FontAttributes = FontAttributes.Italic, TextColor = Color.FromHex("#607d8b") }; Label lblChapterSelected = new Label { Text = _curChapter.ChapterName, FontSize = 15, FontAttributes = FontAttributes.Italic, TextColor = Color.FromHex("#607d8b") }; #region Image Apprendre Image imgLearn = new Image { Source = "learn.png", Aspect = Aspect.AspectFit, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Fill }; TapGestureRecognizer imgLearnTapGest = new TapGestureRecognizer(); imgLearnTapGest.Tapped += async(s, e) => { String test = await DisplayActionSheet("Test action sheet on learn", "Annuler", "destruction", "Other choices"); //await Navigation.PushAsync(new Pages.Connect()); }; imgLearn.GestureRecognizers.Add(imgLearnTapGest); #endregion #region Image Lancer le test Image imgRunTest = new Image { Source = "runtest.png", Aspect = Aspect.AspectFit, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Fill }; TapGestureRecognizer imgRunTestTapGest = new TapGestureRecognizer(); imgRunTestTapGest.Tapped += async(s, e) => { //String test = await DisplayActionSheet("Test action sheet on test", "Annuler", "destruction", "Other choices"); await Navigation.PushAsync(new Pages.TestQuestionCheck(_curChapter)); }; imgRunTest.GestureRecognizers.Add(imgRunTestTapGest); #endregion #region Image Lire la fiche Image imgRevisionCard = new Image { Source = "revisioncard.png", Aspect = Aspect.AspectFit, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Fill }; TapGestureRecognizer imgRevisionCardTapGest = new TapGestureRecognizer(); imgRevisionCardTapGest.Tapped += async(s, e) => { String test = await DisplayActionSheet("Test action sheet on revision", "Annuler", "destruction", "Other choices"); //await Navigation.PushAsync(new Pages.Connect()); }; imgRevisionCard.GestureRecognizers.Add(imgRevisionCardTapGest); #endregion var stackLayout = new StackLayout { Children = { lblUserConnected, lblTopicSelected, lblChapterSelected, imgLearn, imgRunTest, imgRevisionCard }, BackgroundColor = Color.White }; this.Content = stackLayout; this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); this.BackgroundColor = Color.Gray; }
protected override void OnNavigatedTo(NavigationEventArgs e) { chapterViewModel = new ChapterViewModel(new Chapter(), pageFlipView); DataContext = chapterViewModel; //Window.Current.SizeChanged += new WindowSizeChangedEventHandler(sizeChangedHandler); }
protected override void OnAppearing() { List.NeedToReload = true; TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += (sender, e) => { Frame theFrame = (Frame)sender; ChapterViewModel a = theFrame.BindingContext as ChapterViewModel; Navigation.PushAsync(new ChapterPage(a)); }; if (List.NeedToReload == true) { grid.Children.Clear(); chapcounter = 0; while (grid.RowDefinitions.Count - 1 < (App.Database2.GetItems().ToList().Count) / 2) { grid.RowDefinitions.Add(new RowDefinition { Height = 200 }); Console.WriteLine("Added row"); } Console.WriteLine("Count {0} , Rows {1}", ((App.Database2.GetItems().ToList().Count) / 2), grid.RowDefinitions.Count); for (int i = List.Chapters.Count - 1; i > -1; i--) { /*if (i % 2 == 0) * { * grid.RowDefinitions.Add(new RowDefinition { Height = 200 }); * }*/ ChapterViewModel c = List.Chapters[i]; Label title = new Label() { Text = c.Title }; Image delImg = new Image { Source = "trashcanimg.jpg", HeightRequest = 40, WidthRequest = 40 }; Button delBut = new Button { ImageSource = "trashcanimg.jpg", BorderWidth = 0, HeightRequest = 40, WidthRequest = 40, HorizontalOptions = LayoutOptions.Center, CornerRadius = 0, BackgroundColor = Color.White, Command = List.DeleteChapterCommand, CommandParameter = c }; delBut.Clicked += OnDelButtonClicked; delBut.HeightRequest = 40; RelativeLayout layout = new RelativeLayout() { Margin = 0 }; Frame frame = new Frame { BorderColor = Color.Accent, BindingContext = c, Margin = 0 }; frame.Content = layout; layout.Children.Add(title, Constraint.RelativeToParent((parent) => { return(parent.Width - 110); // установка координаты X }), Constraint.RelativeToParent((parent) => { return(parent.Height - 150); // установка координаты Y }), Constraint.Constant(100), // установка ширины Constraint.Constant(100) // установка высоты ); layout.Children.Add(delBut, Constraint.RelativeToParent((parent) => { return(parent.Width - 40); // установка координаты X }), Constraint.RelativeToParent((parent) => { return(parent.Height - 40); // установка координаты Y }), Constraint.Constant(40), // установка ширины Constraint.Constant(40) // установка высоты ); frame.GestureRecognizers.Add(tapGestureRecognizer); if (chapcounter % 2 == 0) { } delBut.HeightRequest = 40; grid.Children.Add(frame, chapcounter % 2, chapcounter / 2); chapcounter++; } } }
public ChapterContentEdition(ChapterViewModel _selChapterVM) { ListView lvAllChapterQuestions = new ListView(); QuestionAnswerViewModel QuestionsVM = new QuestionAnswerViewModel(_selChapterVM); var lblChapter = new Label { Text = "Chapitre " + _selChapterVM.ChapterName }; List <QuestionAnswerViewModel> AllQuestionsVM = QuestionsVM.GetQuestionsForChapterVM(_selChapterVM); if (AllQuestionsVM == null || (AllQuestionsVM != null) && AllQuestionsVM.Count() == 0) { //QuestionAnswerViewModel test = new QuestionAnswerViewModel(_selChapterVM); ; //test.DeleteAllQuestions(); //SDI: If there is no questions yet,we add a "fake" question which is a link to open the CreateQuestion page QuestionAnswerViewModel fakeToAdd = new QuestionAnswerViewModel(_selChapterVM); fakeToAdd.QuestionText = "Nouvelle question"; AllQuestionsVM = new List <QuestionAnswerViewModel>(); AllQuestionsVM.Add(fakeToAdd); } else { //SDI: we just add the fake chapter at the end of the list QuestionAnswerViewModel fakeToAdd = new QuestionAnswerViewModel(_selChapterVM); fakeToAdd.QuestionText = "Nouvelle question"; AllQuestionsVM.Add(fakeToAdd); } lvAllChapterQuestions.ItemsSource = AllQuestionsVM; lvAllChapterQuestions.ItemTemplate = new DataTemplate(typeof(CustomQuestionCell)); lvAllChapterQuestions.ItemTemplate.SetBinding(ImageCell.TextProperty, "QuestionText"); lvAllChapterQuestions.ItemTemplate.SetValue(ImageCell.TextColorProperty, Color.FromHex("#795548")); lvAllChapterQuestions.ItemTapped += async(sender, e) => { QuestionAnswerViewModel qvm = (QuestionAnswerViewModel)e.Item; //SDI: Creation and Update are using the same create question page since the fields are bound to the object await Navigation.PushAsync(new CreateQuestionAnswer(qvm)); #region Old //if (qvm.QuestionText.Trim().ToLower().Equals("nouvelle question")) //{ // //SDI: if element tapped is to create a new question, we go to the CreateQuestion page // await Navigation.PushAsync(new CreateQuestionAnswer(qvm)); //await DisplayAlert("Info", "nouvelle question", "Ok"); //} //else //SDI:An existing question has been selected, we edit the question //{ // await Navigation.PushAsync(new QuestionAnswerContentEdition(qvm)); //} #endregion ((ListView)sender).SelectedItem = null; }; lvAllChapterQuestions.IsPullToRefreshEnabled = true;//To enable the refreshment of the listview when pulled var stackLayout = new StackLayout { Children = { lblChapter, lvAllChapterQuestions }, BackgroundColor = Color.White }; this.BindingContext = AllQuestionsVM; this.Content = stackLayout; this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); this.BackgroundColor = Color.Gray; }
public ChaptersListPage() { NavigationPage.SetHasNavigationBar(this, false); List = new ChaptersListViewModel() { Navigation = this.Navigation }; Thickness labelMargin = new Thickness(15, 15, 15, 0); Button AddButton = new Button() { Text = "Добавить главу", Command = List.CreateChapterCommand, BackgroundColor = Color.FromHex("#1b97f3"), FontSize = 15, TextColor = Color.FromHex("#FFFFFF"), Margin = labelMargin }; grid = new Grid { Margin = 15, ColumnSpacing = 30, RowSpacing = 35, RowDefinitions = { new RowDefinition { Height = 200 } }, ColumnDefinitions = { new ColumnDefinition { Width = 164 }, new ColumnDefinition { Width = 164 }, } }; var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += (sender, e) => { Frame theFrame = (Frame)sender; ChapterViewModel a = theFrame.BindingContext as ChapterViewModel; Navigation.PushAsync(new ChapterPage(a)); }; /* for (int i = List.Chapters.Count - 1; i > -1; i--) * { * ChapterViewModel c = List.Chapters[i]; * Frame frame = new Frame { BorderColor = Color.Accent, BindingContext = c }; * frame.Content = new Label * { * Text = c.Title, * HorizontalTextAlignment = TextAlignment.Center * }; * frame.GestureRecognizers.Add(tapGestureRecognizer); * if (chapcounter % 2 == 0) * { * grid.RowDefinitions.Add(new RowDefinition { Height = 200 }); * } * grid.Children.Add(frame, chapcounter % 2, chapcounter / 2); * chapcounter++; * }*/ grid.Children.Clear(); chapcounter = 0; if (grid.RowDefinitions.Count + 1 < (App.Database2.GetItems().ToList().Count) / 2) { grid.RowDefinitions.Add(new RowDefinition { Height = 200 }); } for (int i = List.Chapters.Count - 1; i > -1; i--) { if (i % 2 == 0) { grid.RowDefinitions.Add(new RowDefinition { Height = 200 }); } ChapterViewModel c = List.Chapters[i]; Label title = new Label() { Text = c.Title }; Image delImg = new Image { Source = "trashcanimg.jpg", HeightRequest = 40, WidthRequest = 40 }; Button delBut = new Button { ImageSource = "trashcanimg.jpg", BorderWidth = 0, HeightRequest = 40, WidthRequest = 40, HorizontalOptions = LayoutOptions.Center, CornerRadius = 0, BackgroundColor = Color.White, Command = List.DeleteChapterCommand, CommandParameter = c }; delBut.Clicked += OnDelButtonClicked; delBut.HeightRequest = 40; RelativeLayout layout = new RelativeLayout() { Margin = 0 }; Frame frame = new Frame { BorderColor = Color.Accent, BindingContext = c, Margin = 0 }; frame.Content = layout; layout.Children.Add(title, Constraint.RelativeToParent((parent) => { return(parent.Width - 90); // установка координаты X }), Constraint.RelativeToParent((parent) => { return(parent.Height - 150); // установка координаты Y }), Constraint.Constant(100), // установка ширины Constraint.Constant(100) // установка высоты ); layout.Children.Add(delBut, Constraint.RelativeToParent((parent) => { return(parent.Width - 40); // установка координаты X }), Constraint.RelativeToParent((parent) => { return(parent.Height - 40); // установка координаты Y }), Constraint.Constant(40), // установка ширины Constraint.Constant(40) // установка высоты ); frame.GestureRecognizers.Add(tapGestureRecognizer); if (chapcounter % 2 == 0) { } delBut.HeightRequest = 40; grid.Children.Add(frame, chapcounter % 2, chapcounter / 2); chapcounter++; } ScrollView scrollView = new ScrollView(); scrollView.Content = grid; StackLayout stackLayout = new StackLayout(); stackLayout.Children.Add(AddButton); stackLayout.Children.Add(scrollView); Content = stackLayout; NavigationPage.SetHasNavigationBar(this, false); }