Esempio n. 1
0
        public bool CreateJoinRequest(ClanJoinView clanJoinView, out string message, out HttpStatusCode code)
        {
            message = ErrorCode.CONNECTION_FAILED;


            Api().CreateAuthenticated("api/clan/request", "post")
            .WithBody(clanJoinView)
            .Execute(out HttpWebResponse response);

            if (response.TryGetStatusCode(out code) && code == HttpStatusCode.OK)
            {
                ValidatedView validatedView = response.GetReponseString()
                                              .DeserializeJsonSafe <ValidatedView>();
                if (validatedView == null)
                {
                    message = ErrorCode.ERROR_WHILE_READING_RESULT;
                }
                else
                {
                    message = validatedView.Message;
                    return(validatedView.IsValid);
                }
            }

            return(false);
        }
Esempio n. 2
0
        public static async Task <ValidatedView> CreateJoinRequest(int accountId, ClanJoinView clanJoinView)
        {
            if (!clanJoinView.IsValid(out string message))
            {
                return(ValidatedView.Invalid(message));
            }

            try {
                if (await Model <ClanMemberPendingModel> .AsQueryable()
                    .Any(x => x.AccountID == accountId && x.ClanID == clanJoinView.ClanID))
                {
                    return(ValidatedView.Invalid(ErrorCode.CLAN_REQUEST_ALREADY_EXISTS));
                }

                if (!await Model <ClanModel> .AsQueryable()
                    .Any(x => x.ID == clanJoinView.ClanID))
                {
                    return(ValidatedView.Invalid(ErrorCode.CLAN_NOT_FOUND));
                }

                await Model <ClanMemberPendingModel> .AsCollection().InsertOneAsync(new ClanMemberPendingModel {
                    AccountID = accountId,
                    ClanID    = clanJoinView.ClanID,
                    Message   = clanJoinView.Description
                });

                return(ValidatedView.Valid());
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED));
        }
Esempio n. 3
0
 public async Task <IActionResult> CreateRequest([FromBody] ClanJoinView clanJoinView)
 {
     if (HttpContext.TryGetCurrentSession(out AccountSessionView accountSessionView))
     {
         return(Ok(await ClanService.CreateJoinRequest(accountSessionView.AccountID, clanJoinView)));
     }
     return(Ok(ValidatedView.Invalid(ErrorCode.OPERATION_FAILED)));
 }