Example #1
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"));
        }
Example #2
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 }));
        }