public ActionResult Create(Photo photo, IEnumerable<HttpPostedFileBase> files) { var context = new TourEntities1(); if (!ModelState.IsValid) return View(photo); if (files.Count() == 0 || files.FirstOrDefault() == null) { ViewBag.error = "Please choose a file"; return View(photo); } foreach (var file in files) { if (file.ContentLength == 0) continue; var model = new Photo(); model.Decription = photo.Decription; var fileName = Guid.NewGuid().ToString(); var extension = System.IO.Path.GetExtension(file.FileName).ToLower(); MemoryStream ms = new MemoryStream(); file.InputStream.CopyTo(ms); file.InputStream.Dispose(); ms.Seek(0, SeekOrigin.Begin); //var img = System.Drawing.Image.FromStream(ms); //img.Save("./asd123.png"); using (var img1 = System.Drawing.Image.FromStream(ms)) { //model.ThumbPath = String.Format("~{2}ImageGallery{2}thumbs{2}{0}{1}", fileName, extension, Path.DirectorySeparatorChar); //model.ImagePath = String.Format("~{2}ImageGallery{2}{0}{1}", fileName, extension, Path.DirectorySeparatorChar); model.ThumbPath = String.Format("/ImageGallery/thumbs/{0}{1}", fileName, extension); model.ImagePath = String.Format("/ImageGallery/{0}{1}", fileName, extension); // Save thumbnail size image, 100 x 100 SaveToFolder(img1, fileName, extension, new Size(100, 100), model.ThumbPath); // Save large size image, 800 x 800 SaveToFolder(img1, fileName, extension, new Size(600, 600), model.ImagePath); } // Save record to database model.CreatedOn = DateTime.Now; context.Photo.Add(model); context.SaveChanges(); } return RedirectToAction("Index", "Photo"); }
public void SavePlacement(Placement b) { var context = new TourEntities1(); if (b.Id == 0) { context.Placement.Add(b); } else { Placement dbEntry = context.Placement.Find(b.Id); if (dbEntry != null) { dbEntry.Description = b.Description; dbEntry.Name = b.Name; } } context.SaveChanges(); }
public void SaveNews(News b) { var context = new TourEntities1(); if (b.Id == 0) { b.Date = DateTime.Now; context.News.Add(b); } else { News dbEntry = context.News.Find(b.Id); if (dbEntry != null) { dbEntry.Name = b.Name; dbEntry.Description = b.Description; dbEntry.Date = DateTime.Now; } } context.SaveChanges(); }
public void SaveResort(Resort b) { var context = new TourEntities1(); if (b.Id == 0) { context.Resort.Add(b); } else { Resort dbEntry = context.Resort.Find(b.Id); if (dbEntry != null) { dbEntry.Name = b.Name; dbEntry.Description = b.Description; dbEntry.CountryId = b.CountryId; dbEntry.ImageData = b.ImageData ?? dbEntry.ImageData; dbEntry.ImageMimeType = b.ImageMimeType; } } context.SaveChanges(); }
public void SaveHotTour(HotTours b) { var context = new TourEntities1(); if (b.Id == 0) { context.HotTours.Add(b); } else { HotTours dbEntry = context.HotTours.Find(b.Id); if (dbEntry != null) { dbEntry.Description = b.Description; dbEntry.Price = b.Price; dbEntry.Category = b.Category; dbEntry.ImageData = b.ImageData ?? dbEntry.ImageData; dbEntry.ImageMimeType = b.ImageMimeType; dbEntry.AmountPeople = b.AmountPeople; dbEntry.DepartureDay = b.DepartureDay; dbEntry.Food = b.Food; dbEntry.Period = b.Period; dbEntry.TourType = b.TourType; dbEntry.Location = b.Location; dbEntry.HotelId = b.HotelId; } } context.SaveChanges(); }
public void SaveHotel(Hotel b) { var context = new TourEntities1(); if (b.Id == 0) { context.Hotel.Add(b); } else { Hotel dbEntry = context.Hotel.Find(b.Id); if (dbEntry != null) { dbEntry.Name = b.Name; dbEntry.Description = b.Description; dbEntry.ImageData = b.ImageData ?? dbEntry.ImageData; dbEntry.ImageMimeType = b.ImageMimeType; dbEntry.Category = b.Category; dbEntry.CountryId = b.CountryId; dbEntry.ResortId = b.ResortId; } } context.SaveChanges(); }
public HotTours DeleteTour(int Id) { var context = new TourEntities1(); HotTours dbEntry = context.HotTours.Find(Id); if (dbEntry != null) { context.HotTours.Remove(dbEntry); context.SaveChanges(); } return dbEntry; }
public Resort DeleteResort(int Id) { var context = new TourEntities1(); Resort dbEntry = context.Resort.Find(Id); if (dbEntry != null) { context.Resort.Remove(dbEntry); context.SaveChanges(); } return dbEntry; }
public Country DeleteCountry(int Id) { var context = new TourEntities1(); Country dbEntry = context.Country.Find(Id); if (dbEntry != null) { context.Country.Remove(dbEntry); context.SaveChanges(); } return dbEntry; }