//this action sends all data in the program to the db
        public ActionResult SendData(finaltable coordinates)
        {
            string reported = "";

            //assigning values to the new object being passed in
            coordinates.flagged       = "Y";
            coordinates.username      = User.Identity.GetUserId();
            coordinates.datereported  = DateTime.Now;
            coordinates.reportedtimes = 1;

            //opening the db
            SquatDBEntities db = new SquatDBEntities();

            //adding the object to the DB
            db.finaltables.Add(coordinates);

            try
            {
                //saving the db
                db.SaveChanges();
            }
            catch
            {
                //same primary key will prevent the new object from being saved, this will alert the user letting them know
                reported = "Already Reported!";
            }

            //sending the message using temp data
            TempData["reported"] = reported;

            //return View();
            return(RedirectToAction("Redirect", "Map"));
        }
        public ActionResult DeleteReport(string DeleteName)
        {
            //action that allows us to delete reports
            finaltable ToDelete = db.finaltables.Find(DeleteName);

            db.finaltables.Remove(ToDelete);

            db.SaveChanges();

            return(RedirectToAction("MyReportsView", "Owner"));
        }
        public ActionResult UnFlag(string UpdateName)
        {
            //allows take the url value and fing the correct item to flag
            finaltable FindItem = db.finaltables.Find(UpdateName);

            if (FindItem.username == User.Identity.GetUserId())
            {
                return(View("MyReportsView", FindItem));
            }
            return(View("OwnerView", FindItem));
        }
        public ActionResult TickReport(string ReportCount)
        {
            //action that allows us to add a value to the times reported
            finaltable ReportNumber = db.finaltables.Find(ReportCount);

            int count = Convert.ToInt32(ReportNumber.reportedtimes);

            int newcount = (count + 1);

            ReportNumber.reportedtimes = Convert.ToByte(newcount);

            db.SaveChanges();

            return(RedirectToAction("OwnerView", "Owner"));
        }
        public ActionResult UpdateComments(string ToBeUpdated)
        {
            //allows us to update changes made to the comments field and limit access to non owners
            ViewBag.Name = User.Identity.GetUserName();

            finaltable FindItem = db.finaltables.Find(ToBeUpdated);

            if (FindItem.username == User.Identity.GetUserId())
            {
                return(View("AccountReportsView", FindItem));
            }
            else
            {
                return(View("DetailsView", FindItem));
            }
        }
        public ActionResult SaveComments(finaltable ToBeUpdated)
        {
            //allows us to save changes made to the comments field and limit access to non owners
            finaltable FindItem = db.finaltables.Find(ToBeUpdated.address);

            FindItem.comments = ToBeUpdated.comments;

            db.SaveChanges();

            if (FindItem.username == User.Identity.GetUserId())
            {
                return(RedirectToAction("MyReportsView"));
            }
            else
            {
                return(RedirectToAction("OwnerView"));
            }
        }
        public ActionResult SaveMyFlag(string flagname)
        {
            //changes the flag value in the myreports view and saves changes
            finaltable FindItem = db.finaltables.Find(flagname);

            if (FindItem.flagged == "Y")
            {
                FindItem.flagged = "N";
            }
            else
            {
                FindItem.flagged = "Y";
            }

            db.SaveChanges();

            return(RedirectToAction("MyReportsView"));
        }