public async Task <IActionResult> Create(AddTravelViewModel viewModel) { var travel = viewModel.ToTravel(); var user = await GetCurrentDomainUserAsync(); var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var userRepository = RepositoriesFactory.CreateUserRepository(unitOfWork); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); var currencyRepository = RepositoriesFactory.CreateCurrencyRepository(unitOfWork); unitOfWork.BeginTransaction(); travel.Traveller = userRepository.GetUser(user.Id); var currency = currencyRepository.GetById(viewModel.BudgetCurrencyId); if (viewModel.BudgetValue > 0 && currency != null) { travel.Budget = new MoneyValue { Value = viewModel.BudgetValue, Currency = currency }; } travelRepository.AddTravel(travel); unitOfWork.Commit(); return(RedirectToAction("Index")); }
public void AddTravel(AddTravelViewModel model) { var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var userRepository = RepositoriesFactory.CreateUserRepository(unitOfWork); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); try { unitOfWork.BeginTransaction(); var user = userRepository.GetUser(_mainController.LoggedInUserId); var travel = new Travel { Name = model.Name, Description = model.Description, DateStart = model.DateStart, DateEnd = model.DateEnd, Budget = model.Budget, Traveller = user }; travelRepository.AddTravel(travel); unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); MessageBox.Show(ex.Message, "TravelBuddy"); } }
public async Task <IActionResult> Edit(EditTravelViewModel viewModel) { var user = await GetCurrentDomainUserAsync(); var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); var currencyRepository = RepositoriesFactory.CreateCurrencyRepository(unitOfWork); unitOfWork.BeginTransaction(); var travel = travelRepository.GetTravel(viewModel.Id); var currency = currencyRepository.GetById(viewModel.BudgetCurrencyId); travel.Name = viewModel.Name; travel.DateStart = viewModel.DateStart; travel.DateEnd = viewModel.DateEnd; travel.Description = viewModel.Description; if (viewModel.BudgetValue > 0 && currency != null) { travel.Budget = new MoneyValue { Value = viewModel.BudgetValue, Currency = currency }; } travelRepository.UpdateTravel(travel); unitOfWork.Commit(); return(RedirectToAction("Index")); }
public void SaveEditedTravel(EditTravelViewModel travelModel) { var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); try { unitOfWork.BeginTransaction(); var travel = travelRepository.GetTravel(travelModel.Id); travel.Name = travelModel.Name; travel.Description = travelModel.Description; travel.DateStart = travelModel.DateStart; travel.DateEnd = travelModel.DateEnd; travel.Budget = travelModel.Budget; travelRepository.UpdateTravel(travel); unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); MessageBox.Show(ex.Message, "TravelBuddy"); } }
public void OpenTravelDetails(Guid travelId) { var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); try { unitOfWork.BeginTransaction(); var travel = travelRepository.GetTravel(travelId); var travelModal = new TravelViewModel { Id = travel.Id, Name = travel.Name, Description = travel.Description, DateStart = travel.DateStart, DateEnd = travel.DateEnd, Budget = travel.Budget }; unitOfWork.Commit(); var travelDetailsView = _formsFactory.CreateTravelDetailsView(this, travelModal); travelDetailsView.ShowModaless(); } catch (Exception ex) { unitOfWork.Rollback(); MessageBox.Show(ex.Message, "TravelBuddy"); } }
public void AddPreliminaryActivity(AddPreliminaryActivityViewModel travelItemViewModel, Guid travelId) { var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); try { unitOfWork.BeginTransaction(); var travel = travelRepository.GetTravel(travelId); travel.PreliminaryActivityList.Add(new PreliminaryActivity { Name = travelItemViewModel.Name, Description = travelItemViewModel.Description, IsCompleted = travelItemViewModel.IsCompleted }); travelRepository.UpdateTravel(travel); unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); MessageBox.Show(ex.Message, "TravelBuddy"); } }
public IActionResult Edit(Guid id) { var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); var currencyRepository = RepositoriesFactory.CreateCurrencyRepository(unitOfWork); unitOfWork.BeginTransaction(); var viewModel = new EditTravelViewModel(travelRepository.GetTravel(id)); viewModel.Id = id; currencyRepository.CreateCurrenciesIfNoneExist(); viewModel.CurrencyOptions = currencyRepository.GetAll(); unitOfWork.Commit(); return(View(viewModel)); }
public void DeleteTravel(Guid travelId) { var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); try { unitOfWork.BeginTransaction(); travelRepository.DeleteTravel(travelId); unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); MessageBox.Show(ex.Message, "TravelBuddy"); } }
public void OpenTravelItemListWindow(Guid travelId) { var unitOfWork = UnitOfWorkFactory.CreateUnitOfWork(); var travelRepository = RepositoriesFactory.CreateTravelRepository(unitOfWork); try { unitOfWork.BeginTransaction(); var travel = travelRepository.GetTravel(travelId); var travelItemList = new List <TravelItem>(travel.ItemList); _formsFactory.CreateTravelItemListView(this, travelItemList, travel.Id).ShowModaless(); unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); MessageBox.Show(ex.Message, "TravelBuddy"); } }