Click here to Skip to main content
15,569,696 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi guys im trying to implement a service that gets the atribute contaminatiotID that is on the two list i have created. im about to showing you up. What i want to do is to get the people with the same contaminationID on wcf.For example Infeted is the person with covid and isolated are the people that had contact with the infected. What im trying to do is a service that retrive the two list of people with the same contamination ID

What I have tried:

This is what i implemented so far

Paste Models:

infected.cs

namespace DgsSoapWebService.Models
{
    [DataContract]
    public class Infected
    {
        [DataMember]
        public string Nome { get; set; }

        [DataMember]
        public int Datanasc { get; set; }

        [DataMember]
        public string Cidade { get; set; }

        [DataMember]
        public int Nrutente { get; set; }

        [DataMember]
        public bool Covid { get; set; }

        [DataMember]
        public int ContaminationID { get; set; }
    }
}


Isolated.cs
public class Isolated : Infected
    {
        [DataMember]
        public bool Internado { get; set; }

        [DataMember]
        public string LocalInternamento { get; set; }

        [DataMember]
        public string DataInternamento { get; set; }
    }


Paste Services:
IInfecteds.cs

[ServiceContract]
   public interface IInfecteds
   {
       [OperationContract]
       List<Infected> GetNome(string nomefiltro ="");

       [OperationContract]
       Isolated GetAllContaminationID(int contaminationID);
   }


Infecteds.svc

public class Infecteds : IInfecteds
   {
       List<Infected> infecteds;
       List<Isolated> isolateds;


       public Infecteds()
       {
           infecteds = new List<Infected>
           {
               new Infected { Nome = "zeze", Datanasc= 2000-23-12, Cidade="Lisboa", Nrutente= 12344512, Covid = true, ContaminationID = 1}
           };

           isolateds = new List<Isolated>
           {
               new Isolated { Nome = "tone", Datanasc= 2000-23-12, Cidade="Cascais", Nrutente= 23244512, Covid = true, ContaminationID = 1}
           };
       }


       public List<Infected> GetNome(string nomefiltro = "")
       {
           return infecteds.Where(p => p.Nome.Contains(nomefiltro)).ToList();
       }

       public Isolated GetAllContaminationID(int contaminationID)
       {
           return isolateds.FirstOrDefault(p => p.ContaminationID.Equals(contaminationID));
       }

   }
Posted
Updated 13-Nov-21 14:27pm
v2
Comments
johannesnestler 15-Nov-21 10:21am    
Whats your problem? To aggregate the result?
Something like this
public Infected GetAllContaminationID(int contaminationID)
{
var isolatedWithContaminationID = isolateds.Where(p => p.ContaminationID.Equals(contaminationID)).ToList();
var infectedWithContaminationID = infecteds.Where(p => p.ContaminationID.Equals(contaminationID)).ToList();

var result = isolatedWithContaminationID.Concat(infectedWithContaminationID).ToList();
return result; ​
​}
btw. you have to change the return type of GetAllContaminationID to the common base class (Infected)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900