Пример #1
0
        public async Task <string> CreateAllianceAsync(CreateAllianceInputModel input, string allianceLeader)
        {
            if (this.alliancesRepository.AllAsNoTracking().Any(x => x.Name == input.Name))
            {
                throw new InvalidOperationException("Alliance name already taken!");
            }

            if (this.playersService.CheckIfPlayerIsInAlliance(allianceLeader))
            {
                throw new InvalidOperationException("You can only be member of one alliance!");
            }

            var alliance = new Alliance
            {
                Name           = input.Name,
                Description    = input.Description,
                AllianceLeader = allianceLeader,
            };

            await this.alliancesRepository.AddAsync(alliance);

            await this.alliancesRepository.SaveChangesAsync();

            if (!(input.AllianceImage?.Length is null))
            {
                await this.imagesService.AddImage(input.AllianceImage.OpenReadStream(), alliance.Id);
            }

            await this.AddPlayerToAllianceAsync(allianceLeader, alliance.Id);

            return(alliance.Id);
        }
Пример #2
0
        public async Task <IActionResult> Create(CreateAllianceInputModel input)
        {
            var applicationUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var allianceLeader    = this.playersService.GetPlayer(applicationUserId).PlayerName;

            var id = await this.alliancesService.CreateAllianceAsync(input, allianceLeader);

            return(this.RedirectToAction("Home", new RouteValueDictionary(new { controller = "Alliances", action = "Home", Id = id })));
        }