public static bool AddNameToArtifacts(Artifact person) { SqlConnection con = new SqlConnection(GetConnectionString()); string insertStatement = "INSERT tblArtifacts " + "(Name, FileName, ArtifactType, HeadStone, Description) " + "VALUES (@Name, @FileName, @ArtifactType, @HeadStone, @Description)"; SqlCommand cmd = new SqlCommand(insertStatement, con); cmd.Parameters.AddWithValue("@Name", person.Name); cmd.Parameters.AddWithValue("@FileName", person.FileName); cmd.Parameters.AddWithValue("@ArtifactType", person.ArtifactType); cmd.Parameters.AddWithValue("@HeadStone", person.HeadStone); cmd.Parameters.AddWithValue("@Description", person.Description); try { con.Open(); int count = cmd.ExecuteNonQuery(); if (count > 0) return true; else return false; } catch (SqlException ex) { throw ex; } finally { con.Close(); } }
public static List<Artifact> GetArtifacts(string name) { List<Artifact> artifacts = new List<Artifact>(); SqlConnection con = new SqlConnection(GetConnectionString()); string sel = "SELECT * " + "FROM tblArtifacts " + "WHERE Name = @Name " + "ORDER BY ArtifactType DESC "; SqlCommand cmd = new SqlCommand(sel, con); cmd.Parameters.AddWithValue("@Name", name); try { con.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (rdr.Read()) { Artifact a = new Artifact(); a.Name = rdr["Name"].ToString(); a.FileName = rdr["FileName"].ToString(); a.ArtifactType = rdr["ArtifactType"].ToString(); a.HeadStone = rdr["HeadStone"].ToString(); a.Description = rdr["Description"].ToString(); artifacts.Add(a); } } catch (SqlException ex) { throw ex; } finally { con.Close(); } return artifacts; }
public ActionResult CreateArtifact(HttpPostedFileBase file, Models.Artifact artifactcm) { ViewBag.Message = "Testing Artifact File Create"; if (file != null && file.ContentLength > 0) try { string path = Path.Combine(Server.MapPath("~/photoprowess/images/demo/gallery"), Path.GetFileName(file.FileName)); //System.IO.File.SetAttributes(path, System.IO.FileAttributes.Normal); //System.Drawing.Image MainImgPhotoVert = System.Drawing.Image.FromFile(path); /* System.Drawing.Image MainImgPhotoVert = System.Drawing.Image.FromStream(System.IO.Stream file); Bitmap MainImgPhoto = (System.Drawing.Bitmap)ScaleByPercent(MainImgPhotoVert, 100); MainImgPhoto.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg); MainImgPhoto.Dispose(); */ //if the file already exists redirect control to Index page! if (System.IO.File.Exists(path)) { TempData["ReturnData"] = "A Photo named: " + file.FileName + " already exists. You may Delete it below. Then re-Add the photo"; return RedirectToAction("Index"); } { file.SaveAs(path); } //file.InputStream.Flush(); //useless //file.InputStream.Close(); //less than useless //file.InputStream.Dispose(); //complete waste of keystrokes //System.IO.File.SetAttributes(path, System.IO.FileAttributes.Normal); // Validating whether the following commented code releases a recently created // file from IIS for file Delete. Problem occuring in the Visual Studio test environment. //file.InputStream.Dispose(); //GC.Collect(); //GC.WaitForPendingFinalizers(); // Create the Thumbnail image string smallImageFilePath = Path.Combine(Server.MapPath("~/photoprowess/images/demo/gallery/") + "ThumbSize" + (file.FileName)); //allocate an Image object from the uploaded full sized .jpg // works System.Drawing.Image imgPhotoVert = System.Drawing.Image.FromFile(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); System.Drawing.Image imgPhotoVert = System.Drawing.Image.FromStream(fs); Bitmap imgPhoto = (System.Drawing.Bitmap)ScaleByPercent(imgPhotoVert, 50); //imgPhoto.Save(smallImageFilePath, System.Drawing.Imaging.ImageFormat.Jpeg); imgPhoto.Save(smallImageFilePath, System.Drawing.Imaging.ImageFormat.Jpeg); fs.Close(); imgPhoto.Dispose(); //((IDisposable)imgPhoto).Dispose(); var artifact = new Artifact(); //gallery.PhotoNumberID = 9; artifact.FileName = file.FileName; if (artifactcm.Description == null) artifactcm.Description = " "; artifact.Description = artifactcm.Description; artifact.ArtifactType = " "; artifact.HeadStone = " "; artifact.Name = genericPersonName; //artifact.Name = "Mildred B. Whelehon"; var artifactContext = new EFContextArtifacts(); artifactContext.Artifact.Add(artifact); artifactContext.SaveChanges(); } catch (Exception ex) { TempData["ReturnData"] = file.FileName + " Upload exception. The Details follow: " + ex.ToString(); return RedirectToAction("Index"); } else { //ViewBag.Message = "You have not specified a file."; TempData["ReturnData"] = "A file was not chosen for upload."; return RedirectToAction("CreateArtifact"); } TempData["ReturnData"] = file.FileName + " was successfully Added"; return RedirectToAction("Index"); }
public ActionResult FileAssociate(List<BomanGen.Models.ArtifactModel> list) { ViewBag.Message = "It's Test 1 2 3 Time"; string currFileName = Session["currentFileProcessed"].ToString(); // Retrieve and temporarily hold the generic row in an Artifact Model class var genericArtifactRow = db.Artifact.Find(currFileName, genericPersonName); // Delete all database rows for this fileName // in case the user de-selected any of them if (PersonDB.DelNamesByFile(currFileName) == true) ; // Re-Add the Generic Person database row since it has to exist PersonDB.AddNameToArtifacts(genericArtifactRow); /* bool trueOrFalse = PersonDB.DelNamesByFile(currFileName); */ int ttlNumOfNames = list.Count; for (int x = 0; x < ttlNumOfNames; x++) { if (list[x].IfChecked == true ) { Artifact currArtifact = new Artifact(); //var myRow = db.Artifact.ToArray(); //var genericRow = db.Artifact.Find(currFileName); currArtifact.FileName = currFileName; currArtifact.Name = list[x].Name; currArtifact.HeadStone = genericArtifactRow.HeadStone; currArtifact.Description = genericArtifactRow.Description; currArtifact.ArtifactType = genericArtifactRow.ArtifactType; //BomanGen.Models.Artifact currArtifact; PersonDB.AddNameToArtifacts(currArtifact); } } TempData["ReturnData"] = "The following Artifact or Photo was Updated successfully: " + currFileName; return View(list); }