Example #1
0
        public IHttpActionResult PutTTBActiveWinePermitModel(string id, TTBActiveWinePermitModel tTBActiveWinePermitModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tTBActiveWinePermitModel.PERMIT_NUMBER)
            {
                return(BadRequest());
            }

            db.Entry(tTBActiveWinePermitModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TTBActiveWinePermitModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public IHttpActionResult PutWine(int id, Wine wine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != wine.Id)
            {
                return(BadRequest());
            }

            db.Entry(wine).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Create([Bind(Include = "WineID,Name,Vineyard,Description,ImageURL,BottlePrice,CasePrice,Grape")] Wine wine)
        {
            if (ModelState.IsValid)
            {
                db.Wines.Add(wine);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(wine));
        }
Example #4
0
        public ActionResult <Address> CreateAddress(Address addressCreate)
        {
            var address = _context.Addresses.Find(addressCreate.Id);

            if (address == null)
            {
                _context.Addresses.Add(addressCreate);
                _context.SaveChanges();

                return(CreatedAtRoute(nameof(GetAddressById), new { Id = addressCreate.Id }, addressCreate));
            }
            return(Conflict("Address already exits"));
        }
Example #5
0
        public ActionResult <Manufactuer> CreateWine(Manufactuer manufactuer)
        {
            Address address = _context.Addresses.Find(manufactuer.address.Id);

            if (address != null)
            {
                manufactuer.address = address;
            }

            _context.Manufactuers.Add(manufactuer);
            _context.SaveChanges();

            return(CreatedAtRoute(nameof(GetManufactuerById), new { Id = manufactuer.Id }, manufactuer));
        }
Example #6
0
        public ActionResult <Wine> CreateWine(Wine wineCreate)
        {
            var manufactuer = wineCreate.manufactuer;

            wineCreate.manufactuer = _context.Manufactuers.Find(wineCreate.manufactuer.Id);
            if (wineCreate.manufactuer == null)
            {
                wineCreate.manufactuer = manufactuer;
            }
            _context.Wines.Add(wineCreate);
            _context.SaveChanges();

            return(CreatedAtRoute(nameof(GetWineById), new { Id = wineCreate.Id }, wineCreate));
        }
Example #7
0
        public ActionResult deleteEveryThing(string token)
        {
            var wines = _context.Wines.ToList();
            var manufactuers = _context.Manufactuers.ToList();
            var addresses = _context.Addresses.ToList();

            if (token.Equals("$69420çH3llo2cönt"))
            {
                foreach (var wine in wines)
                {
                    _context.Remove(wine);    
                }
                foreach (var manufactuer in manufactuers)
                {
                    _context.Remove(manufactuer);    
                }
                foreach (var address in addresses)
                {
                    _context.Remove(address);    
                }
                _context.SaveChanges();
                return NoContent();
            }
            return Conflict("False Token");            
        }
Example #8
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"));
        }
Example #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"));
 }
Example #10
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"));
            };
        }
Example #11
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");
        }