Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        // Delete multiple copies of images

        public ActionResult DeleteImages()
        {
            using (WineContext db = new WineContext())
            {
                return(View(db.SliderPics.ToList()));
            }
        }
Exemplo n.º 3
0
 public static List <GrapeVarietal> GetAllGrapeVarietals()
 {
     using (var context = new WineContext())
     {
         return(context.Varietals.ToList());
     }
 }
Exemplo n.º 4
0
        //Add images in slider

        public ActionResult AddImage()
        {
            using (WineContext db = new WineContext())
            {
                return(View(db.SliderPics.ToList()));
            }
            //return View();
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
 public DbService()
 {
     try
     {
         var v = new StackFrame(1, true).GetMethod();
         Context = new WineContext();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 7
0
        // *********************************************************
        // ********* 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));
            }
        }
Exemplo n.º 8
0
        // ************************************************
        // **** 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));
            }
        }
Exemplo n.º 9
0
 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"));
 }
Exemplo n.º 10
0
        // *********************************************************
        // ********* 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));
            }
        }
Exemplo n.º 11
0
        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"));
            };
        }
Exemplo n.º 12
0
        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);
            }
        }
Exemplo n.º 13
0
 public DeleteEveryThing(WineContext context)
 {
     _context = context;
 }
Exemplo n.º 14
0
 public ProductSearchQueryHandler(WineContext context)
 {
     _db = context;
 }
Exemplo n.º 15
0
 public ProductSearchController(WineContext context, Messaging messaging)
 {
     _db        = context;
     _messaging = messaging;
 }
 public UpdateVinmonopoletRepositoryCommandHandler(IHttpClientFactory httpClientFactory, WineContext wineContext)
 {
     _httpClient = httpClientFactory.CreateClient();
     _db         = wineContext;
 }
Exemplo n.º 17
0
 public WineController(WineContext context)
 {
     _context = context;
 }
Exemplo n.º 18
0
 public AddressController(WineContext context)
 {
     _context = context;
 }
 public InventoryProductsController(WineContext context, Messaging messaging)
 {
     _db        = context;
     _messaging = messaging;
 }
Exemplo n.º 20
0
        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");
        }
Exemplo n.º 21
0
 public WineByManufactuerController(WineContext context)
 {
     _context = context;
 }
 public ClimatesController(WineContext context)
 {
     _context = context;
 }