Example #1
0
        //taking the Jarray to push to DB
        public void ToDatabase(JArray satdata)
        {
            string atTime = DateTime.Now.ToString();

            // creating a new db object
            SatelliteN2YOs dbObj = new SatelliteN2YOs();

            //iterating through the satdata table returnong the request
            foreach (var SatRequest in satdata)
            {
                //returning the data in correct format
                dbObj.Category          = SatRequest["info"]["category"].Value <string>();
                dbObj.TransactionsCount = SatRequest["info"]["transactionscount"].Value <int>();
                dbObj.SatCount          = SatRequest["info"]["satcount"].Value <int>();

                if (SatRequest["info"]["satcount"].Value <int>() != 0)
                {
                    foreach (var satData in SatRequest["above"])
                    {
                        //getting all these values from the model
                        dbObj.SatId           = satData["satid"].Value <int>();
                        dbObj.SatName         = satData["satname"].Value <string>();
                        dbObj.Designator      = satData["intDesignator"].Value <string>();
                        dbObj.LaunchDate      = satData["launchDate"].Value <string>();
                        dbObj.SatLat          = satData["satlat"].Value <double>();
                        dbObj.SatLng          = satData["satlng"].Value <double>();
                        dbObj.SatAlt          = satData["satalt"].Value <double>();
                        dbObj.AtTime          = atTime;
                        db.Entry(dbObj).State = EntityState.Added;
                        db.SaveChanges();
                    }
                    //adding to the DB
                }
                else
                {
                    dbObj.SatId      = null;
                    dbObj.SatName    = null;
                    dbObj.Designator = null;
                    dbObj.LaunchDate = null;
                    dbObj.SatLat     = null;
                    dbObj.SatLng     = null;
                    dbObj.SatAlt     = null;
                    dbObj.AtTime     = null;

                    db.Entry(dbObj).State = EntityState.Added;
                    db.SaveChanges();
                }
            }
            //saving chnages actually made to the DB
        }
Example #2
0
        public void AddUser(User registeredUser)
        {
            if (registeredUser.Email == null)                       //checks if the user address is null and assigns dummy data if it is.
            {
                registeredUser.AddressLine = "no address";
                registeredUser.Email       = "*****@*****.**";
            }

            WhatsUpDBEntities db = new WhatsUpDBEntities();

            if (db.Users.Find(registeredUser.Email) == null)
            {
                db.Entry(registeredUser).State = EntityState.Added;
                db.SaveChanges();
            }
        }