// GET: LendItems/Details/5 public virtual ActionResult Details(int Id) { var model = _lendItemRepository.GetLendItemByID(Id); if (model == null) { return(RedirectToAction(Actions.Index())); } LendItemViewModel vm = _mapper.Map <LendItem, LendItemViewModel>(model); vm.CreatedBy = model.User; vm.Description = model.Description; //get images if (vm.FileId != null) { var lenditemImages = _fileRepository.GetFileById(vm.FileId.Value); List <FileViewModel> listimages = new List <FileViewModel>(); FileViewModel itemFileVM = _mapper.Map <File, FileViewModel>(lenditemImages); listimages.Add(itemFileVM); //add images to Item VM vm.ItemImageViewModels = listimages.AsEnumerable(); } return(View(vm)); }
public virtual ActionResult Create(LendViewModel lendVM) { if (ModelState.IsValid) { lendVM.CreatedAt = DateTime.Now; //get currently logged in user var dbUser = General.GetCurrentUser(_userRepository); var model = _mapper.Map <LendViewModel, Lend>(lendVM); model.UserId = dbUser.Id; _lendRepository.InsertLend(model); //update Availability of LendItem var lenditem = _lendItemRepository.GetLendItemByID(lendVM.LendItemId); lenditem.Avialable--; _lendItemRepository.UpdateLendItem(lenditem); return(RedirectToAction("Index")); } return(View(lendVM)); }
public virtual ActionResult Create(LendReturnViewModel lendReturnVM, HttpPostedFileBase uploadfile) { //todo refactoring and improvement§ if (ModelState.IsValid) { lendReturnVM.UserId = General.GetCurrentUser(_userRepository).Id; lendReturnVM.CreatedBy = General.GetCurrentUser(_userRepository); lendReturnVM.CreatedAt = DateTime.Now; lendReturnVM.FileId = null; //process Return Attached Images if (uploadfile != null) { lendReturnVM.ReturnImageViewModels = ImageInsert.InsertImages(uploadfile).AsEnumerable(); //create Return model var firstOrDefault = lendReturnVM.ReturnImageViewModels.FirstOrDefault(); if (firstOrDefault != null) { lendReturnVM.FileId = firstOrDefault.Id; } } var model = _mapper.Map <LendReturnViewModel, LendReturn>(lendReturnVM); _lendReturnRepository.InsertReturn(model); //get Lend and update it var lendmodel = _lendRepository.GetLendByID(model.LendId); lendmodel.LendReturnId = model.Id; lendmodel.To = DateTime.Now; _lendRepository.UpdateLend(lendmodel); //get LendItem and update availability if (model.SetComplete != null && model.SetComplete.Value) { var lenditemmodel = _lendItemRepository.GetLendItemByID(lendmodel.LendItemId); lenditemmodel.Avialable++; _lendItemRepository.UpdateLendItem(lenditemmodel); } return(RedirectToAction("..\\Lends\\Index")); } return(View(lendReturnVM)); }