public ViewResult New()
        {
            var categories = _context.Categories.ToList();
            var viewModel  = new ArchiveFormViewModel
            {
                Categories = categories
            };

            return(View("ArchiveForm", viewModel));
        }
        public ActionResult Edit(int id)
        {
            var archive = _context.Archives.SingleOrDefault(a => a.Id == id);

            if (archive == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new ArchiveFormViewModel(archive)
            {
                Categories = _context.Categories.ToList()
            };

            return(View("ArchiveForm", viewModel));
        }
Beispiel #3
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));
        }
Beispiel #4
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 }));
        }
        public ActionResult Save(Archive archive)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new ArchiveFormViewModel(archive)
                {
                    Categories = _context.Categories.ToList()
                };
                return(View("ArchiveForm", viewModel));
            }

            // Create New Archive
            if (archive.Id == 0)
            {
                // Specify a name for your top-level folder.
                const string folderName = @"c:\OndoProbate";

                // To create a string that specifies the path to a subfolder under your
                // top-level folder, add a name for the subfolder to folderName.
                var pathString = Path.Combine(folderName, "CASE" + Guid.NewGuid());

                archive.FilePath = pathString;

                var category = _context.Categories.Single(c => c.Id == archive.CategoryId);
                archive.Category = category;
                _context.Archives.Add(archive);
                Directory.CreateDirectory(pathString);
            }
            // Edit Existing Archive
            else
            {
                var archiveInDb = _context.Archives.Single(a => a.Id == archive.Id);
                archiveInDb.Name       = archive.Name;
                archiveInDb.FilePath   = archive.FilePath;
                archiveInDb.CaseDate   = archive.CaseDate;
                archiveInDb.CategoryId = archive.CategoryId;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Archives"));
        }