public ActionResult Create(int id, FormCollection collection, HttpPostedFileBase newPicture) { try { // TODO: Add insert logic here // mime type checking string[] types = { "image/gif", "image/jpeg", "image/png" }; if (newPicture != null && newPicture.ContentLength > 0 && types.Contains(newPicture.ContentType)) { Models.Picture newPic = new Models.Picture() { caption = collection["caption"], time_info = collection["time_info"], loc_info = collection["loc_info"], relative_path = SavePicture(newPicture), person_id = id }; db.Pictures.Add(newPic); db.SaveChanges(); } return(RedirectToAction("Index", new { id = id })); } catch { return(View()); } }
public ActionResult Edit(int id, FormCollection collection, HttpPostedFileBase thePicture)//Picture ID { try { // TODO: Add update logic here string[] types = { "image/gif", "image/jpeg", "image/png" }; if (thePicture != null && thePicture.ContentLength > 0 && types.Contains(thePicture.ContentType)) { Guid g = Guid.NewGuid(); string filename = g.ToString() + Path.GetExtension(thePicture.FileName); string path = Server.MapPath("~/Images/"); path = Path.Combine(path, filename); thePicture.SaveAs(path); Models.Picture aPicture = database.Pictures.SingleOrDefault(p => p.picture_id == id); aPicture.caption = collection["caption"]; aPicture.time = collection["time"]; aPicture.location = collection["location"]; aPicture.path = filename; database.SaveChanges(); } return(RedirectToAction("Index", new { id = id })); } catch { return(View()); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == id); thePicture.Profile.picture_id = null; string path = Server.MapPath("~/Images/" + thePicture.path); System.IO.File.Delete(path); database.SaveChanges(); database.Comments.RemoveRange(thePicture.Comments); database.Likes.RemoveRange(thePicture.Likes); database.SaveChanges(); database.Pictures.Remove(thePicture); database.SaveChanges(); return(RedirectToAction("Index", new { id = thePicture.profile_id })); } catch { return(View()); } }
private async void GetImages(AppPreferences ap) { if (!String.IsNullOrEmpty(imageNames[0])) { Bitmap bit = ap.SetImageBitmap(ap.CreateDirectoryForPictures() + "/" + imageNames[0]); if (bit != null) { pictureHolder.SetImageBitmap(bit); } else if (bit == null && !String.IsNullOrEmpty(imageNames[0])) { PictureViewModel pictureViewModel = new PictureViewModel(); Models.Picture picture = await pictureViewModel.ExecuteGetPictureCommand(imageNames[0]); if (picture != null) { var _bit = ap.StringToBitMap(picture.File); if (_bit != null) { ap.SaveImage(_bit, imageNames[0]); } pictureHolder.SetImageBitmap(_bit); } } } }
public ActionResult Edit(int id, FormCollection collection, HttpPostedFileBase newPicture) { try { // TODO: Add update logic here Models.Picture picture = db.Pictures.SingleOrDefault(p => p.picture_id == id); // mime type checking string[] types = { "image/gif", "image/jpeg", "image/png" }; picture.caption = collection["caption"]; picture.time_info = collection["time_info"]; picture.loc_info = collection["loc_info"]; if (newPicture != null && newPicture.ContentLength > 0 && types.Contains(newPicture.ContentType)) { DeletePicture(picture.relative_path); picture.relative_path = SavePicture(newPicture); } db.SaveChanges(); return(RedirectToAction("Index", new { id = picture.person_id })); } catch { return(View()); } }
public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here int id = int.Parse(Session["picture_id"].ToString()); Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == id); Models.Comment newComment = new Models.Comment() { picture_id = thePicture.picture_id, profile_id = thePicture.profile_id, comment1 = collection["comment1"], timestamp = DateTime.Now, read = 0 }; database.Comments.Add(newComment); database.SaveChanges(); return(RedirectToAction("Index", new { id = id })); } catch { return(View()); } }
public ActionResult Edit(int id, FormCollection collection, HttpPostedFileBase thePicture) { try { // TODO: Add update logic here var type = thePicture.ContentType; string[] acceptableTypes = { "image/jpeg", "image/gif", "image/png" }; Models.Picture thePic = db.Pictures.SingleOrDefault(c => c.picture_id == id); if (thePicture != null && thePicture.ContentLength > 0 && acceptableTypes.Contains(type)) { Guid g = Guid.NewGuid(); String filename = g.ToString() + Path.GetExtension(thePicture.FileName); String path = Path.Combine(Server.MapPath("~/Images/") + filename); thePicture.SaveAs(path); thePic.caption = collection["caption"]; thePic.path = filename; thePic.loc_info = collection["loc_info"]; thePic.time_info = collection["time_info"]; db.SaveChanges(); } return(RedirectToAction("Index", new { id = thePic.person_id })); } catch { return(View()); } }
public void ComparePictures(MyContext context, int pictureId1, int pictureId2, ref Boolean couldCompare) { try { Models.Picture[] pictures = new Models.Picture[2]; pictures[0] = GetImage(context, pictureId1); pictures[1] = GetImage(context, pictureId2); System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"C:\Users\Jesper\Documents\Datamatiker\4. Semester\Projekt\Pictures\Training\Dogs\dog2.jpg"); byte[] data = new byte[fileInfo.Length]; using (System.IO.FileStream fs = fileInfo.OpenRead()) { fs.Read(data, 0, data.Length); } string imageString = Convert.ToBase64String(data); var Picture = new Models.Picture { ImageString = imageString, PictureTakenDate = DateTime.Now.Date, UserTaken = false, SectionId = pictures[0].SectionId }; context.Pictures.Add(Picture); context.SaveChanges(); couldCompare = true; } catch (Exception e) { } }
// GET: Comment public ActionResult Index(int id) { ViewBag.id = id; int personId = Int32.Parse(Session["person_id"].ToString()); Models.Picture thePicutre = db.Pictures.SingleOrDefault(c => c.picture_id == id); int counter = 0; int counterCommentLike = Int32.Parse(Session["new_CommentLikes"].ToString()); IEnumerable <Models.Comment> yourComment = db.Comments.Where(c => c.person_id == personId); foreach (Models.Comment_like ML in db.Comment_like.ToList()) { if (yourComment.Contains(db.Comments.SingleOrDefault(c => c.comment_id == ML.comment_id)) && ML.read.Equals("Not read")) { counter++; ML.read = "Read"; } } db.SaveChanges(); counterCommentLike -= counter; Session["new_CommentLikes"] = counterCommentLike; return(View(thePicutre)); }
public ActionResult Create(int id, FormCollection collection, HttpPostedFileBase newPicture) { try { var type = newPicture.ContentType; string[] acceptableTypes = { "image/jpeg", "image/gif", "image/png" }; if (newPicture != null && newPicture.ContentLength > 0 && acceptableTypes.Contains(type)) { Guid g = Guid.NewGuid(); string filename = g.ToString() + Path.GetExtension(newPicture.FileName); string path = Path.Combine(Server.MapPath("~/Images/") + filename); newPicture.SaveAs(path); Models.Picture newPic = new Models.Picture() { caption = collection["Caption"], path_of_picture = filename, location_info = collection["Location"], person_id = id, time_info = collection["Time"] }; db.Pictures.Add(newPic); db.SaveChanges(); } return(RedirectToAction("Index", new { id = id })); } catch { return(View()); } }
public ActionResult Create(int id, FormCollection collection, HttpPostedFileBase picture) { try { string[] allowedPicTypes = { "image/png", "image/jpeg", "image/gif", "image/bmp", "image/svg+xml", "image/tiff", "image/x-icon" }; if (picture != null && allowedPicTypes.Contains(picture.ContentType) && picture.ContentLength > 0) { Guid g = Guid.NewGuid(); string filename = g.ToString() + Path.GetExtension(picture.FileName); string picPath = Path.Combine(Server.MapPath("~/Pictures/"), filename); picture.SaveAs(picPath); // TODO: Add insert logic here Models.Picture newPicture = new Models.Picture() { caption = collection["caption"], picture_path = "~/Pictures/" + filename, location = collection["location"], profile_id = id }; db.Pictures.Add(newPicture); db.SaveChanges(); } return(RedirectToAction("Index", new { id = id })); } catch { ViewBag.id = id; return(View()); } }
public ActionResult MakeMyProfile(int id) { Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == id); thePicture.Person.picture_id = id; database.SaveChanges(); return(RedirectToAction("Index", new { id = thePicture.person_id })); }
public ActionResult makeThisProfile(int id) { Models.Picture picture = db.Pictures.SingleOrDefault(p => p.picture_id == id); picture.Person.picture_id = id; db.SaveChanges(); return(RedirectToAction("Index", new { id = picture.person_id })); }
// GET: Comment public ActionResult Index(int id) { Session["picture_id"] = id; Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == id); int profile_id = (int)Session["user_id"]; ViewBag.theCommentLike = database.Comment_Like.Where(c => c.profile_id == profile_id); return(View(thePicture)); }
public ActionResult UnLikePicture(int id) { Models.Like likePicture = database.Likes.SingleOrDefault(p => p.picture_id == id); Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == id); database.Likes.Remove(likePicture); database.SaveChanges(); return(RedirectToAction("Details", new { id = thePicture.profile_id })); }
public void SavePicture(MyContext context, Models.Picture picture) { try { context.Picutres.Add(picture); context.SaveChanges(); } catch (Exception e) { string error = e.Message; } }
// GET: Picture/Edit/5 public ActionResult Edit(int id) { //authorization based on ownership Models.Picture picture = db.Pictures.SingleOrDefault(p => p.picture_id == id); int myId = int.Parse(Session["user_id"].ToString()); if (picture.person_id != myId) { return(RedirectToAction("Index")); } return(View(picture)); }
public ActionResult UnlikePic(int id) { int personId = Int32.Parse(Session["person_id"].ToString()); Models.Like theLike = db.Likes.SingleOrDefault(c => c.person_id == personId && c.picture_id == id); Models.Picture thePerson = db.Pictures.SingleOrDefault(c => c.picture_id == theLike.picture_id); db.Likes.Remove(theLike); db.SaveChanges(); return(RedirectToAction("Index", new { id = thePerson.person_id })); }
private async void GetImages(AppPreferences ap) { if (!String.IsNullOrEmpty(imageNames[0])) { Bitmap bit = ap.SetImageBitmap(_dir + "/" + imageNames[0]); if (bit != null) { facilityPhoto.SetImageBitmap(bit); } else if (bit == null && !String.IsNullOrEmpty(imageNames[0])) { PictureViewModel pictureViewModel = new PictureViewModel(); Models.Picture picture = await pictureViewModel.ExecuteGetPictureCommand(imageNames[0]); if (picture != null) { var _bit = ap.StringToBitMap(picture.File); if (_bit != null) { ap.SaveImage(_bit, imageNames[0]); } facilityPhoto.SetImageBitmap(_bit); } } } if (imageNames.Count > 1) { Bitmap bit = ap.SetImageBitmap(_dir + "/" + imageNames[1]); if (bit != null) { secondFacilityPhoto.SetImageBitmap(bit); } else if (bit == null && !String.IsNullOrEmpty(imageNames[1])) { PictureViewModel pictureViewModel = new PictureViewModel(); Models.Picture picture = await pictureViewModel.ExecuteGetPictureCommand(imageNames[1]); if (picture != null) { var _bit = ap.StringToBitMap(picture.File); if (_bit != null) { ap.SaveImage(_bit, imageNames[1]); } secondFacilityPhoto.SetImageBitmap(_bit); } } } }
public ActionResult Guess(Models.Picture picture, string guessedPrice) { Models.Picture[] pictures = (Models.Picture[])Session["Pictures"];; int index = (int)Session["Index"]; long price = 0; ViewBag.guessedPrice = guessedPrice; if (Int64.TryParse(guessedPrice, out price)) { return(View(pictures[index])); } else { return(View("Index", pictures[index])); } }
public ActionResult Delete(int id, FormCollection collection)//Picture ID { try { // TODO: Add delete logic here Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == id); database.Pictures.Remove(thePicture); database.SaveChanges(); return(RedirectToAction("Index", new { id = thePicture.person_id })); } catch { return(View()); } }
public static Models.Picture ReadPicture(HttpPostedFileBase upload) { if (upload == null) { return(null); } var avatar = new Models.Picture { FileName = System.IO.Path.GetFileName(upload.FileName), PictureType = Models.PictureType.Avatar, ContentType = upload.ContentType }; HttpPostedFileBase uploadforMini = upload; //make small upload.InputStream.Seek(0, 0); using (var stream = new System.IO.MemoryStream()) { ImageResizer.ImageJob image = new ImageResizer.ImageJob(upload, stream, new ImageResizer.Instructions("width=200;height=200;crop=auto;format=jpg;anchor=middlecenter;autorotate=true;quality=100")); image.Build(); System.Drawing.Image Image = System.Drawing.Image.FromStream(stream); System.IO.MemoryStream ms = new System.IO.MemoryStream(); Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); avatar.Content = ms.ToArray(); //make smaller uploadforMini.InputStream.Seek(0, 0); using (var streamMini = new System.IO.MemoryStream()) { ImageResizer.ImageJob imageMini = new ImageResizer.ImageJob(uploadforMini, streamMini, new ImageResizer.Instructions("width=50;height=50;crop=auto;format=jpg;anchor=middlecenter;autorotate=true;quality=100")); imageMini.Build(); System.Drawing.Image ImageMini = System.Drawing.Image.FromStream(streamMini); System.IO.MemoryStream msMini = new System.IO.MemoryStream(); ImageMini.Save(msMini, System.Drawing.Imaging.ImageFormat.Jpeg); avatar.ContentMini = msMini.ToArray(); return(avatar); //} } } //return null; }
public void EqualityTest() { Models.Picture pictureOne = new Models.Picture("apple.png"); Models.Picture pictureTwo = new Models.Picture("apple.png"); Models.Picture pictureThree = new Models.Picture("apple2.png"); Assert.IsTrue(pictureOne.GetDifferences(pictureTwo).Count == 0); var points = pictureOne.GetDifferences(pictureThree); Assert.IsTrue(points.Count == 2); Console.WriteLine(points[0].ToString()); Console.WriteLine(points[1].ToString()); Assert.IsTrue(pictureOne == pictureTwo); }
//public static Models.Picture GetPicture(HttpPostedFileBase upload) //{ // var avatar = new Models.Picture // { // FileName = System.IO.Path.GetFileName(upload.FileName), // PictureType = Models.PictureType.Avatar, // ContentType = upload.ContentType // }; // avatar.ContentMini= //} public static Models.Picture ReadPicture(string filename) { var avatar = new Models.Picture { FileName = filename, PictureType = Models.PictureType.Avatar, ContentType = "NoPic", }; System.Drawing.Image img = System.Drawing.Image.FromFile(filename); using (System.IO.MemoryStream mStream = new System.IO.MemoryStream()) { img.Save(mStream, img.RawFormat); avatar.ContentMini = mStream.ToArray(); avatar.Content = mStream.ToArray(); return(avatar); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here Models.Picture thePicture = db.Pictures.SingleOrDefault(c => c.picture_id == id); var filePath = Server.MapPath("~/Images/" + thePicture.path); System.IO.File.Delete(filePath); db.Pictures.Remove(thePicture); db.SaveChanges(); return(RedirectToAction("Index", new { id = thePicture.person_id })); } catch { return(View()); } }
public ActionResult LikePic(int id) { int personId = Int32.Parse(Session["person_id"].ToString()); Models.Like newLike = new Models.Like() { person_id = personId, picture_id = id, timestamp = DateTime.Now.ToString(), read = "Not read" }; Models.Picture thePerson = db.Pictures.SingleOrDefault(c => c.picture_id == newLike.picture_id); db.Likes.Add(newLike); db.SaveChanges(); ViewBag.liked = db.Likes.SingleOrDefault(c => c.person_id == personId && c.picture_id == id); return(RedirectToAction("Index", new { id = thePerson.person_id })); }
public Boolean DeleteImage(MyContext context, int pictureId) { Boolean couldDelete = false; try { var toDelete = new Models.Picture { PictureId = pictureId }; context.Pictures.Attach(toDelete); context.Pictures.Remove(toDelete); context.SaveChanges(); couldDelete = true; } catch (Exception e) { string error = e.Message; } return(couldDelete); }
public ActionResult LikeComment(int id) { // TODO: Add insert logic here int picture_id = int.Parse(Session["picture_id"].ToString()); Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == picture_id); Models.Comment theComment = database.Comments.SingleOrDefault(c => c.comment_id == id); Models.Comment_Like likeComment = new Models.Comment_Like() { comment_id = theComment.comment_id, profile_id = thePicture.profile_id, timestamp = DateTime.Now, read = 0 }; database.Comment_Like.Add(likeComment); database.SaveChanges(); return(RedirectToAction("Index", new { id = theComment.picture_id })); }
public ActionResult LikePicture(int id) { // TODO: Add insert logic here int user_id = int.Parse(Session["user_id"].ToString()); Models.Profile theProfile = database.Profiles.SingleOrDefault(p => p.user_id == user_id); Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == id); Models.Like likePicture = new Models.Like() { picture_id = thePicture.picture_id, profile_id = theProfile.profile_id, timestamp = DateTime.Now, read = 0 }; database.Likes.Add(likePicture); database.SaveChanges(); return(RedirectToAction("Index", new { id = thePicture.profile_id })); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here Models.Picture picture = db.Pictures.SingleOrDefault(p => p.picture_id == id); if (picture.Person.picture_id == id) { picture.Person.picture_id = null; } DeletePicture(picture.relative_path); db.Pictures.Remove(picture); db.SaveChanges(); return(RedirectToAction("Index", new { id = picture.person_id })); } catch { return(View()); } }
public ActionResult UploadPicture(HttpPostedFileBase file) { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the filename var fileName = Path.GetFileName(file.FileName); var extension = Path.GetExtension(file.FileName); var newPicture = new Models.Picture(); newPicture.Date = DateTime.Now; newPicture.FileName = DateTime.Now.ToString("yyyyMMddHHmmss") + extension; newPicture.Description = ""; // store the file inside the right folder var path = Path.Combine(Server.MapPath("~/Images/ImageUploads/"), newPicture.FileName); file.SaveAs(path); db.Pictures.Add(newPicture); db.SaveChanges(); } //return RedirectToAction("UploadPictures"); return RedirectToAction("Pictures"); }
public ActionResult SignUp(string username, string password, string mail, HttpPostedFileBase picture) { MembershipUser user = Membership.CreateUser(username, password, mail); if (picture != null) { Models.Picture p = new Models.Picture(); p.Id = new Guid(user.ProviderUserKey.ToString()); p.Link = Guid.NewGuid().ToString().Replace("-", ""); string ext = Path.GetExtension(picture.FileName); p.Link += ext; picture.SaveAs(Server.MapPath("~/ProfilePictures/" + p.Link)); Models.YoyoEntities db = new Models.YoyoEntities(); db.Pictures.Add(p); db.SaveChanges(); } FormsAuthentication.SetAuthCookie(username, true); return RedirectToAction("Index"); }