예제 #1
0
        public static async Task <ValidatedView <List <ClanDiplomacyView> > > RetrievePendingDiplomacies(int accountId)
        {
            try {
                ClanMemberModel clanMemberModel = await Model <ClanMemberModel>
                                                  .AsQueryable().FirstOrDefault(x => x.AccountID == accountId);

                if (clanMemberModel != null)
                {
                    ClanModel clanModel = await Model <ClanModel> .AsQueryable()
                                          .FirstOrDefault(x => x.ID == clanMemberModel.ClanID);

                    if (clanModel == null)
                    {
                        return(ValidatedView <List <ClanDiplomacyView> > .Invalid(ErrorCode.CLAN_NOT_FOUND));
                    }
                    else
                    {
                        List <ClanDiplomacyView> diplomacies = new List <ClanDiplomacyView>();
                        foreach (ClanRelationPendingModel clanRelationModel in await Model <ClanRelationPendingModel>
                                 .AsQueryable().Where(x => x.InitiatorID == clanModel.ID || x.TargetID == clanModel.ID)
                                 .ToList())
                        {
                            ClanDiplomacyView clanDiplomacyView = Mapper <ClanRelationPendingModel> .Map <ClanDiplomacyView>(clanRelationModel);

                            ValidatedView <ClanView> validatedView = await RetrieveClan(accountId,
                                                                                        (clanRelationModel.InitiatorID == clanModel.ID ? clanRelationModel.TargetID
                                : clanRelationModel.InitiatorID));

                            if (!validatedView.IsValid)
                            {
                                GameContext.Logger.LogWarning($"Failed to load pending diplomacy for {clanModel.ID}!");
                                continue;
                            }

                            clanDiplomacyView.Clan = validatedView.Object;
                            diplomacies.Add(clanDiplomacyView);
                        }

                        return(ValidatedView <List <ClanDiplomacyView> > .Valid(diplomacies));
                    }
                }
                else
                {
                    return(ValidatedView <List <ClanDiplomacyView> > .Invalid(ErrorCode.CLAN_NOT_MEMBER));
                }
            } catch (Exception e) {
                GameContext.Logger.LogError(e);
            }
            return(ValidatedView <List <ClanDiplomacyView> > .Invalid(ErrorCode.OPERATION_FAILED));
        }
예제 #2
0
 protected void Change(ClanDiplomacyView selected)
 {
     Selected = selected;
 }