Exemple #1
0
        public ActionResult _PrivateDetails(string Link)
        {
            //Create Entity ORM object to access DB.
            waybackdbEntities dbContext = new waybackdbEntities();

            //Create list.
            List <Archive> archiveList = dbContext.Archives.ToList();
            //Get the current logged in user id.
            string CurrentUserId = User.Identity.GetUserId();

            // Checks each item in db for matching primary key(Link)
            //Only viewable to user logged in. [View "_PrivateDetails" displays button if bool is true]
            foreach (var item in archiveList)
            {
                if (item.Link == Link && item.UserID == CurrentUserId)

                {
                    ViewBag.Archive = item;
                }
                else if (item.Link == Link && item.UserID != CurrentUserId)
                {   //Redirects to homepage for now.
                    RedirectToAction("Index", "Home");
                }
            }
            return(View());
        }
Exemple #2
0
        //checks the DB for another project with the same name
        #region Methods
        public bool saveLink(string Link)
        //checks the DB for another project with the same name //Returns false if there is any error
        {
            //get db
            try
            {//if db is empty, we catch and skip this error handling.
                waybackdbEntities dbContext = new waybackdbEntities();

                List <Archive> archiveList = dbContext.Archives.ToList();

                List <string> Links = new List <string>();

                //Use primary key to separate lists
                foreach (var item in archiveList)
                {
                    Links.Add(item.Link);
                }

                //If link already in db, message.
                if (Links.Exists(x => x == Link))
                {
                    ViewBag.errormessage = "Link exists!";
                    return(false);
                }
                else
                {
                    return(saveLinkInDB(Link));
                }
            }

            catch
            {
                return(saveLinkInDB(Link));
            }
        }
Exemple #3
0
        public ActionResult Edit(Archive editedArchive)
        {
            waybackdbEntities dbContext = new waybackdbEntities();

            //Get original archive.
            Archive oldArchive = dbContext.Archives.Find(editedArchive.Link);

            //Get user that is logged in.
            string UserID = User.Identity.GetUserId();

            //Check if original archive Foreign key(userid) matches logged in user.
            if (oldArchive.UserID == UserID)
            {
                //Change the values in original archive to the edited values.

                oldArchive.ProjectName = editedArchive.ProjectName;
                oldArchive.TeamName    = editedArchive.TeamName;
                oldArchive.RepoLink    = editedArchive.RepoLink;
                oldArchive.ShortDesc   = editedArchive.ShortDesc;
                oldArchive.LongDesc    = editedArchive.LongDesc;
                oldArchive.PrivateLink = editedArchive.PrivateLink;

                //Saves changes to DB via Entity ORM.
                dbContext.SaveChanges();
            }

            //Send user to /home/dashboard.

            return(RedirectToAction("Dashboard", "Home"));
        }
        public ActionResult Dashboard(string Link)
        {
            //Change background image here.
            ViewBag.background = @Url.Content("~/Content/dashboard.jpg");

            //Create ORM Object to access database.
            waybackdbEntities Archives = new waybackdbEntities();

            //Turn Object into a List. Get all archives in it.
            List <Archive> ArchiveList = Archives.Archives.ToList();

            //Get the current logged in user id.
            string CurrentUserId = User.Identity.GetUserId();

            //New list that will represent the archives archived by user (foreign key)
            List <Archive> userArchiveList = new List <Archive>();

            //Get all userid that match current userid logged in.
            foreach (var item in ArchiveList)
            {   //Matching IDs get thrown in list.
                if (item.UserID == CurrentUserId)
                {
                    userArchiveList.Add(item);
                }
            }

            //Make list that has all of the current users archive.
            ViewBag.userArchiveList = userArchiveList;

            return(View());
        }
        public ActionResult Index()
        {
            //Change background image of homepage here.
            ViewBag.background = @Url.Content("~/Content/Keeper1.jpg");

            //Create ORM Object to access database
            waybackdbEntities dbContext = new waybackdbEntities();

            ////Turn Object into a List. Get all archives in it.
            List <Archive> archiveList = dbContext.Archives.ToList();

            //Displays only links that are marked public(PrivateLink=false)
            ViewBag.ArList = dbContext.Archives.Where(x => x.PrivateLink.Equals(false));

            return(View());
        }
Exemple #6
0
        //To be called when a delete button is made.
        public ActionResult Delete(string Link)
        {
            waybackdbEntities dbContext = new waybackdbEntities();

            //Create list
            List <Archive> archiveList = dbContext.Archives.ToList();

            //populate list with select object (by the input Link)  (refactor: use orm .find?)
            foreach (var item in archiveList)
            {
                if (item.Link == Link)
                {
                    archiveList.Remove(item);
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemple #7
0
        public ActionResult EditPage(string Link)
        {
            //Background image can be changed from here.
            ViewBag.background = @Url.Content("~/Content/NewProject.gif");

            //get db
            waybackdbEntities dbContext = new waybackdbEntities();

            //Finds one matching archive
            Archive archive = dbContext.Archives.Find(Link);

            //Refactored to use ViewModel.
            ArchiveFormViewModel viewModel = new ArchiveFormViewModel(archive);

            //sends the archive to the view
            return(View("EditPage", archive));
        }
Exemple #8
0
        public ActionResult Save(Archive archive)
        {
            //Create Entity ORM object to access DB.
            waybackdbEntities dbContext = new waybackdbEntities();


            //Send user back to blank form with an empty archive obj if model state is not valid
            if (!ModelState.IsValid)
            {
                ArchiveFormViewModel viewModel = new ArchiveFormViewModel(archive);
                return(View("ArchiveForm", viewModel));
            }


            //Savelink() tries to save link and returns false if error... changes ViewBag.errorMessage, accordingly
            if ((saveLink(archive.Link)) == false) //If we get an error (false)     refactor to try/catch
            {
                return(View("ArchiveForm"));       //renders ArchiveForm view
            }

            //Get the url that was archived using the wayback API.
            string ArchiveLink = archiveLink(archive.Link);

            //Call screenshot method, input users website link.
            var SnapShot = GetBytesFromImage(archive.Link);

            //Gets currently logged in user.
            string UserID = User.Identity.GetUserId();

            //Create the Archive object to determine what will be sent to DB from Project/New.
            archive = new Archive(archive.Link, ArchiveLink, archive.RepoLink, archive.ShortDesc, archive.LongDesc, SnapShot, UserID, archive.ProjectName, archive.TeamName, archive.PrivateLink);

            //Adds changes to DB via Entity ORM.
            dbContext.Archives.Add(archive);

            //Saves changes to DB via Entity ORM.
            dbContext.SaveChanges();

            //send user to Project/Details?Link=myurl.com
            return(RedirectToAction("Details", "Project", new { Link = archive.Link }));
        }
Exemple #9
0
        public ActionResult Details(string Link)   // returns one archived website in iframe, with details
        {
            //Create Entity ORM object to access DB.
            waybackdbEntities dbContext = new waybackdbEntities();

            //Create list.
            List <Archive> archiveList = dbContext.Archives.ToList();

            // Checks each item in db for matching primary key (to display selected record)
            //Only display if archive entity is marked public.
            foreach (var item in archiveList)
            {
                if (item.Link == Link && item.PrivateLink == false)
                {//sends archive to page
                    ViewBag.Archive = item;
                }
                else
                {
                    RedirectToAction("Index", "Home");
                }
            }
            return(View());
        }