public async Task <IActionResult> UpdateShip(IFormCollection request) { ShipType ship = await _Db.ShipTypes.FindAsync(request._int("ship_id")); ship.Queue = (Queue)request._int("queue_id"); await _Db.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> NewShip(IFormCollection request) { string hullType = request._str("ship_name"); int queue_id = request._int("queue_id"); ShipType ship = await _Db.ShipTypes.Where(c => c.Name.ToLower() == hullType.ToLower()).FirstOrDefaultAsync(); if (ship != null) { ship.Queue = (Queue)queue_id; await _Db.SaveChangesAsync(); return(Accepted()); } SearchResults x = await EsiWrapper.Search(hullType, true, SearchCategory.InventoryType); if (x.InventoryTypes == null) { return(NotFound($"{hullType} could not be found. Is the name spelt correctly?")); } await _Db.AddAsync(new ShipType { Id = (int)x.InventoryTypes[0], Name = hullType, Queue = (Queue)queue_id }); await _Db.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Comms(IFormCollection request, int fleetId) { var fleet = await _Db.Fleets.Where(c => c.Id == fleetId && c.ClosedAt == null).FirstOrDefaultAsync(); if (fleet == null) { // Fleet not found return(NotFound("Fleet not found.")); } int commsId = request._int("commsId"); CommChannel comm = await _Db.CommChannels.FindAsync(commsId); if (comm == null) { return(BadRequest("Comms setting is invalid")); } try { fleet.CommChannel = comm; await _Db.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { _Logger.LogError("Cannot change the fleet comms (Fleet ID: {0}) channel {1} {2}.", fleet.Id, comm.LinkText, ex.Message); return(BadRequest("Error setting fleet comms.")); } }
public async Task <IActionResult> Boss(IFormCollection request, int fleetId) { var fleet = await _Db.Fleets.Where(c => c.Id == fleetId && c.ClosedAt == null).FirstOrDefaultAsync(); if (fleet == null) { // Fleet not found return(NotFound("Fleet not found.")); } int bossId = request._int("pilotId"); var pilot = await _Db.Pilots.Where(c => c.CharacterID == bossId && c.AccountId == User.AccountId()).FirstOrDefaultAsync(); if (pilot == null) { return(BadRequest("The pilot was not found, or you do not have permission to complete this request.")); } try { fleet.BossPilot = pilot; await _Db.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { _Logger.LogError("Cannot change the fleet boss (Fleet ID: {0}) to {1} {2}.", fleet.Id, pilot.CharacterName, ex.Message); return(BadRequest("Error setting fleet boss.")); } }
public async Task <IActionResult> SetDestination(IFormCollection request) { int target_id = request._int("target_id"); Pilot pilot = await _Db.Pilots.FindAsync(Request.Cookies.PreferredPilotId()); await pilot.UpdateToken(); EsiWrapper.SetDestination((AuthorizedCharacterData)pilot, target_id); await _Db.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Leave(IFormCollection request) { List <WaitingPilot> waitingPilots; if (request._str("pilot_id") == "") { waitingPilots = await _Db.WaitingPilots.Include(c => c.Pilot).Where(c => c.Pilot.AccountId == User.AccountId() && c.RemovedByAccount == null).ToListAsync(); } else { waitingPilots = await _Db.WaitingPilots.Where(c => c.PilotId == request._int("pilot_id") && c.RemovedByAccount == null).ToListAsync(); } foreach (WaitingPilot pilot in waitingPilots) { pilot.RemovedByAccountId = User.AccountId(); } await _Db.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Join(IFormCollection request) { int pilotId = request._str("pilot_id") == "" ? Request.Cookies.PreferredPilotId() : request._int("pilot_id"); List <int> roleIds = request._str("role_ids") != "" ? request._str("role_ids").Split(',').Select(item => int.Parse(item)).ToList() : new List <int>(); List <int> fitIds = request._str("fit_ids").Split(',').Select(item => int.Parse(item)).ToList(); Pilot pilot = await _Db.Pilots.FindAsync(pilotId); if (pilot == null) { return(NotFound("Pilot not found")); } if (fitIds.Count == 0) { return(BadRequest("You must select a fit before you can join the waitlist")); } try { WaitingPilot waitlist = new WaitingPilot { PilotId = pilot.CharacterID, SelectedFits = null, SelectedRoles = null, RemovedByAccountId = null, NewPilot = false, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow }; await _Db.AddAsync(waitlist); foreach (int id in fitIds) { await _Db.AddAsync(new SelectedFit { FitId = id, WaitingPilotId = waitlist.Id }); } // Add Roles foreach (int id in roleIds) { await _Db.AddAsync(new SelectedRole { FleetRoleId = id, WaitingPilotId = waitlist.Id }); } await _Db.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { _Logger.LogWarning("{0} could not be added to the waitlist: {1}", pilot.CharacterName, ex.Message); return(BadRequest($"Could not add {pilot.CharacterName} to the waitlist {ex.Message}")); } }
public async Task <IActionResult> Index(IFormCollection request) { string EsiUrl = request._str("EsiFleetUrl"); long fleetId; try { fleetId = request._str("EsiFleetUrl").GetEsiId(); } catch (Exception ex) { _Logger.LogError("Cannot parse the ESI Fleet ID from the URL provided. {0}", EsiUrl); return(BadRequest(string.Format("Cannot parse the ESI Fleet ID from the URL provided. {0}\n{1}", EsiUrl, ex.Message))); } int bossId = request._int("fleetBoss"); Pilot pilot = await _Db.Pilots.Where(c => c.CharacterID == bossId && c.AccountId == User.AccountId()).FirstOrDefaultAsync(); if (pilot == null) { return(NotFound("Pilot not found, or you do not have access to it.")); } string fleetType = request._str("FleetType"); //Is there an active fleet with this ID? IF yes redirect to that fleet else continue var fleet = await _Db.Fleets.Where(c => c.EveFleetId == fleetId && c.ClosedAt == null).FirstOrDefaultAsync(); if (fleet != null) { // Fleet already registered let's redirect the user to that page. return(Ok(fleet.Id)); } CommChannel comms = await _Db.CommChannels.FindAsync(request._int("FleetComms")); if (comms == null) { // Fleet comms not found _Logger.LogError("Invalid Comms channel provided."); } // TODO: Can we actually ESI into this fleet? if (false) { _Logger.LogWarning("(ID: {0}) does not have access to fleet {1}.", bossId, fleetId); return(Forbid("Pilot selected does not have access to that fleet. Check you selected the correct fleet boss!")); } Fleet newFleet = new Fleet { EveFleetId = fleetId, BossPilot = pilot, CommChannelId = comms.Id, IsPublic = false, Type = fleetType, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow }; await _Db.AddAsync(newFleet); await _Db.SaveChangesAsync(); // Redirect to page! return(Ok(newFleet.Id)); }