Пример #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
        }
Пример #2
0
        public ActionResult SaveFavorties(Favorite newFavorite)
        {
            WhatsUpDBEntities db = new WhatsUpDBEntities();

            db.Favorites.Add(newFavorite);
            db.SaveChanges();
            return(RedirectToAction("Favorites"));
        }
Пример #3
0
 public ActionResult AddFavorites(Favorite favorite)
 {
     if (ModelState.IsValid)
     {
         WhatsUpDBEntities db = new WhatsUpDBEntities();
         db.Favorites.Add(favorite);
         db.SaveChanges();
         return(View("Favorites"));
     }
     else
     {
         ViewBag.Added = "Not a valid selection";
         return(View("Favorites"));
     }
 }
Пример #4
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();
            }
        }
Пример #5
0
        public ActionResult DeleteFavorite(int id)
        {
            WhatsUpDBEntities db = new WhatsUpDBEntities();
            List <Favorite>   NewFavoriteList = db.Favorites.Where(x => x.FavID == id).ToList();

            foreach (Favorite favorite in NewFavoriteList)
            {
                db.Favorites.Remove(favorite);
            }

            Favorite found = db.Favorites.Find(id);

            db.Favorites.Remove(found);
            db.SaveChanges();

            return(RedirectToAction("Favorites"));
        }