コード例 #1
0
        /// <summary>
        /// Show page with user/aurhors list.
        /// </summary>
        /// <returns>Page with list of users.</returns>
        public async Task <IActionResult> Index()
        {
            var authorsQuery = new GetAuthorsQuery();
            var authors      = await _mediator.Send(authorsQuery);

            var authorsVM = _mapper.Map <IEnumerable <AuthorDTO>, ICollection <AuthorViewModel> >(authors);

            foreach (var author in authorsVM)
            {
                author.Email = await _identityService.GetEmailByIdAsync(author.UserId);

                author.PostsNumber = _mediator.Send(new GetPostsByAuthorIdQuery {
                    AuthorId = author.AuthorId
                }).GetAwaiter().GetResult().Count;
                author.CommentsNumber = _mediator.Send(new GetCommentsByAuthorIdQuery {
                    AuthorId = author.AuthorId
                }).GetAwaiter().GetResult().Count;
            }

            var isAdmin = HttpContext.User.IsInRole("admin");
            var model   = new AuthorsViewModel
            {
                Authors = authorsVM,
                IsAdmin = isAdmin,
            };

            return(View(model));
        }
コード例 #2
0
        public ActionResult Edit(AuthorsViewModel author)
        {
            if (ModelState.IsValid)
            {
                var MyAuthor = db.Authors.Find(author.AuthorID);

                MyAuthor.Name    = author.Name;
                MyAuthor.Surname = author.Surname;

                foreach (var item in db.AuthorsToBooks)
                {
                    if (item.AuthorID == author.AuthorID)
                    {
                        db.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                    }
                }

                foreach (var item in author.Books)
                {
                    if (item.Checked)
                    {
                        db.AuthorsToBooks.Add(new AuthorToBook()
                        {
                            AuthorID = author.AuthorID, BookID = item.Id
                        });
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(author));
        }
コード例 #3
0
        public ActionResult Authors()
        {
            var model = new AuthorsViewModel();

            try
            {
                using (var dbContext = new Bookshop_DBContext())
                {
                    dbContext.Authors.ForEach(author => model.Authors.Add(new Author
                    {
                        author_id  = author.author_id,
                        first_name = author.first_name,
                        last_name  = author.last_name,
                        DOB        = author.DOB,
                        info       = author.info
                    }));
                }
            }
            catch (SqlException e)
            {
                model.ErrorMessage = e.Message;
                return(View(model));
            }

            return(View(model));
        }
コード例 #4
0
        public async Task <ActionResult> Edit(AuthorsViewModel model, string id)
        {
            var access_token = Session["access_token"];

            var data = new Dictionary <string, string> {
                { "Name", model.Name },
                { "LastName", model.LastName },
                { "Email", model.Email },
                { "Birth", model.Birth.ToString() }
            };

            using (var client = new HttpClient()) {
                client.BaseAddress = new Uri("http://localhost:60453");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{access_token}");

                using (var requestContent = new FormUrlEncodedContent(data)) {
                    var response = await client.PutAsync($"Api/Author?author_id={id}", requestContent);

                    if (response.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(View("Error"));
                    }
                }
            }
        }
コード例 #5
0
        public async Task <ActionResult> Edit(string id)
        {
            var access_token = Session["access_token"];

            AuthorsViewModel autor = new AuthorsViewModel();

            using (var client = new HttpClient()) {
                client.BaseAddress = new Uri("http://localhost:60453");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{access_token}");

                var response = await client.GetAsync($"/api/author/{id}");

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = await response.Content.ReadAsStringAsync();

                    autor = JsonConvert.DeserializeObject <AuthorsViewModel>(responseContent);

                    return(View(autor));
                }
                else
                {
                    return(View("Error"));
                }
            }
        }
コード例 #6
0
        public async Task <IActionResult> Authors()
        {
            var model = new AuthorsViewModel {
                Authors = await db.Authors.ToListAsync()
            };

            return(View(model));
        }
コード例 #7
0
        public async Task <ActionResult> PutAuthors(Guid id, [FromBody] AuthorsViewModel author)
        {
            if (id != author.ID)
            {
                return(BadRequest());
            }
            await _authorsService.Edit(_mapper.Map <IAuthors>(author));

            return(NoContent());
        }
コード例 #8
0
        public async Task <IActionResult> Index()
        {
            var authors = await authorLookupDataService.GetAuthorLookupAsync(nameof(AuthorsViewModel));

            var vm = new AuthorsViewModel()
            {
                Authors = authors
            };

            return(View(vm));
        }
コード例 #9
0
ファイル: AuthorService.cs プロジェクト: Esusbek/EducationApp
 public AuthorsViewModel GetViewModel(AuthorsViewModel model)
 {
     return(new AuthorsViewModel
     {
         Authors = GetAuthorsFiltered(null, model.SortBy, model.Ascending, page: model.Page),
         Page = model.Page,
         PageCount = GetPageCount(),
         SortBy = model.SortBy,
         Ascending = model.Ascending
     });
 }
コード例 #10
0
        public async Task <IActionResult> Authors()
        {
            var query       = new AuthorsQuery();
            var queryResult = await _mediator.Send(query);

            var model = new AuthorsViewModel()
            {
                Authors = queryResult.Authors
            };

            return(View(model));
        }
コード例 #11
0
        public async Task <IActionResult> Edit(AuthorsViewModel author)
        {
            /*if (id != author.AuthorID)
             * {
             *  return NotFound();
             * }*/

            if (ModelState.IsValid)
            {
                try
                {
                    var MyAuthor = _context.Author.Find(author.AuthorID);
                    MyAuthor.Name    = author.Name;
                    MyAuthor.SurName = author.SurName;

                    foreach (var item in _context.AuthorToBook)
                    {
                        if (item.AuthorID == author.AuthorID)
                        {
                            _context.Remove(item);
                        }
                    }
                    foreach (var item in author.Books)
                    {
                        if (item.Checked)
                        {
                            _context.AuthorToBook.Add(new AuthorToBook()
                            {
                                AuthorID = author.AuthorID, BookID = item.ID
                            });
                        }
                    }
                    //_context.Update(author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuthorExists(author.AuthorID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
コード例 #12
0
        public AuthorsViewModelTests()
        {
            eventAggregatorMock     = new Mock <IEventAggregator>();
            authorLookupServiceMock = new Mock <IAuthorLookupDataService>();

            authorLookupServiceMock.Setup(dp => dp.GetAuthorLookupAsync(nameof(AuthorDetailViewModel)))
            .ReturnsAsync(new List <LookupItem>
            {
                new LookupItem {
                    Id = Guid.NewGuid(), DisplayMember = "King, Stephen"
                },
                new LookupItem {
                    Id = Guid.NewGuid(), DisplayMember = "Rothfuss, Patrick"
                }
            });

            viewModel = new AuthorsViewModel(eventAggregatorMock.Object, authorLookupServiceMock.Object);
        }
コード例 #13
0
        public async Task <ActionResult> Delete(string Id, string praDiferenciarOsMetodos)
        {
            var autor        = new AuthorsViewModel();
            var access_token = Session["access_token"];

            using (var client = new HttpClient()) {
                client.BaseAddress = new Uri("http://localhost:60453");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{access_token}");

                var books_resopnse = await client.GetAsync($"api/author/{Id}");

                var responseContent = await books_resopnse.Content.ReadAsStringAsync();

                autor = JsonConvert.DeserializeObject <AuthorsViewModel>(responseContent);
            }

            return(View(autor));
        }
コード例 #14
0
 public IHttpActionResult GetAuthor()
 {
     try
     {
         var authors = new AuthorsViewModel().FindAuthor();
         if (authors.Count() > 0)
         {
             return(Ok(new { Result = "OK", Record = new JavaScriptSerializer().Serialize(authors) }));
         }
         else
         {
             return(NotFound());
         }
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
コード例 #15
0
 public IHttpActionResult DELETE(int id)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var authors = new AuthorsViewModel().RemoveById(id);
             return(Ok(authors));
         }
         catch (Exception ex)
         {
             return(InternalServerError(ex));
         }
     }
     else
     {
         return(NotFound());
     }
 }
コード例 #16
0
        public ActionResult Authors(string author)
        {
            var libraryClient = new LibrarySoapClient();
            var model         = new AuthorsViewModel();

            model.Authors = libraryClient.GetAuthors();
            if (!string.IsNullOrWhiteSpace(author))
            {
                model.PublicatedBooks =
                    libraryClient.GetBooksByAuthor(author).Select(e => new BookShortInfo()
                {
                    Id = e.Id, Title = e.Title
                });
                model.SelectedAuthor = author;
            }
            libraryClient.Close();

            return(View(model));
        }
コード例 #17
0
 public IHttpActionResult POST([FromBody] Models.IAuthors autor)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var authors = new AuthorsViewModel().AddOrModifyAuthor(autor);
             return(Ok(authors));
         }
         catch (Exception ex)
         {
             return(InternalServerError(ex));
         }
     }
     else
     {
         return(NotFound());
     }
 }
コード例 #18
0
        public void Execute(object parameter)
        {
            // wyciągnięcie danych z tabeli - patients
            getter         = new AuthorsViewModel(); //Deklarujemy zmienną typu PatientsView
            selectedAuthor = getter.InfoAuthorGetter();
            //SelectedIDPatient = selectedPatient[1];
            MessageBoxResult result = MessageBox.Show("Czy na pewno chcesz usunąć autora " + selectedAuthor[1] + " " + selectedAuthor[2], "Potwierdź usunięcie autora", MessageBoxButton.OKCancel, MessageBoxImage.Warning);

            switch (result)
            {
            case MessageBoxResult.OK:
                vm.DeleteAuthor();
                break;

            case MessageBoxResult.Cancel:

                break;
            }
        }
コード例 #19
0
 public IHttpActionResult PUT([FromBody]  int autorId)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var authors = new AuthorsViewModel().SetAuthor(autorId);
             return(Ok(authors));
         }
         catch (Exception ex)
         {
             return(InternalServerError(ex));
         }
     }
     else
     {
         return(NotFound());
     }
 }
コード例 #20
0
        public ActionResult Index(int?id, int page = 1)
        {
            var authors      = bookService.GetAuthors().Result;
            var books        = bookService.GetBooks().Result;
            int itemsPerPage = 10;

            ViewBag.PageCount = Math.Ceiling(authors.Count() / (double)itemsPerPage);
            if (page < 0)
            {
                page = 0;
            }

            if (page > ViewBag.PageCount)
            {
                page = (int)ViewBag.PageCount;
            }

            ViewBag.CurrentPage = page;
            int start = (page - 1) * itemsPerPage;

            //for (int i = authors.Count; i < 150; i++)
            //{
            //    var aut = new Author()
            //    {
            //        Name = $"Example Author #{i.ToString()}",
            //        Books = new List<Book>()
            //    };
            //    authors.Add(aut);
            //}

            var vm = new AuthorsViewModel()
            {
                Authors      = authors.Skip(start).Take(itemsPerPage).ToList(),
                SelectedBook = id == null ? null : books.Find(x => x.Id == id)
            };

            if (vm.SelectedBook != null)
            {
                vm.SelectedBook.Author = authors.Find(x => x.Id == vm.SelectedBook.AuthorId);
            }

            return(View(vm));
        }
コード例 #21
0
        // GET: Authors/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var author = await _context.Author
                         .FirstOrDefaultAsync(m => m.AuthorID == id);

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

            var Results = from b in _context.Book
                          select new
            {
                b.BookID,
                b.Title,
                Checked = (from ab in _context.AuthorToBook
                           where (ab.AuthorID == id) & (ab.BookID == b.BookID)
                           select ab).Count() > 0
            };
            var MyViewModel = new AuthorsViewModel();

            MyViewModel.AuthorID = id.Value;
            MyViewModel.Name     = author.Name;
            MyViewModel.SurName  = author.SurName;

            var MyCheckBoxList = new List <CheckBoxViewModel>();

            foreach (var item in Results)
            {
                MyCheckBoxList.Add(new CheckBoxViewModel {
                    ID = item.BookID, Name = item.Title, Checked = item.Checked
                });
            }
            MyViewModel.Books = MyCheckBoxList;
            return(View(MyViewModel));
        }
コード例 #22
0
        // GET: Authors/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Author author = db.Authors.Find(id);

            if (author == null)
            {
                return(HttpNotFound());
            }

            var Results = from b in db.Books
                          select new
            {
                b.BookID,
                b.Title,
                Checked = ((from ab in db.AuthorsToBooks
                            where (ab.AuthorID == id) & (ab.BookID == b.BookID)
                            select ab).Count() > 0)
            };

            var MyViewModel = new AuthorsViewModel();

            MyViewModel.AuthorID = id.Value;
            MyViewModel.Name     = author.Name;
            MyViewModel.Surname  = author.Surname;

            var MyCheckBoxList = new List <CheckBoxViewModel>();

            foreach (var item in Results)
            {
                MyCheckBoxList.Add(new CheckBoxViewModel {
                    Id = item.BookID, Name = item.Title, Checked = item.Checked
                });
            }
            MyViewModel.Books = MyCheckBoxList;
            return(View(MyViewModel));
        }
コード例 #23
0
 public AuthorListPage(CreateBookViewModel createBookViewModel, LibraryContext context)
 {
     InitializeComponent();
     this.createBookViewModel = createBookViewModel;
     DataContext = new AuthorsViewModel(new AuthorRepository(context));
 }
コード例 #24
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ViewModel = new AuthorsViewModel();
            ViewModel.LoadAuthorsCommand.Execute(null);
            // Setup UITableView.
            //refreshControl = new UIRefreshControl();
            //refreshControl.ValueChanged += RefreshControl_ValueChanged;
            //TableView.Add(refreshControl);
            var regex = new Regex("^[a-z]");

            foreach (var author in ViewModel.Authors)
            {
                var firstLetter = author.Name[0].ToString();
                if (regex.IsMatch(firstLetter.ToLower()))
                {
                    continue;
                }
                if (indexedTableAuthors.ContainsKey(firstLetter))
                {
                    indexedTableAuthors[firstLetter].Add(author);
                }
                else
                {
                    if (firstLetter == "أ" || firstLetter == "إ")
                    {
                        if (indexedTableAuthors.ContainsKey("ا"))
                        {
                            indexedTableAuthors["ا"].Add(author);
                        }
                        else
                        {
                            indexedTableAuthors.Add("ا", new List <Author>()
                            {
                                author
                            });
                        }
                    }
                    else
                    {
                        indexedTableAuthors.Add(firstLetter, new List <Author>()
                        {
                            author
                        });
                    }
                }
            }
            keys = indexedTableAuthors.Keys.ToArray();

            TableView.Source = new AuthorsDataSource(indexedTableAuthors, keys);


            //Search bar
            resultsTableController = new ResultsTableController
            {
                Authors = new List <Author>()
            };

            searchController = new UISearchController(resultsTableController)
            {
                WeakDelegate = this,
                DimsBackgroundDuringPresentation = false,
                WeakSearchResultsUpdater         = this
            };

            searchController.SearchBar.SizeToFit();
            searchController.SearchBar.SearchBarStyle    = UISearchBarStyle.Minimal;
            searchController.SearchBar.Placeholder       = "ابحث بالاسم";
            searchController.SearchBar.ShowsCancelButton = false;
            TableView.TableHeaderView = searchController.SearchBar;

            resultsTableController.TableView.WeakDelegate = this;
            searchController.SearchBar.WeakDelegate       = this;

            DefinesPresentationContext = true;

            if (searchControllerWasActive)
            {
                searchController.Active   = searchControllerWasActive;
                searchControllerWasActive = false;

                if (searchControllerSearchFieldWasFirstResponder)
                {
                    searchController.SearchBar.BecomeFirstResponder();
                    searchControllerSearchFieldWasFirstResponder = false;
                }
            }



            // Title
            Title = ViewModel.Title;

            //ViewModel.PropertyChanged += IsBusy_PropertyChanged;
            //ViewModel.Authors.CollectionChanged += Items_CollectionChanged;
        }
コード例 #25
0
 public IEnumerable <GeneralInformation> GetPublicationsByAuthors(AuthorsViewModel model)
 {
     return(this.GetPublicationsByAuthorIds(model.Authors));
 }
コード例 #26
0
 public AddAuthorCommand(AuthorsViewModel VM)
 {
     vm = VM;
 }
コード例 #27
0
 public AuthorTheseus()
 {
     InitializeComponent();
     DataContext = new AuthorsViewModel();
 }
コード例 #28
0
 public DeleteAuthorCommand(AuthorsViewModel VM)
 {
     vm = VM;
 }
コード例 #29
0
 public AuthorDetailPage()
 {
     InitializeComponent();
     BindingContext = new AuthorsViewModel();
 }
コード例 #30
0
        public async Task <ActionResult <AuthorsViewModel> > PostAuthors([FromBody] AuthorsViewModel author)
        {
            var newAuthor = await _authorsService.Edit(_mapper.Map <AuthorsViewModel, IAuthors>(author));

            return(CreatedAtAction(nameof(Get), new { id = newAuthor.ID }, newAuthor));
        }