Esempio n. 1
0
        public void AddCheckoutToTeam(int serverTeamId, CheckoutEntity checkout)
        {
            TeamEntity team = teamRepository.GetTeamById(serverTeamId);

            if (checkout.ShiftDate.Date != team.ShiftDate.Date)
            {
                throw new InvalidOperationException("You cannot add a checkout to a team with different shift dates.");
            }

            TeamCheckoutEntity addedCheckout = new TeamCheckoutEntity
            {
                Team      = team,
                Checkout  = checkout,
                ShiftDate = checkout.ShiftDate
            };

            if (teamRepository.CheckoutHasAlreadyBeenAdded(checkout.Id, checkout.ShiftDate))
            {
                throw new InvalidOperationException("That checkout is currently on another team");
            }

            teamRepository.AddCheckoutToTeam(addedCheckout);

            if (!teamRepository.Save())
            {
                throw new Exception("An unexpected error occured while trying to add the checkout to the team.");
            }
        }