public async Task <List <CreatureViewModel> > DeleteCreature(int creatureId) { var creature = await dbContext.Creatures.FirstOrDefaultAsync(c => c.Id == creatureId && c.Author.Id == userSession.Player.Id); if (creature != null) { creature.Delisted = true; await dbContext.SaveChangesAsync(); } var query = this.dbContext.Creatures.Where(c => c.IsPlayerCharacter && c.Author.Id == userSession.Player.Id) .OrderBy(c => c.Name); return(await query.Select(r => r.ToViewModel()).ToListAsync()); }
public async Task <FlawViewModel> CreateFlaw([FromBody] FlawViewModel flawVM) { var domainModel = flawVM.ToDomainModel(); if (flawVM.FlawId > 0) // editing an existing feature { //make sure they're the author of this feature var existingFlaw = await this.dbCtx.Flaws.FirstOrDefaultAsync(f => f.Player.Id == userSession.Player.Id && f.Id == flawVM.FlawId); if (existingFlaw != null) { //yep, it's theirs existingFlaw.Delisted = true; } } domainModel.Id = 0; dbCtx.Attach(userSession.Player); domainModel.Player = userSession.Player; domainModel.CreatedAtMS = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); dbCtx.Flaws.Add(domainModel); await dbCtx.SaveChangesAsync(); domainModel.Player = userSession.Player; return(domainModel.ToViewModel()); }
public async Task <ItemViewModel> CreateItem([FromBody] ItemViewModel itemVM) { var domainModel = itemVM.ToDomainModel(); domainModel.CreatedAtMS = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); dbCtx.Attach(userSession.Player); domainModel.Player = userSession.Player; domainModel.Id = 0; var originalSpellsById = domainModel.Enchantments.ToDictionary(e => e.BaseSpellId, e => e.BaseSpell); domainModel.Enchantments.ForEach(e => e.BaseSpell = null); if (itemVM.EquipmentId > 0) // editing an existing feature { //make sure they're the author of this feature var existingItem = await this.dbCtx.Items.FirstOrDefaultAsync(f => f.Player.Id == userSession.Player.Id && f.Id == itemVM.EquipmentId); if (existingItem != null) { //yep, it's theirs existingItem.Delisted = true; domainModel.Enchantments.ForEach(e => e.Id = 0); } } dbCtx.Items.Add(domainModel); await dbCtx.SaveChangesAsync(); domainModel.Enchantments.ForEach(e => e.BaseSpell = originalSpellsById[e.BaseSpellId]); return(domainModel.ToViewModel()); }
public async Task <RaceViewModel> CreateRace([FromBody] RaceViewModel raceVM) { var domainModel = raceVM.ToDomainModel(); var originalFlawsById = domainModel.FlawInformation.ToDictionary(fi => fi.FlawId, fi => fi.Flaw); var originalFeaturesById = domainModel.FeatureInformation.ToDictionary(fi => fi.FeatureId, fi => fi.Feature); domainModel.FeatureInformation.ForEach(fi => fi.Feature = null); domainModel.FlawInformation.ForEach(fi => fi.Flaw = null); domainModel.Id = 0; if (raceVM.RaceId > 0) { //make sure they're the author of this race var existingRace = await this.dbCtx.Races.FirstOrDefaultAsync(r => r.AuthorId == userSession.Player.Id && r.Id == raceVM.RaceId); if (existingRace != null) { //yep, it's theirs existingRace.Delisted = true; domainModel.FeatureInformation.ForEach(fi => fi.Id = 0); domainModel.FlawInformation.ForEach(fi => fi.Id = 0); } } dbCtx.Attach(userSession.Player); domainModel.Author = userSession.Player; domainModel.CreatedAtMS = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); dbCtx.Races.Add(domainModel); await dbCtx.SaveChangesAsync(); domainModel.Author = userSession.Player; domainModel.FeatureInformation.ForEach(fi => fi.Feature = originalFeaturesById[fi.FeatureId]); domainModel.FlawInformation.ForEach(fi => fi.Flaw = originalFlawsById[fi.FlawId]); return(domainModel.ToViewModel()); }
public async Task <AuthToken> Signup([FromBody] SignupInputModel inputModel) { if (await dbContext.Players.AnyAsync(p => p.Name.ToLower() == inputModel.PlayerName.ToLower())) { return(null); } Player player = new Player() { Name = inputModel.PlayerName, SecurityHash = utilities.HashText(inputModel.InitialPassword) }; dbContext.Players.Add(player); await dbContext.SaveChangesAsync(); return(new AuthToken { PlayerName = player.Name, PlayerId = player.Id, Signature = CreateSignature(player) }); }