public async Task <IActionResult> AddCpu([FromBody] ServerCpuInsertDto model) { var player = await _dbContext.Players.Where(p => p.UserId == UserId) .Include(p => p.Camp) .ThenInclude(p => p.Server) .Include(p => p.Camp) .ThenInclude(p => p.Cpus) .FirstOrDefaultAsync(); if (player == null) { return(NotFound("Path not found")); } if (player.Camp.Server.CpuCount <= player.Camp.Cpus.Count) { return(BadRequest($"You already have {player.Camp.Server.CpuCount} cpu")); } var cpu = _mapper.Map <CampCpu>(model); cpu.CampId = player.Camp.Id; await _dbContext.ServerCpus.AddAsync(cpu); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> AddSlot([FromBody] SlotInsertDto dto) { var slot = _mapper.Map <DungeonSlot>(dto); await _dbContext.DungeonSlots.AddAsync(slot); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> AddDefenceItem([FromBody] SlotDefenceItemInsertDto dto) { var dItem = _mapper.Map <SlotDefenceItem>(dto); await _dbContext.SlotDefenceItems.AddAsync(dItem); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> AddDungeon([FromBody] DungeonInsertDto model) { var dungeon = _mapper.Map <CampDungeon>(model); var player = await _dbContext.Players.Where(p => p.UserId == UserId).Include(p => p.Camp).FirstOrDefaultAsync(); dungeon.CampId = player.Camp.Id; await _dbContext.PlayerDungeons.AddAsync(dungeon); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> AddPool([FromBody] CampPoolInsertDto dto) { var player = await _dbContext.Players .Where(p => p.UserId == UserId) .Include(p => p.Camp) .FirstOrDefaultAsync(); var pool = _mapper.Map <CampPool>(dto); pool.CampId = player.Camp.Id; await _dbContext.CampPools.AddAsync(pool); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> SetWeapon([FromBody] WeaponInsertDto weaponDto) { var player = await _db.Players.FirstOrDefaultAsync(p => p.UserId == UserId); var weapon = _mapper.Map <PlayerWeapon>(weaponDto); if (await _db.PlayerWeapons.Where(w => w.PlayerId == player.Id).AnyAsync(w => w.WeaponId == weapon.Id)) { return(BadRequest("You already have this weapon!")); } weapon.PlayerId = player.Id; await _db.PlayerWeapons.AddAsync(weapon); await _db.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult> SetWorld([FromBody] CampInsertDto model) { var player = await _dbContext.Players.FirstOrDefaultAsync(x => x.UserId == UserId); if (player == null) { return(NotFound("player not found for this user")); } var playerBase = _mapper.Map <PlayerCamp>(model); playerBase.PlayerId = player.Id; await _dbContext.PlayerCamps.AddAsync(playerBase); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> SignUp(UserSignUpDto userSignUpDto) { var user = _mapper.Map <UserSignUpDto, AppUser>(userSignUpDto); if (!string.IsNullOrEmpty(userSignUpDto.Email)) { var message = new Message(new[] { userSignUpDto.Email }, "Test email", "this is test email"); await _emailSender.SendEmail(message); if (!ModelState.IsValid) { return(BadRequest()); } if (await _userManager.FindByEmailAsync(user.Email) != null) { var error = _userManager.ErrorDescriber.DuplicateEmail(user.Email); return(Problem($"{_convertErrorToCode.ConvertErrorToCode(error.Code).ToString()} : {error.Description}", null, 500)); } } var userCreateResult = await _userManager.CreateAsync(user, userSignUpDto.Password); if (userCreateResult.Succeeded) { var player = new Player { UserId = user.Id }; player.IsOnline = true; await _dbContext.Players.AddAsync(player); await _dbContext.SaveChangesAsync(); return(Ok()); } var code = _convertErrorToCode.ConvertErrorToCode(userCreateResult.Errors.First().Code); return(Problem($"{code.ToString()} : {userCreateResult.Errors.First().Description}", null, 500)); }
public async Task <IActionResult> AddGem(int gemId) { var gemPack = await _dbContext.GemPacks.FirstOrDefaultAsync(g => g.Id == gemId); if (gemPack == null) { return(NotFound("Gem packs with this id not found")); } var player = await _dbContext.Players.FirstOrDefaultAsync(p => p.UserId == UserId); if (player == null) { return(NotFound("Player not found")); } player.Gem += gemPack.Value; await _dbContext.SaveChangesAsync(); return(Ok()); }