public async Task <bool> Handle(CreateQuarryCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.FiefId, out Guid id)) { var fief = await _context.Fiefs.FindAsync(id); var quarry = new Quarry { Fief = fief, QuarryTypeId = request.QuarryTypeId, IsFirstYear = true, IsBeingDeveloped = false, YearsLeft = request.YearsLeft }; fief.Industries.Add(quarry); await _context.SaveChangesAsync(cancellationToken); return(true); throw new CustomException($"CreateQuarryCommand >> Unauthorized!"); } throw new CustomException($"CreateQuarryCommand >> Could not parse FiefId({request.FiefId})."); }
public async Task <bool> Handle(UpdateRoadCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.FiefId, out Guid id)) { var fief = await _context.Fiefs.FindAsync(id); if (fief != null) { var roadType = await _context.RoadTypes.Where(o => o.Type == request.newRoad).FirstAsync(); fief.Road.RoadType = roadType; fief.Road.RoadTypeId = roadType.RoadTypeId; await _context.SaveChangesAsync(cancellationToken); return(true); } else { return(false); } } return(false); }
public async Task <GameSession> Handle(CreateGameSessionCommand request, CancellationToken cancellationToken) { var gameSession = new GameSession(); if (_user == "00000000-0000-0000-0000-000000000000") { gameSession.User = "******"; } else { gameSession.User = _user; } var count = _context.GameSessions.Where(o => o.User == gameSession.User).Count(); gameSession.Name = $"Session{++count}"; var fief = gameSession.Fiefs.FirstOrDefault(); if (fief != null) { fief.Name = "Förläning 1"; } _context.GameSessions.Add(gameSession); await _context.SaveChangesAsync(cancellationToken); return(gameSession); }
public async Task <bool> Handle(DeleteQuarryCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.IndustryId, out Guid id)) { var quarry = (Quarry)await _context.Industries.FindAsync(id); if (quarry == null) { throw new CustomException($"DeleteQuarryCommand >> Quarry({id}) could not be found!"); } var fief = await _context.Fiefs.FindAsync(quarry.Fief.FiefId); if (fief == null) { throw new CustomException($"DeleteQuarryCommand >> Fief({quarry.Fief.FiefId}) could not be found!"); } fief.Industries.Remove(quarry); await _context.SaveChangesAsync(cancellationToken); return(true); throw new CustomException($"DeleteQuarryCommand >> Unauthorized!"); } throw new CustomException($"DeleteQuarryCommand >> Could not parse IndustryId({request.IndustryId})."); }
public async Task <bool> Handle(CreateTaxCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.FiefId, out Guid id)) { var fief = await _context.Fiefs.FindAsync(id); if (fief == null) { throw new CustomException($"CreateTaxCommand >> Could not find Fief({fief.FiefId})."); } var tax = new Tax { Name = request.TaxName }; fief.Industries.Add(tax); await _context.SaveChangesAsync(cancellationToken); return(true); throw new CustomException($"CreateTaxCommand >> Unauthorized!"); } throw new CustomException($"CreateTaxCommand >> Could not parse FiefId({request.FiefId})."); }
public async Task <bool> Handle(DeleteGameSessionCommand request, CancellationToken cancellationToken) { var session = await _context.GameSessions.Where(o => o.GameSessionId.ToString() == request.GameSessionId).FirstOrDefaultAsync(); _context.GameSessions.Remove(session); await _context.SaveChangesAsync(cancellationToken); return(true); }
public async Task <bool> Handle(UpdateGameSessionCommand request, CancellationToken cancellationToken) { var gameSession = await _context.GameSessions.Where(o => o.GameSessionId.ToString() == request.GameSessionId).FirstAsync(); if (gameSession != null) { gameSession.Name = request.Name; await _context.SaveChangesAsync(cancellationToken); return(true); } return(false); }
public async Task <bool> Handle(DeleteFellingCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.IndustryId, out Guid id)) { var industry = await _context.Industries.FindAsync(id); _context.Industries.Remove(industry); await _context.SaveChangesAsync(cancellationToken); return(true); } return(false); }
public async Task <StewardLookupDto> Handle(CreateStewardCommand request, CancellationToken cancellationToken) { var session = await _context.GameSessions.FindAsync(request.GameSessionId); if (session != null) { var steward = new Steward(); session.Stewards.Add(steward); await _context.SaveChangesAsync(cancellationToken); return(_mapper.Map <StewardLookupDto>(steward)); } return(null); }
public async Task <bool> Handle(CreateFellingCommand request, CancellationToken cancellationToken) { var fief = _context.Fiefs.Where(o => o.FiefId.ToString() == request.FiefId).First(); if (fief != null) { var felling = new Felling(); fief.Industries.Add(felling); await _context.SaveChangesAsync(cancellationToken); return(true); } return(false); }
public async Task <bool> Handle(DeleteVillageCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.VillageId, out Guid villageId) && Guid.TryParse(request.FiefId, out Guid fiefId)) { var village = await _context.Villages.FindAsync(villageId); var fief = await _context.Fiefs.FindAsync(fiefId); fief.Villages.Remove(village); _context.Villages.Remove(village); await _context.SaveChangesAsync(cancellationToken); return(true); } return(false); }
public async Task <bool> Handle(CreateVillageCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.FiefId, out Guid id)) { var fief = await _context.Fiefs.FindAsync(id); var count = fief.Villages.Count; fief.Villages.Add(new Village { Name = $"By{count}" }); await _context.SaveChangesAsync(cancellationToken); return(true); } else { return(false); } }
public async Task <bool> Handle(DeleteFiefCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.FiefId, out Guid id)) { var fief = await _context.Fiefs.FindAsync(id); if (fief != null) { _context.Fiefs.Remove(fief); await _context.SaveChangesAsync(cancellationToken); return(true); } // FiefId could not be found!"); return(false); } else { // Could not parse FiefId to a valid Guid. return(false); } }
public async Task <FiefLookupDto> Handle(CreateFiefCommand request, CancellationToken cancellationToken) { if (Guid.TryParse(request.GameSessionId, out Guid id)) { var session = await _context.GameSessions.FindAsync(id); if (session != null) { if (session.User == _user) { var count = session.Fiefs.Count; var fief = new Fief { Name = $"Förläning {count++}" }; session.Fiefs.Add(fief); await _context.SaveChangesAsync(cancellationToken); fief.Livingcondition.LivingconditionType = await _context.LivingconditionTypes.Where(o => o.LivingconditionTypeId == 3).FirstAsync(); fief.Road.RoadType = await _context.RoadTypes.Where(o => o.RoadTypeId == 2).FirstAsync(); fief.Inheritance.InheritanceType = await _context.InheritanceTypes.Where(o => o.InheritanceTypeId == 1).FirstAsync(); return(_mapper.Map <FiefLookupDto>(fief)); } // GameSession does not belong to the user. return(null); } // GameSession with id could not be found. return(null); } // GameSessionId could not be parsed to a Guid. return(null); }