public ActionResult SaveNode(string childid, string parentid)
        {
            //*****REVISION******Do not allow reportsto = itself
            if (childid != null && parentid != null && parentid != childid)
            {
                string source      = childid;
                string destination = parentid;
                using (var ctx = new CosmicVerseEntities1())
                {
                    var personals = ctx.Personals.Where(m => m.Name == source).First();

                    var personalsParent = ctx.Personals.Where(m => m.Name == destination).First();

                    //***check
                    //*****REVISION******Do not allow make circle in data base such as P1 is parent for P2 and also P2 is parent for P1 ==> Prevent these mistake by checking it
                    //

                    if (personalsParent.ReportsTo != personals.ID)
                    {
                        personals.ReportsTo = Convert.ToInt16(personalsParent.ID);


                        ctx.SaveChanges();
                    }
                    //***check
                }
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult LinkHit(string link)
        {
            //this line is to check the clien ip address from the server itself
            string IP = "";

            string strHostName = "";

            strHostName = System.Net.Dns.GetHostName();

            IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);

            IPAddress[] addr = ipEntry.AddressList;

            IP = addr[2].ToString();

            //Initializing a new xml document object to begin reading the xml file returned
            XmlDocument doc = new XmlDocument();

            doc.Load("http://www.freegeoip.net/xml");
            XmlNodeList nodeLst_IP          = doc.GetElementsByTagName("Ip");
            XmlNodeList nodeLst_CountryCode = doc.GetElementsByTagName("CountryCode");
            XmlNodeList nodeLst_CountryName = doc.GetElementsByTagName("CountryName");
            XmlNodeList nodeLst_RegionCode  = doc.GetElementsByTagName("RegionCode");
            XmlNodeList nodeLst_RegionName  = doc.GetElementsByTagName("RegionName");
            XmlNodeList nodeLst_City        = doc.GetElementsByTagName("City");
            XmlNodeList nodeLst_ZipCode     = doc.GetElementsByTagName("ZipCode");
            XmlNodeList nodeLst_Latitude    = doc.GetElementsByTagName("Latitude");
            XmlNodeList nodeLst_Longitude   = doc.GetElementsByTagName("Longitude");
            XmlNodeList nodeLst_MetroCode   = doc.GetElementsByTagName("MetroCode");
            XmlNodeList nodeLst_AreaCode    = doc.GetElementsByTagName("AreaCode");

            //IP = "" + nodeLst_IP[0].InnerText + "<br>" + nodeLst_CountryCode[0].InnerText + "<br>" +
            //   nodeLst_CountryName[0].InnerText;

            //Response.Write(IP);
            //this is my header that I love

            if (link != null)
            {
                string source = link;
                //string destination = parentid;
                using (var ctx = new CosmicVerseEntities1())
                {
                    LinkHit lnkhit = new LinkHit();

                    lnkhit.Link        = link;
                    lnkhit.Date        = DateTime.Now.Date.Date.ToString();
                    lnkhit.Time        = DateTime.Now.TimeOfDay.ToString();
                    lnkhit.countrycode = nodeLst_CountryCode[0].InnerText;
                    lnkhit.countryname = nodeLst_CountryName[0].InnerText;
                    lnkhit.city        = nodeLst_City[0].InnerText;
                    lnkhit.IP          = nodeLst_IP[0].InnerText;
                    lnkhit.regioncode  = nodeLst_RegionCode[0].InnerText;
                    lnkhit.regionname  = nodeLst_RegionName[0].InnerText;
                    lnkhit.areacode    = nodeLst_AreaCode[0].InnerText;
                    lnkhit.longitude   = nodeLst_Longitude[0].InnerText;
                    lnkhit.latitude    = nodeLst_Latitude[0].InnerText;
                    lnkhit.zipcode     = nodeLst_ZipCode[0].InnerText;


                    ctx.LinkHits.Add(lnkhit);
                    ctx.SaveChanges();
                }
            }
            return(RedirectToAction(link));
        }