public SaveBookResult Save(BookCopyViewModel viewModel, UserSessionObject user) { var result = new SaveBookResult(); BookCopyDomainModelBuilder builder = BuilderResolverService.Get <BookCopyDomainModelBuilder, BookCopyViewModel>(viewModel); Constructor.ConstructDomainModelData(builder); BookCopyData domainModel = builder.GetDataModel(); if (viewModel.Id == 0) { domainModel.RefUserCreatedBy = user.UserId; } int id = BookCopyRepository.SaveData(domainModel); if (id != 0) { BookViewModel bookViewModel = Get(viewModel.BookId); bookViewModel.NumOfAvailableCopies = bookViewModel.NumOfAvailableCopies + 1; SaveBookResult updateResult = Save(bookViewModel, user); if (updateResult.Success) { result = new SaveBookResult(id, viewModel.BookAuthorAndTitle, "Successfully added copy of book " + viewModel.BookAuthorAndTitle); } } return(result); }
public ActionResult Form(int id) { var viewModel = new BookCopyViewModel(); var referencingBook = BookService.Get(id); viewModel.BookId = id; viewModel.BookAuthorAndTitle = referencingBook.AuthorAndTitle; return(PartialView("BookCopyForm", viewModel)); }
public BookCopyViewModel GetCopy(int?bookCopyId) { var viewModel = new BookCopyViewModel(); if (bookCopyId.HasValue) { BookCopyData domainModel = BookCopyRepository.GetDataById(bookCopyId.Value); BookCopyViewModelBuilder builder = BuilderResolverService.Get <BookCopyViewModelBuilder, BookCopyData>(domainModel); Constructor.ConstructViewModelData(builder); viewModel = builder.GetViewModel(); } return(viewModel); }
public ActionResult Save(BookCopyViewModel viewModel) { UserSessionObject user = Session.GetUser(); JsonResult response = (JsonResult)RouteData.Values["validation"]; ValidationResponse validation = (ValidationResponse)response.Data; if (validation.Success) { viewModel.Id = 0; viewModel.Available = true; SaveBookResult result = BookService.Save(viewModel, user); response.Data = result; } return(response); }
private SaveBookResult UpdateCopyAndBook(int copyId, UserSessionObject user) { var result = new SaveBookResult(); BookCopyViewModel bookCopyData = BookService.GetCopy(copyId); bookCopyData.Available = false; result = BookService.SaveOnly(bookCopyData, user); if (result.Success) { BookViewModel bookData = BookService.Get(bookCopyData.BookId); bookData.NumOfAvailableCopies = bookData.NumOfAvailableCopies - 1; result = BookService.Save(bookData, user); } return(result); }
public static BookCopyViewModel MapToCopyViewModel(this Book book) { var vm = new BookCopyViewModel(); vm.Title = book.Title; vm.Status = book.Status.ToString(); vm.Isbn = book.ISBN; if (book.ReservedBooks != null) { var resUsers = new List <User>(); book.ReservedBooks.ForEach(x => resUsers.Add(x.User)); vm.ReservedBy = resUsers; } if (book.CheckedoutBook != null) { vm.CheckedOutBy = book.CheckedoutBook.User; } return(vm); }
public SaveBookResult SaveOnly(BookCopyViewModel viewModel, UserSessionObject user) { var result = new SaveBookResult(); BookCopyDomainModelBuilder builder = BuilderResolverService.Get <BookCopyDomainModelBuilder, BookCopyViewModel>(viewModel); Constructor.ConstructDomainModelData(builder); BookCopyData domainModel = builder.GetDataModel(); if (viewModel.Id == 0) { domainModel.RefUserCreatedBy = user.UserId; } int id = BookCopyRepository.SaveData(domainModel); if (id != 0) { result = new SaveBookResult(id, domainModel.BookId.ToString()); } return(result); }
public ActionResult FormComplex() { var viewModel = new BookCopyViewModel(); return(PartialView("BookCopyFormComplex", viewModel)); }