public void UpdateAllowedNumberOfPeople(Trip trip, int newNumberOfPeople) { //TODO : Notification to user's for the change //TODO : Repayment for users is newNumberOfPeople is increasing //TODO : Update has payed flag if newNumberOfPeople is decreasing Errors.Clear(); var oldNumberOfPeople = trip.NumberMaxOfPeople; using (var scope = new TransactionScope()) { try { // 1 - Update User pot amotunt foreach (var potUser in _potUserRepository.GetPotUsers(trip.TripPot.Id)) { potUser.TargetAmount = trip.Price / newNumberOfPeople; _potUserRepository.UpdatePotUser(potUser); if (_potUserRepository.HasErrors) { Errors.Add("Unable to update pot user informations"); MergeErrors(_potUserRepository); return; } } // 2 - update trip trip.NumberMaxOfPeople = newNumberOfPeople; _tripRepository.UpdateTrip(trip); if (_tripRepository.HasErrors) { trip.NumberMaxOfPeople = oldNumberOfPeople; Errors.Add("Unable to update trip"); MergeErrors(_tripRepository); return; } scope.Complete(); } catch (Exception ex) { trip.NumberMaxOfPeople = oldNumberOfPeople; HandleException(ex); } } }
public Pot GetPot(int potId) { Errors.Clear(); try { // 1 - pot var pot = _potRepository.GetPot(potId); if (pot == null || _potRepository.HasErrors) { Errors.Add(string.Format("Unable to find pot with id : {0}", potId)); MergeErrors(_potRepository); return(null); } // 2 - Pot members var potMembers = _potUserRepository.GetPotUsers(pot.Id); if (_potUserRepository.HasErrors) { Errors.Add(string.Format("Unable to find users for pot with id : {0}", potId)); MergeErrors(_potUserRepository); return(null); } foreach (var user in potMembers) { pot.AddParticipant(user); } return(pot); } catch (Exception ex) { HandleException(ex); return(null); } }