Beispiel #1
0
        public IActionResult RunServerTeamCheckout([FromBody] RunServerTeamCheckoutDto data)
        {
            try
            {
                if (!serverTeamsCore.ServerTeamExists(data.ServerTeamId))
                {
                    ModelState.AddModelError("Team ID Not Found", "No team with that ID was found");
                    return(BadRequest(ModelState));
                }

                UtilityMethods.ValidateLunchOrDinnerSpecification(data.LunchOrDinner);
                data.FormattedDate = Convert.ToDateTime(data.StringDate);

                ServerTeamDto         team      = serverTeamsCore.GetServerTeamById(data.ServerTeamId);
                List <StaffMemberDto> teammates = serverTeamsCore.GetStaffMembersOnServerTeam(data.ServerTeamId);

                //need to reset earnings for the staff memebers if the checkout is being updated
                earningsCore.ResetEarningsForServerTeam(teammates, data.FormattedDate, data.LunchOrDinner);


                List <CheckoutEntity> checkouts  = checkoutsCore.GetCheckoutEntitiesForATeam(data.ServerTeamId).ToList();
                EarningDto            earningDto = serverTeamsCore.RunServerTeamCheckout(data, checkouts);
                TipOutDto             tipOutDto  = serverTeamsCore.GetServerTeamTipOut(data.ServerTeamId);

                //The earnings get added to servers here to seperate earnings work into its own section
                List <EarningDto> earnings = earningsCore.AddServerEarning(teammates, earningDto);

                ServerTipOutEarningDto tipoutAndEarning = new ServerTipOutEarningDto
                {
                    TeamTipOut     = tipOutDto,
                    ServerEarnings = earnings
                };

                return(CreatedAtRoute("RunCheckout", tipoutAndEarning));
            }
            catch (Exception e)
            {
                if (e.InnerException is InvalidOperationException)
                {
                    ModelState.AddModelError("Invalid Operation", e.Message);
                    return(BadRequest(ModelState));
                }
                else if (e.InnerException is KeyNotFoundException)
                {
                    ModelState.AddModelError("Key Not Found", e.Message);
                    return(BadRequest(ModelState));
                }
                ModelState.AddModelError("Run CheckoutError", e.Message);
                return(StatusCode(500, ModelState));
            }
        }
Beispiel #2
0
        public EarningDto RunServerTeamCheckout(RunServerTeamCheckoutDto data, List <CheckoutEntity> checkouts)
        {
            TeamEntity teamEntity = teamRepository.GetTeamById(data.ServerTeamId);

            //Check for the team to have an existing tipout, if it does remove it to not have incorrect tipout data.
            if (teamEntity.CheckoutHasBeenRun == true)
            {
                teamRepository.DeleteTipOut(data.ServerTeamId);
                teamEntity.CheckoutHasBeenRun = false;
            }

            ServerTeam team = new ServerTeam(teamEntity.ShiftDate);

            Mapper.Map(teamEntity, team);

            foreach (CheckoutEntity c in checkouts)
            {
                Checkout x = Mapper.Map <Checkout>(c);
                team.CheckOuts.Add(x);
            }

            //The earning is returned from the method called, and a tipout property is set on the team
            Earnings earning = team.RunCheckout()[0];

            //The teams tipout is accessed here and saved to the database
            //The earning is tied to the server and not the checkout, so the earning
            //gets added and saved once this method returns an earning DTO
            TipOutEntity tipOutEntity = Mapper.Map <TipOutEntity>(team.TipOut);

            tipOutEntity.Team = teamEntity;
            teamRepository.AddTipOut(tipOutEntity);
            teamEntity.CheckoutHasBeenRun = true;

            if (!teamRepository.Save())
            {
                throw new Exception("An unexpected error occured while saving the tipout for the team's checkout");
            }

            return(Mapper.Map <EarningDto>(earning));
        }