public ActionResult AddImage(HttpPostedFileBase ImagePath) { if (ImagePath != null) { // This forces user to upload images of // specified resolution. System.Drawing.Image img = System.Drawing.Image.FromStream(ImagePath.InputStream); if ((img.Width != 800 && img.Height != 356)) { ModelState.AddModelError("", "Image resolution must be 800 x 356 pixels."); return(View()); } // Upload pic string pic = System.IO.Path.GetFileName(ImagePath.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/Content/Images/"), pic); ImagePath.SaveAs(path); using (WineContext db = new WineContext()) { SliderPic sliderPic = new SliderPic { ImageURL = "~/Content/Images/" + pic, Name = pic }; db.SliderPics.Add(sliderPic); db.SaveChanges(); } } return(RedirectToAction("Index")); }
// Delete multiple copies of images public ActionResult DeleteImages() { using (WineContext db = new WineContext()) { return(View(db.SliderPics.ToList())); } }
public static List <GrapeVarietal> GetAllGrapeVarietals() { using (var context = new WineContext()) { return(context.Varietals.ToList()); } }
//Add images in slider public ActionResult AddImage() { using (WineContext db = new WineContext()) { return(View(db.SliderPics.ToList())); } //return View(); }
static async Task Main(string[] args) { var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: false).Build(); var connectionString = config.GetConnectionString("VinmonopoletProducts"); var builder = new DbContextOptionsBuilder <WineContext>(); builder.UseNpgsql(connectionString); var dbContext = new WineContext(builder.Options); await dbContext.Database.MigrateAsync(); }
public DbService() { try { var v = new StackFrame(1, true).GetMethod(); Context = new WineContext(); } catch (Exception ex) { throw ex; } }
// ********************************************************* // ********* GET: ListWine View **************************** // ********************************************************* public ActionResult Index() { // ************************************************* // *** Establish New WineContext (Plate of Data) *** // *** And Return the list of wine ***************** // ************************************************* using (var context = new WineContext()) { var x = context.Wines.Include(w => w.TheVarietal).ToList(); return(View("ListWine", x)); } }
// ************************************************ // **** Wine To Delete (Get) Method *************** // **** GET: /Wine/Delete/ ******************* // ************************************************ public ActionResult Delete(int?id) { using (var winedB = new WineContext()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Wine wine = winedB.Wines.Include(w => w.TheVarietal).Single(w => w.Id == id); if (wine == null) { return(HttpNotFound()); } // ****************************************** // *** If Wine To Delete Is Not Null, Set *** // *** A New WineDeleteViewModel Equal To *** // *** To The Wine To Delete *** // ****************************************** var wineDeleteVm = new WineDeleteViewModel { id = wine.Id, Name = wine.Name, Varietal = new VarietalModel { GrapeFam = wine.TheVarietal.grapeFam, VarietalName = wine.TheVarietal.Name, VarietalpictureUrl = wine.TheVarietal.pictureUrl }, AVA = wine.AVA, ABV = wine.ABV, btlVol = wine.btlVol, btlVolUOM = wine.btlVolUOM, fluidOz = wine.fluidOz, Winetype = wine.TheWineType, TTBWineClass = wine.TheTTBWineClass }; // ******************************************** // *** Return the Delete Wine View with the *** // *** Wine To Delete View Model Variable *** // ******************************************** return(View("DeleteWine", wineDeleteVm)); } }
public ActionResult DeleteImages(IEnumerable <int> ImageIDs) { using (WineContext db = new WineContext()) { foreach (var id in ImageIDs) { var image = db.SliderPics.Single(s => s.Id == id); string imgPath = Server.MapPath(image.ImageURL); db.SliderPics.Remove(image); if (System.IO.File.Exists(imgPath)) { System.IO.File.Delete(imgPath); } } db.SaveChanges(); } return(RedirectToAction("DeleteImages")); }
// ********************************************************* // ********* GET: ListPermitsByState View **************************** // ********************************************************* public ActionResult GetPermitsActionResult() { // ************************************************* // *** Establish New WineContext (Plate of Data) *** // *** And Return the list of wine ***************** // ************************************************* using (var WineContext = new WineContext()) { //var TTBAllPermits = Repository.GetAllPermits().ToList(); // Query for all permits var allpermits = WineContext.TTBActiveWinePermits; //var blogs = WineContext.TTBActiveWinePermits.SqlQuery("SELECT * FROM dbo.TTBActiveWinePermits").ToList(); return(View("TTBActiveWinePermits", allpermits)); } }
public ActionResult DeleteConfirmed(int id) { // ****************************************** // ******* Establish New Data Context ******* // ******* Wine To Delete Variable ******* // ******* Utilize the Include Method ******* // ******* To Avoid LazyLoading Null ******* // ******* Issue That Would Cause An ******* // ******* Exception To Be Thrown ******* // ****************************************** using (var WinedB = new WineContext()) { Wine wineToDelete = WinedB.Wines.Include(w => w.TheVarietal).Single(w => w.Id == id); WinedB.Wines.Remove(wineToDelete); WinedB.SaveChanges(); return(RedirectToAction("Index")); }; }
public ActionResult Index() { //using (WineContext db = new WineContext()) //{ // return View(db.sliderPics.ToList()); // //return View(); //} // ************************************************* // *** Establish New WineContext (Plate of Data) *** // *** And Return the list of wine ***************** // ************************************************* using (WineContext db = new WineContext()) { //Console.WriteLine(db.Database); //var x = context.SliderPics.Include(g => g.SliderPic).ToList(); return(View(db.SliderPics.ToList())); //return View("Index", x); } }
public DeleteEveryThing(WineContext context) { _context = context; }
public ProductSearchQueryHandler(WineContext context) { _db = context; }
public ProductSearchController(WineContext context, Messaging messaging) { _db = context; _messaging = messaging; }
public UpdateVinmonopoletRepositoryCommandHandler(IHttpClientFactory httpClientFactory, WineContext wineContext) { _httpClient = httpClientFactory.CreateClient(); _db = wineContext; }
public WineController(WineContext context) { _context = context; }
public AddressController(WineContext context) { _context = context; }
public InventoryProductsController(WineContext context, Messaging messaging) { _db = context; _messaging = messaging; }
public ActionResult AddWine2(Models.ViewModels.WineAddViewModel wine) { // **************************************************** // ********* Check To Make Sure Model Is Valid ******** // **************************************************** if (ModelState.IsValid) { wine.VarietalsToChooseFrom = Repository.GetAllGrapeVarietals(); using (var context = new WineContext()) { // ************************************************* // * Might Be Useful To Cache For Some Time In The * // * Future To Make Sure That User Does Not Try * // * To Pass A Varietal To DB That Does Not Exist * // ************************************************* var varietalFromDb = context.Varietals.FirstOrDefault(v => v.Id == wine.TheWine.Varietal.VarietalId) ; if (varietalFromDb == null) { throw new Exception("Received an invalid varietal name."); } //****************************************** //*** Map Field Names For The Database ***** //*** In New dbWine Variable *************** //****************************************** var dbWine = new Wine { ABV = wine.TheWine.ABV, AVA = wine.TheWine.AVA, btlVol = wine.TheWine.btlVol, btlVolUOM = wine.TheWine.btlVolUOM, fluidOz = wine.TheWine.fluidOz, Id = wine.TheWine.Id, Name = wine.TheWine.Name, TheVarietal = varietalFromDb, TheWineType = wine.TheWine.WineType, TheTTBWineClass = wine.TheWineClass, Description = wine.TheWine.Description, WineryURL = wine.TheWine.WineryURL }; // ***************************************** // *** Add The New Wine To The Database **** // *** And Save The Changes **************** // ***************************************** context.Wines.Add(dbWine); context.SaveChanges(); } //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // CODE NOTE USED CODE NOT USED //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ var blankWine = new WineAddViewModel { ShowSuccessMsg = true, //SelectedVarietalId = null, TheWine = new WineModel(), VarietalsToChooseFrom = Repository.GetAllGrapeVarietals(), }; //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // CODE NOTE USED CODE NOT USED //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ return(RedirectToAction("Index", "Wine", wine)); } // ************************************************* // *** Repopulate Varietals To Choose From ********* // ************************************************* wine.VarietalsToChooseFrom = Repository.GetAllGrapeVarietals(); //Return Some Error View - to be added... throw new NotImplementedException("Dealing With Errors"); }
public WineByManufactuerController(WineContext context) { _context = context; }
public ClimatesController(WineContext context) { _context = context; }