public List <JournalViewModel> GetJournals(PublishingHouseViewModel phvm) { IEnumerable <int> journalsId = _journalPublishingHouseRepository.GetAll().Where(h => h.PublishingHouseId == phvm.Id).Select(h => h.JournalId).ToList(); var a = from b in _journalRepository.GetAll().ToList() from t in journalsId where b.Id == t select b; var res = a.Select(b => new JournalViewModel { Id = b.Id, Name = b.Name, Date = b.Date, Authors = (from at in _authorRepository.GetAll().ToList() from ba in _journalAuthorRepository.GetAll().ToList() where ba.JournalId == b.Id where ba.AuthorId == at.Id select new AuthorViewModel { Id = at.Id, FullName = at.Name + " " + at.Surname }).ToList(), PublishingHouses = (from ph in _publishingHouseRepository.GetAll().ToList() from bph in _journalPublishingHouseRepository.GetAll().ToList() where bph.JournalId == b.Id where bph.PublishingHouseId == ph.Id select new PublishingHouseViewModel { Id = ph.Id, Name = ph.Name }).ToList() }).ToList(); return(res); }
public List <NewspaperViewModel> GetNewspapers(PublishingHouseViewModel phvm) { IEnumerable <int> newspaperId = _newspaperPublishingHouseRepository.GetAll().Where(h => h.PublishingHouseId == phvm.Id).Select(h => h.NewspaperId).ToList(); var a = from b in _newspaperRepository.GetAll().ToList() from t in newspaperId where b.Id == t select b; var res = a.Select(b => new NewspaperViewModel { Id = b.Id, Name = b.Name, Date = b.Date, Authors = (from at in _authorRepository.GetAll().ToList() from na in _newspaperAuthorRepository.GetAll().ToList() where na.NewspaperId == b.Id where na.AuthorId == at.Id select new AuthorViewModel { Id = at.Id, FullName = at.Name + " " + at.Surname }).ToList(), PublishingHouses = (from ph in _publishingHouseRepository.GetAll().ToList() from bph in _newspaperPublishingHouseRepository.GetAll().ToList() where bph.NewspaperId == b.Id where bph.PublishingHouseId == ph.Id select new PublishingHouseViewModel { Id = ph.Id, Name = ph.Name }).ToList() }).ToList(); return(res); }
public void UpdatePublishingHouse(PublishingHouseViewModel ph) { var mappedph = mapper.Map <PublishingHouseViewModel, PublishingHouse>(ph); db.PublishingHouses.Update(mappedph); db.Save(); }
public int CreatePublishingHouse(PublishingHouseViewModel ph) { var mappedph = mapper.Map <PublishingHouseViewModel, PublishingHouse>(ph); var newId = db.PublishingHouses.Create(mappedph); db.Save(); return(newId); }
public void AddPublishingHouse(PublishingHouseViewModel pvm) { PublishingHouse publishingHouse = new PublishingHouse { Name = pvm.Name, }; _publishingHouseRepository.Create(publishingHouse); }
public ActionResult Create(PublishingHouseViewModel ph) { if (!ModelState.IsValid) { return(View(ph)); } var id = service.CreatePublishingHouse(ph); return(RedirectToAction("Details", new { id })); }
public IHttpActionResult Data(int id) { List <SearchViewModel> svm = new List <SearchViewModel>(); PublishingHouseViewModel phvm = new PublishingHouseViewModel { Id = _publishingHouseService.Find(id).Id, Name = _publishingHouseService.Find(id).Name }; List <BookViewModel> bvm = _bookService.GetBooks(phvm); List <JournalViewModel> jvm = _journalService.GetJournals(phvm); List <NewspaperViewModel> nvm = _newspaperService.GetNewspapers(phvm); svm.AddRange(bvm.Select(t => new SearchViewModel { Id = (int)t.Id, Type = "Book", Date = t.Date, Name = t.Name, Authors = t.Authors, PublishingHouses = t.PublishingHouses })); svm.AddRange(jvm.Select(t => new SearchViewModel { Id = (int)t.Id, Type = "Journal", Date = t.Date, Name = t.Name, Authors = t.Authors, PublishingHouses = t.PublishingHouses })); svm.AddRange(nvm.Select(t => new SearchViewModel { Id = (int)t.Id, Type = "Newspaper", Date = t.Date, Name = t.Name, Authors = t.Authors, PublishingHouses = t.PublishingHouses })); return(Ok(svm)); }
public void UpdatePublishingHouse(PublishingHouseViewModel pvm) { _publishingHouseRepository.Update(new PublishingHouse { Id = (int)pvm.Id, Name = pvm.Name }); }
public PublishingHouseViewModel Create([FromBody] PublishingHouseViewModel PublishingHouse) { var id = service.CreatePublishingHouse(PublishingHouse); return(service.GetPublishingHouseViewModel(id)); }
public PublishingHouseViewModel Edit([FromBody] PublishingHouseViewModel PublishingHouse) { service.UpdatePublishingHouse(PublishingHouse); return(service.GetPublishingHouseViewModel(PublishingHouse.Id)); }
public ActionResult Edit(PublishingHouseViewModel ph) { service.UpdatePublishingHouse(ph); return(RedirectToAction("Details", new { id = ph.Id })); }