Пример #1
0
 private void AddDiscussionsToClubIndexViewModel(ClubIndexViewModel viewModel)
 {
     viewModel.Discussions = db.Discussions.Where(d => d.ClubId == viewModel.Club.Id).OrderByDescending(d => d.StartTime).ToList();
     foreach (Discussion discussion in viewModel.Discussions)
     {
         BookDiscussions bookDiscussions = db.BookDiscussions.Include("Book").FirstOrDefault(bd => bd.DiscussionId == discussion.Id);
         discussion.Book = bookDiscussions.Book;
     }
 }
Пример #2
0
 public ActionResult Create(NewDiscussionViewModel viewModel)
 {
     try
     {
         DateTime Start = new DateTime
                          (
             viewModel.Date.Year,
             viewModel.Date.Month,
             viewModel.Date.Day,
             viewModel.StartTime.Hour,
             viewModel.StartTime.Minute,
             0
                          );
         if ((Start - DateTime.Now).Ticks < 0)
         {
             return(View(viewModel));
         }
         Book       book       = db.Books.Find(viewModel.Book.Id);
         Discussion discussion = new Discussion
         {
             Id        = Guid.NewGuid(),
             ClubId    = viewModel.ClubId,
             Name      = viewModel.Name,
             StartTime = Start,
             Date      = Start.Date
         };
         BookDiscussions bookDiscussions = new BookDiscussions
         {
             Id         = Guid.NewGuid(),
             Book       = book,
             Discussion = discussion
         };
         db.Discussions.Add(discussion);
         db.BookDiscussions.Add(bookDiscussions);
         BookClub club = db.BookClubs.Find(viewModel.ClubId);
         club.NextBook = book;
         db.SaveChanges();
         return(RedirectToAction("Index", "Club", new { id = viewModel.ClubId }));
     }
     catch
     {
         return(View(viewModel));
     }
 }