コード例 #1
0
        public ActionResult ApproveApp(AuthUserCharacterGuildApplication application)
        {
            string username = User.Identity.GetUserId();
            // Add the user to the guild roster, then remove the application
            var app         = _authUserCharacterGuildApplicationRepository.GetPendingApplication(application.Id);
            var defaultRank = _guildRankRepository.GetDefaultRankForGuildApplications();

            if (defaultRank == null)
            {
                ModelState.AddModelError("", "Couldn't approve this guild application because no rank has been defined as default for new members!");
                return(View(app));
            }
            var result = _authUserCharacterRepository.AddCharacterToGuild(app.AuthUserCharacterId, app.GuildId, defaultRank.Id);

            if (!result.Success)
            {
                ModelState.AddModelError("", result.Message);
                return(View(app));
            }
            _logger.Debug(string.Format("{0} has approved {1}'s application for {2}", username, app.Character.CharacterName, app.Guild.Name));
            result = _authUserCharacterGuildApplicationRepository.Remove(application.Id, username);
            if (!result.Success)
            {
                ModelState.AddModelError("", result.Message);
                return(View(app));
            }
            return(RedirectToAction("AppApproved", new { @id = app.GuildId }));
        }
コード例 #2
0
        public ActionResult DeclineApp(AuthUserCharacterGuildApplication application)
        {
            string username = User.Identity.GetUserId();
            var    app      = _authUserCharacterGuildApplicationRepository.GetPendingApplication(application.Id);
            var    result   = _authUserCharacterGuildApplicationRepository.Remove(application.Id, username);

            if (!result.Success)
            {
                ModelState.AddModelError("", result.Message);
                return(View(app));
            }
            _logger.Debug(string.Format("{0} has declined {1}'s application for {2}", username, app.Character.CharacterName, app.Guild.Name));
            return(RedirectToAction("AppDeclined", new { @id = app.GuildId }));
        }
コード例 #3
0
        /// <summary>
        /// Updated for MySQL
        /// </summary>
        /// <param name="application"></param>
        /// <returns></returns>
        public ReturnValue Create(AuthUserCharacterGuildApplication application)
        {
            var returnValue = new ReturnValue();

            // Check to see if this character already exists in the guild or has an existing application

            if (PendingApplication(application.AuthUserCharacterId, application.GuildId))
            {
                returnValue.Message = "You have already submitted an application for this guild with this character!";
                return(returnValue);
            }

            string timeElapsed;
            var    alreadyInGuild = Query(q => q.Query <long>(MySQL.AuthUserCharacter.CharacterIsInGuild,
                                                              new { @authUserCharacterId = application.AuthUserCharacterId, @guildId = application.GuildId }),
                                          out timeElapsed).SingleOrDefault() == 1;

            if (alreadyInGuild)
            {
                returnValue.Message = "This character is already in the selected guild!";
                return(returnValue);
            }

            var guild =
                Query(q => q.Query <Guild, Shard, GuildStatus, Guild>
                          (MySQL.Guild.GetGuildById,
                          (g, s, gs) =>
            {
                g.Shard  = s;
                g.Status = gs;
                return(g);
            }, new { @id = application.GuildId }), out timeElapsed)
                .Single();
            var character =
                Query(
                    q =>
                    q.Query <AuthUserCharacter>(MySQL.AuthUserCharacter.Get,
                                                new { @id = application.AuthUserCharacterId }), out timeElapsed).Single();

            // Add the application
            try
            {
                DapperDb dapperDb = DapperDb.Init(OpenConnection(), 3, false);

                var newId = dapperDb.AuthUserCharacterGuildApplicationTable.Insert(
                    new //AuthUserCharacterGuildApplication()
                {
                    GuildId             = application.GuildId,
                    Message             = application.Message,
                    AuthUserCharacterId = application.AuthUserCharacterId
                });

                if (newId > 0)
                {
                    returnValue.Message = newId.ToString();
                    returnValue.Success = true;
                }

                _logger.Debug(string.Format("{0} has applied to join {1} on {2}", character.CharacterName, guild.Name, guild.Shard.Name));
            }
            catch (Exception ex)
            {
                returnValue.Message = ex.Message;
            }

            return(returnValue);
        }