public virtual ActionResult Edit(LendViewModel viewModel) { //get data from DB var model = _lendRepository.GetLendByID(viewModel.Id); var updatedLendmodel = _mapper.Map <LendViewModel, Lend>(viewModel); //updating values to model model.From = updatedLendmodel.From; model.To = updatedLendmodel.To; _lendRepository.UpdateLend(model); return(RedirectToAction("Index")); }
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)); }