public checkIfTagExists ( string TagArr ) : List |
||
TagArr | string | |
Résultat | List |
public string stringOfTags(FormCollection form) { Tools tool = new Tools(); string[] Taglist = seperateTags(form["StringTag"]); List<int> TagIDs = tool.checkIfTagExists(Taglist); string Tagfinal = tool.convertTagsToString(TagIDs); return Tagfinal; }
public ActionResult UploadImage(HttpPostedFileBase file, string FolderID, string description, string tags) { Tools funcs = new Tools(); //funcs contains resize/rename method Size newSize = new Size(181, 100); //global size for all thumbnails string[] TagArr; List<int> TagIDs; string finalTags; System.Drawing.Imaging.ImageFormat fileExtension; var user = (from u in dbContext.Users where u.UserID == WebSecurity.CurrentUserId select u).SingleOrDefault(); // user can't upload if account is frozen if (user.Status == Status.Frozen) { Tools.uploaded = false; return RedirectToAction("UploadImage"); } //Check file is valid if (funcs.PhotoValidation(file) == true) { //Declare filename and path var fileName = System.IO.Path.GetFileName(file.FileName); var path = ""; //split tags TagArr = funcs.seperateTags(tags); //Checks if tag exists, if not adds it. TagIDs = funcs.checkIfTagExists(TagArr); //Converts the list array to a string and puts in ',' finalTags = funcs.convertTagsToString(TagIDs); //Find filetype fileExtension = funcs.checkExtension(fileName); //Create encrypted fileName fileName = funcs.CreateFilename(Tools.UserID, fileName); //Path is directory and filename path = System.IO.Path.Combine(Server.MapPath("~/Images/User/"), fileName); //save uploaded picture via path file.SaveAs(path); //temp image for thumb resize, so it doesnt overwrite the original image Image tempImage = System.Drawing.Image.FromFile(path); //Create new database file using tempimage properties funcs.insertImageToDB(tempImage.Height, tempImage.Width, (int)(new System.IO.FileInfo(path).Length / 1000), fileName, finalTags, description, Convert.ToInt16(FolderID)); //call resize on tempimage tempImage = funcs.ImageResize(tempImage, newSize); //resize tempimage using resize method in tools //save tempimage to server tempImage.Save(Server.MapPath("~/Images/User/" + fileName.Split('.')[0] + "_thumb." + fileName.Split('.')[1]), fileExtension); //save temp image //Clear connection to image tempImage.Dispose(); Tools.uploaded = true; } //Error else { Tools.uploaded = false; } return RedirectToAction("UploadImage"); }