コード例 #1
0
        public ActionResult <List <OInteraction> > InteractionHistory(int id1)
        {
            List <Interaction> interactions = new List <Interaction>();

            try{
                if (context.Interactions.Any(x => (x.IdMain == id1 || (x.IdSecondary == id1 && x.Match2.HasValue))))
                {
                    interactions = context.Interactions.Where(x => (x.IdMain == id1 || (x.IdSecondary == id1 && x.Match2.HasValue))).ToList();
                    return(OInteraction.BuildFromInteractionsList(id1, interactions));
                }
            }
            catch {
                return(BadRequest());
            }
            return(OInteraction.BuildFromInteractionsList(id1, interactions));
        }
    public static List <OInteraction> BuildFromInteractionsList(int refId, List <Interaction> interactions)
    {
        if (interactions == null)
        {
            return(new List <OInteraction>());
        }

        List <OInteraction> OInteractions = new List <OInteraction>();

        foreach (var interaction in interactions)
        {
            OInteraction toAdd = new OInteraction();
            toAdd.Id = interaction.Id;

            if (interaction.IdSecondary == refId)
            {
                if (!interaction.Match2.HasValue)
                {
                    continue;
                }

                toAdd.IdMain      = interaction.IdSecondary;
                toAdd.IdSecondary = interaction.IdMain;
                toAdd.Match1      = interaction.Match2.Value;
                toAdd.Match2      = interaction.Match2;
            }
            else
            {
                toAdd.IdMain      = interaction.IdMain;
                toAdd.IdSecondary = interaction.IdSecondary;
                toAdd.Match1      = interaction.Match1;
                toAdd.Match2      = interaction.Match2;
            }
            OInteractions.Add(toAdd);
        }
        return(OInteractions);
    }