public BorrowResult BorrowBook(RelationUserBookCopyViewModel viewModel, UserSessionObject user) { var result = new BorrowResult(); viewModel.DateOfIssue = DateTime.Now; viewModel.DateDueForReturn = DateTime.Now.AddDays(14); RelationUserBookCopyDomainModelBuilder builder = BuilderResolverService.Get <RelationUserBookCopyDomainModelBuilder, RelationUserBookCopyViewModel>(viewModel); Constructor.ConstructDomainModelData(builder); RelationUserBookCopyData domainModel = builder.GetDataModel(); if (viewModel.Id == 0) { domainModel.RefUserCreatedBy = user.UserId; } int loanId = RelationUserBookCopyRepository.SaveData(domainModel); if (loanId != 0) { var saveResult = UpdateCopyAndBook(domainModel.BookCopyId, user); if (saveResult.Success) { string username = UserService.Get(domainModel.UserId).Username; result = new BorrowResult(loanId, domainModel.BookCopyId, username); } } return(result); }
public ActionResult Borrow(RelationUserBookCopyViewModel viewModel) { UserSessionObject user = Session.GetUser(); JsonResult response = (JsonResult)RouteData.Values["validation"]; ValidationResponse validation = (ValidationResponse)response.Data; if (validation.Success) { viewModel.Id = 0; BorrowResult result = LoanService.BorrowBook(viewModel, user); response.Data = result; } return(response); }
public RelationUserBookCopyViewModel CreateLoanModel(int bookCopyId) { BookCopyData copy = BookCopyRepository.GetDataById(bookCopyId); BookData book = BookRepository.GetDataById(copy.BookId); var viewModel = new RelationUserBookCopyViewModel { BookCopyId = bookCopyId, BookFullName = book.BookAuthorAndTitle, DateOfIssue = DateTime.Now, DateDueForReturn = DateTime.Now.AddDays(14) }; return(viewModel); }