public ActionResult Edit(int id, Announcement announce, HttpPostedFileBase file) { int imageid; PODBProjectEntities entities = new PODBProjectEntities(); String userId = User.Identity.GetUserId(); PostPhoto photo = new PostPhoto(); String path = photo.PostPhotoAnnouncement(file); if (file != null) { imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID; } else { imageid = entities.PetProfiles.Where(e => e.petId.Equals(id)).FirstOrDefault().imageID; } try { using (PODBProjectEntities announcement = new PODBProjectEntities()) { announce.Id = User.Identity.GetUserId(); announce.announceDate = DateTime.Now; announce.imageID = imageid; announcement.Entry(announce).State = EntityState.Modified; announcement.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Announcement announce, HttpPostedFileBase file) { PODBProjectEntities entities = new PODBProjectEntities(); PostPhoto photo = new PostPhoto(); String path = photo.PostPhotoAnnouncement(file); int ImageID = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID; try { using (PODBProjectEntities announcement = new PODBProjectEntities()) { announce.Id = User.Identity.GetUserId(); announce.announceDate = DateTime.Now; announce.imageID = ImageID; entities.Announcements.Add(announce); entities.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }