public JsonResult AddPhotoToAttraction(string tokken, int attrId, int userId = 0) { //check user role for permission?? byte[] image = new byte[Request.InputStream.Length]; Request.InputStream.Read(image, 0, image.Length); if (Request.InputStream.Length == 0) { return(Json("false", JsonRequestBehavior.AllowGet)); } MemoryStream ms = new MemoryStream(image); Bitmap bitmap = new Bitmap(ms); var name = HashHelper.CalculateMD5Hash(new Guid().ToString()); String path = HttpContext.Server.MapPath("~/Content/AttractionImages"); bitmap.Save(path + "/" + name + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); var ati = new AttractionImage() { AttractionID = attrId, FileName = name + ".jpg" }; db.AttractionImage.Add(ati); db.SaveChanges(); return(Json("true", JsonRequestBehavior.AllowGet)); }
public ActionResult Approve(int id) { AttractionImage approved = db.AttractionImage.Where(x => x.ID == id).Single(); approved.isApproved = 1; db.SaveChanges(); return(RedirectToAction("Index")); }
void ReleaseDesignerOutlets() { if (AttractionImage != null) { AttractionImage.Dispose(); AttractionImage = null; } if (BackgroundImage != null) { BackgroundImage.Dispose(); BackgroundImage = null; } if (City != null) { City.Dispose(); City = null; } if (IsFavorite != null) { IsFavorite.Dispose(); IsFavorite = null; } if (IsFlighBooked != null) { IsFlighBooked.Dispose(); IsFlighBooked = null; } if (IsDirections != null) { IsDirections.Dispose(); IsDirections = null; } if (SubTitle != null) { SubTitle.Dispose(); SubTitle = null; } if (Title != null) { Title.Dispose(); Title = null; } }
private void SaveBtn_Click(object sender, RoutedEventArgs e) { StringBuilder errors = new StringBuilder(); if (String.IsNullOrEmpty(NameBox.Text)) { errors.Append("Поле названии не заполнено"); } if (String.IsNullOrEmpty(PlaceCombo.Text)) { errors.Append("Поле местоположения не заполнено"); } if (String.IsNullOrEmpty(DescriptionBox.Text)) { errors.Append("Поле описании не заполнено"); } //Валидация if (errors.Length > 0) { MessageBox.Show(errors.ToString(), "Внимание", MessageBoxButton.OK, MessageBoxImage.Error); return; } foreach (var source in sources) { AttractionImage AttractionImages = new AttractionImage(); AttractionImages.Source = source; AttractionImages.Attraction = editAttraction; AttractionImagess.Add(AttractionImages); } if (AttractionImagess.Count >= 0) { editAttraction.AttractionImage = AttractionImagess; } DBHelper.GetContext().SaveChanges(); this.Close(); MessageBox.Show("Изменения сохранены", "Успешно", MessageBoxButton.OK, MessageBoxImage.Information); }
public ActionResult ImageCreate(int AttractionId, String Author, String FileName, String Title) { AttractionImage image = new AttractionImage(); image.AttractionID = AttractionId; image.isApproved = 0; image.Author = Author; image.Title = Title; try { int i = 0; foreach (string upload in Request.Files) { if (Request.Files[i].ContentLength == 0) { continue; } string path = AppDomain.CurrentDomain.BaseDirectory + "Content/AttractionImages/"; string ext = Request.Files[i].FileName.Substring(Request.Files[i].FileName.LastIndexOf('.')); image.FileName = generateRandomString(32) + ext; System.Diagnostics.Debug.WriteLine(image.FileName); Request.Files[i].SaveAs(Path.Combine(path, image.FileName)); i++; } } catch (NullReferenceException) { //no photo } db.AttractionImage.Add(image); db.SaveChanges(); return(RedirectToAction("Details", new { id = image.AttractionID })); //return View("GetImage", image); }
public ActionResult Create(Attraction attraction) { attraction.AttractionType = db.AttractionType.Find(attraction.AttractionType.ID); attraction.Country = db.Country.Find(attraction.Country.ID); attraction.AvgRating = 0.0; //upload photos try { int i = 0; foreach (string upload in Request.Files) { if (Request.Files[i].ContentLength == 0) { continue; } string path = AppDomain.CurrentDomain.BaseDirectory + "Content/AttractionImages/"; string ext = Request.Files[i].FileName.Substring(Request.Files[i].FileName.LastIndexOf('.')); AttractionImage ai = new AttractionImage { AttractionID = attraction.ID, FileName = generateRandomString(32) + ext }; attraction.Images.Add(ai); Request.Files[i].SaveAs(Path.Combine(path, ai.FileName)); i++; } } catch (NullReferenceException) { //no photo } //end of upload user photo db.Attraction.Add(attraction); db.SaveChanges(); return(RedirectToAction("Details", new { id = attraction.ID })); }