public List <Earnings> RunBarTeamCheckout(DateTime shiftDate, string lunchOrDinner, int barBackCount) { TeamEntity barTeam = _teamRepository.GetBarTeamForShift(shiftDate, lunchOrDinner); BarTeam team = Mapper.Map <BarTeam>(barTeam); List <CheckoutEntity> checkouts = _checkoutRepository.GetCheckoutsForATeam(team.Id).ToList(); foreach (CheckoutEntity c in checkouts) { Checkout chkout = Mapper.Map <Checkout>(c); team.Checkouts.Add(chkout); } List <TipOutEntity> serverTipOuts = _teamRepository.GetTipOuts(shiftDate, lunchOrDinner, "server"); decimal serverTips = 0; foreach (TipOutEntity t in serverTipOuts) { serverTips += t.BarTipOut; } if (team.CheckoutHasBeenRun == true) { _teamRepository.DeleteTipOut(team.Id); } List <Earnings> teamEarnings = team.RunBarCheckout(serverTips, barBackCount); TipOutEntity tipoutEntity = Mapper.Map <TipOutEntity>(team.TipOut); tipoutEntity.Team = barTeam; _teamRepository.AddTipOut(tipoutEntity); return(teamEarnings); }
public void DeleteTeamCheckout(TeamEntity team) { TipOutEntity tipOutEntity = _context.TipOuts.Where(t => t.TeamId == team.Id).FirstOrDefault(); if (tipOutEntity == null) { return; } else { _context.TipOuts.Remove(tipOutEntity); } }
public TipOutDto GetServerTeamTipOut(int serverTeamId) { if (!teamRepository.TeamExists(serverTeamId)) { throw new KeyNotFoundException("No team with the provided ID was found."); } TeamEntity team = teamRepository.GetTeamById(serverTeamId); if (team.CheckoutHasBeenRun == false) { throw new InvalidOperationException("No tipout exists for the team because their checkout has not be run"); } TipOutEntity tipOutEntity = teamRepository.GetTeamTipOut(serverTeamId); return(Mapper.Map <TipOutDto>(tipOutEntity)); }
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)); }
public void AddTipOut(TipOutEntity tipOut) { _context.TipOuts.Add(tipOut); }