public List <string> Get()
        {
            APT     apt     = new APT();
            Country country = new Country();

            country.Id          = 1026;
            country.CountryName = "أندورا";
            country.Contenant   = "EU";
            ThreatSignature signature = new ThreatSignature();
            AlternativeName name      = new AlternativeName();

            name.Serial           = 1;
            name.Name             = "alternativeName";
            signature.DomainName  = "domain";
            signature.Serial      = 2;
            signature.Name        = "signature Name";
            apt.TargetedCountries = new List <Country> {
                country
            };
            apt.OriginCountries = new List <Country> {
                country
            };
            apt.ThreatSignatures = new List <ThreatSignature> {
                signature
            };
            apt.AlternativeNames = new List <AlternativeName> {
                name
            };

            apt.Name = "سالم";
            List <Country> targetedCountries = new List <Country>();
            List <Country> originCountry     = new List <Country>();


            foreach (Country c in apt.OriginCountries)
            {
                targetedCountries.Add(_context.Countries.Find(c.Id));
            }

            foreach (Country c in apt.OriginCountries)
            {
                originCountry.Add(_context.Countries.Find(c.Id));
            }
            apt.OriginCountries   = originCountry;
            apt.TargetedCountries = targetedCountries;

            _context.Apts.Add(apt);
            _context.SaveChanges();

            return(new List <String> {
                "Salim"
            });
        }
コード例 #2
0
        public void Put([FromBody] APT newAPT)
        {
            var queryables = context.Apts.Where(x => x.id == newAPT.id).Select(a => new
            {
                id = a.id,
                AlternativeNames  = a.AlternativeNames.ToList(),
                ThreatSignatures  = a.ThreatSignatures.ToList(),
                Name              = a.Name,
                Contents          = a.Contents.ToList(),
                OriginCountries   = a.OriginCountries.ToList(),
                TargetedCountries = a.TargetedCountries.ToList()
            });

            var lists = queryables.AsEnumerable().Select(x => new APT
            {
                AlternativeNames = x.AlternativeNames,
                id                = x.id,
                Name              = x.Name,
                Contents          = x.Contents,
                OriginCountries   = x.OriginCountries,
                ThreatSignatures  = x.ThreatSignatures,
                TargetedCountries = x.TargetedCountries
            }).ToList();



            APT aPT = lists.ElementAt(0);

            List <Country> targetedCountries = new List <Country>();
            List <Country> originCountry     = new List <Country>();


            foreach (Country c in newAPT.TargetedCountries)
            {
                targetedCountries.Add(context.Countries.Find(c.Id));
            }

            foreach (Country c in newAPT.OriginCountries)
            {
                originCountry.Add(context.Countries.Find(c.Id));
            }

            context.Entry(aPT).CurrentValues.SetValues(newAPT);
            context.SaveChanges();
        }
コード例 #3
0
        public void Post([FromBody] APT apt)
        {
            List <Country> targetedCountries = new List <Country>();
            List <Country> originCountry     = new List <Country>();


            foreach (Country c in apt.TargetedCountries)
            {
                targetedCountries.Add(context.Countries.Find(c.Id));
            }
            foreach (Country c in apt.OriginCountries)
            {
                originCountry.Add(context.Countries.Find(c.Id));
            }
            apt.OriginCountries   = originCountry;
            apt.TargetedCountries = targetedCountries;

            context.Apts.Add(apt);
            context.SaveChanges();
        }
コード例 #4
0
 public APT_Service()
 {
     apt = new APT();
 }