public void InsertOrUpdate(GalleryImage galleryimage) { if (galleryimage.ID == default(int)) { // New entity context.GalleryImage.Add(galleryimage); } else { // Existing entity context.GalleryImage.Attach(galleryimage); context.Entry(galleryimage).State = EntityState.Modified; } }
public ActionResult Create(GalleryImage galleryimage, HttpPostedFileBase file) { // TODO UserID muss aus Session kommen //galleryimage.CreatedOn = DateTime.UtcNow; //galleryimage.UserID = 1; //if (ModelState.IsValid) { // galleryimageRepository.InsertOrUpdate(galleryimage); // galleryimageRepository.Save(); // return RedirectToAction("Index"); //} else { return View(); //} }
public void Upload(HttpPostedFileBase FileData) { try { string path = UserContext.GetCurrent().ID + @"\" + "Gallery" + @"\"; FileHelper.WriteFile(HttpContext.Server.MapPath("~") + ConfigurationManager.AppSettings["UserContentBasePath"] + @"\" + path, FileData.FileName, FileData.InputStream); GalleryImage galleryimage = new GalleryImage(); galleryimage.CreatedOn = DateTime.UtcNow; galleryimage.ID = default(int); galleryimage.NumberOfViews = 0; galleryimage.Url = path + FileData.FileName; galleryimage.UserID = UserContext.GetCurrent().ID; galleryimageRepository.InsertOrUpdate(galleryimage); galleryimageRepository.Save(); } catch (Exception e) { throw e; } }
public ActionResult Edit(GalleryImage galleryimage) { if (ModelState.IsValid) { galleryimageRepository.InsertOrUpdate(galleryimage); galleryimageRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleUser = userRepository.All; return View(); } }