Exemplo n.º 1
0
        public IActionResult Post([FromBody] AddGuildModel addGuildModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(GetErrorMessageObject(GetModelStateErrors())));
                }

                var guild = _guildBankRepository.AddGuild(addGuildModel, ClassicGuildBankUser);

                return(new JsonResult(guild));
            }
            catch
            {
                return(BadRequest(GetErrorMessageObject("Failed to Add Guild")));
            }
        }
        public Guild AddGuild(AddGuildModel addGuildModel, ClassicGuildBankUser classicGuildBankUser)
        {
            var guild = new Guild()
            {
                Id        = Guid.NewGuid(),
                UserId    = classicGuildBankUser.Id,
                Name      = addGuildModel.GuildName,
                InviteUrl = GenerateGuildInviteUrl()
            };

            _classicGuildBankDbContext.Guilds.Add(guild);

            AddGuildMember(guild.Id, classicGuildBankUser, save: false);

            _classicGuildBankDbContext.SaveChanges();

            guild.UserIsOwner   = true;
            guild.UserCanUpload = true;

            return(guild);
        }