Example #1
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));
        }
Example #2
0
 public void Update(Wine wine)
 {
     if (wine != null && Exists(wine.WineID))
     {
         db.SaveChanges();
     }
 }
        public ActionResult Create([Bind(Include = "ID,wineName,wineYear,winePrice,wineHarvest,Wine_TypeID")] Wine wine)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Wines.Add(wine);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException dex)
            {
                if (dex.InnerException.InnerException.Message.Contains("IX_Unique"))
                {
                    ModelState.AddModelError("", "Unable to save changes. Remember, you cannot have duplicate wine and wine year.");
                }
                else
                {
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                }
            }


            PopulateDropDownLists(wine);
            return(View(wine));
        }
Example #4
0
        public async Task <IActionResult> PutWine(int id, Wine wine)
        {
            if (id != wine.Id)
            {
                return(BadRequest());
            }

            var claims  = User.Claims;
            var subject = claims.FirstOrDefault(c => c.Type == "sub")?.Value;

            if (wine.UserSubject != subject)
            {
                return(Forbid());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        public HttpResponseMessage Put(DeleteReviewSubmitModel delModel)
        {
            var response = new HttpResponseMessage(HttpStatusCode.NotFound);

            using (var session = ravenStore.OpenSession())
            {
                Wine wine = session.Load <Wine>(delModel.SubjectId);

                Review myReview = wine.Reviews.FirstOrDefault(x => x.UserId == delModel.UserId);
                wine.Reviews.Remove(myReview);

                if (wine.Reviews.Count > 0)
                {
                    var rating = wine.Reviews.Average(x => x.Rating);
                    wine.Rating = rating;
                }
                else
                {
                    wine.Rating = 0;
                }

                session.SaveChanges();

                response = new HttpResponseMessage(HttpStatusCode.OK);
            }

            return(response);
        }
Example #6
0
        public ActionResult Create([Bind(Include = "WineID,Name,WineType,Grape,Region,Country,Description,Body,AlcoholVol,RateOverall,WineImage")] Wine wine)
        {
            //default wine images

            if (wine.WineImage == null)
            {
                switch (wine.WineType)
                {
                case "Red":
                    //use @ to escape '\' charater error
                    wine.WineImage = @"~\Content\Images\redWine.jpg";
                    break;

                case "White":
                    wine.WineImage = @"~\Content\Images\whiteWine.jpg";
                    break;

                default:
                    wine.WineImage = @"~\Content\Images\roseWine.jpg";
                    break;
                }
            }

            if (ModelState.IsValid)
            {
                db.Wines.Add(wine);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(wine));
        }
Example #7
0
        private void AddWineButton_Click(object sender, EventArgs e)
        {
            Wine local = new Wine();

            try
            {
                local.Id            = Convert.ToInt32(IdTextBox.Text);
                local.Name          = NameTextBox.Text;
                local.NameEng       = NameEngTextBox.Text;
                local.Alcohol       = Convert.ToDouble(AlcoholTextBox.Text);
                local.GrapeSort     = Convert.ToInt32(GrapeSortTextBox.Text);
                local.Price         = Convert.ToDouble(PriceTextBox.Text);
                local.SortCategory  = Convert.ToInt32(WineSortTextBox.Text);
                local.SulfurDioxide = Convert.ToDouble(SulfurDioxideTextBox.Text);
                local.Sweetness     = Convert.ToInt32(SweetnessTextBox.Text);
                local.Year          = Convert.ToInt32(YearTextBox.Text);
                MainForm main = Application.OpenForms["MainForm"] as MainForm;
                main.WineManager.LoadData(local);
                main.WineList.Add(local);
                main.UpdateWineTable();
                this.Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Ошибка!", MessageBoxButtons.OK);
            }
        }
Example #8
0
        public IActionResult Results(string name, Wine wine)
        {
            ViewBag.Name        = name;
            ViewBag.NotFiltered = false;

            List <Wine> allWines = Wine.GetWineList().Skip(1).ToList();

            if (!String.IsNullOrEmpty(wine.Price))
            {
                allWines = allWines.Where(w => w.Price == wine.Price).ToList();
            }

            if (!String.IsNullOrEmpty(wine.Price))
            {
                allWines = allWines.Where(w => w.Points == wine.Points).ToList();
            }

            if (!String.IsNullOrEmpty(wine.Country))
            {
                allWines = allWines.Where(w => w.Country.ToLower() == wine.Country.ToLower()).ToList();
            }

            if (allWines.Count > 100)
            {
                allWines            = allWines.Take(100).ToList();
                ViewBag.NotFiltered = true;
            }

            return(View(allWines));
        }
Example #9
0
        public async Task <IActionResult> Edit(int id, Wine wine)
        {
            if (id != wine.WineId)
            {
                return(NotFound());
            }

            var user = await GetCurrentUserAsync();

            if (ModelState.IsValid)
            {
                try
                {
                    wine.ApplicationUserId = user.Id;

                    _context.Update(wine);
                    await _context.SaveChangesAsync();
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!WineExists(wine.WineId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                WineDetailsViewModel viewModel = new WineDetailsViewModel();

                var updatedWine = await _context.Wine
                                  .Include(w => w.Winery)
                                  .Include(w => w.Variety)
                                  .FirstOrDefaultAsync(m => m.WineId == id);

                if (wine == null)
                {
                    return(NotFound());
                }

                var foods = await _context.Food
                            .Include(f => f.FoodCategory)
                            .ThenInclude(fc => fc.Category)
                            .ThenInclude(c => c.Variety)
                            .ThenInclude(v => v.Wines)
                            .Where(f => f.FoodCategory.Any(fc => fc.CategoryId == updatedWine.Variety.CategoryId))
                            .ToListAsync()
                ;

                viewModel.Wine  = updatedWine;
                viewModel.Foods = foods;

                return(View("Details", viewModel));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", wine.ApplicationUserId);
            return(View(wine));
        }
Example #10
0
        public void Delete(int id)
        {
            Wine wine = Get(id);

            m_context.Remove(wine);
            m_context.SaveChanges();
        }
Example #11
0
 public Wine Edit(int id, Wine changedWine)
 {
     changedWine.Id = id;
     m_context.Update(changedWine);
     m_context.SaveChanges();
     return(changedWine);
 }
Example #12
0
 public Wine Add(Wine wine)
 {
     m_context.Wines.Add(wine);
     // commit changes to DB
     m_context.SaveChanges();
     return(wine);
 }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Price,YearOfBotteling,AlcholPercentage,ImagePath,Description,WineType,WineryID")] Wine wine)
        {
            if (id != wine.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(wine);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WineExists(wine.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["WineryID"] = new SelectList(_context.Winery, "Id", "Name", wine.WineryID);
            ViewBag.Items = new SelectList(_context.Winery, "Id", "Name", wine.WineryID);

            return(View(wine));
        }
        public WineDetailsPopUp(Wine wine)
        {
            InitializeComponent();

            BindingContext  = _viewModel;
            _viewModel.Wine = wine;
        }
Example #15
0
        public IActionResult Results(string name, string price, string points)
        {
            ViewBag.Name = name;
            List <Wine> wineList = Wine.FilterWineList(price, points);

            return(View(wineList));
        }
Example #16
0
        public bool Insert(Wine item)
        {
            Context.Wine.Add(item);
            int result = Context.SaveChanges();

            return(result < 0 ? false : true);
        }
        public void PutWine_AttributesUnchanged_WhenUsingInvalidWineId()
        {
            // Arrange
            // Set up associated object - Varietal.
            var varietalEntity = new VarietalEntity
            {
                Varietal = "Test 4.4 Varietal"
            };

            _dbContext.Varietals.Add(varietalEntity);

            // Set up associated object - BottleSize.
            var bottleSizeEntity = new BottleSizeEntity
            {
                // Just use default values.
            };

            _dbContext.BottleSizes.Add(bottleSizeEntity);

            // Set up associated object - Winery.
            var wineryEntity = new WineryEntity
            {
                Name = "Test 4.4 Winery"
            };

            _dbContext.Wineries.Add(wineryEntity);

            _dbContext.SaveChanges( );

            var wineEntity = new WineEntity
            {
                Name          = "Test 4.4 Wine",
                WhenPurchased = "Test 4.4 WhenPurchased",
                //--BottlesDrank = 4,
                BottlesPurchased   = 3,
                VarietalEntityId   = varietalEntity.Id,
                BottleSizeEntityId = bottleSizeEntity.Id,
                WineryEntityId     = wineryEntity.Id,
                Vintage            = "Test 4.4 Vintage"
            };

            _dbContext.Wines.Add(wineEntity);
            _dbContext.SaveChanges( );
            var wineEntityId = wineEntity.Id;

            var wine = new Wine
            {
                Name          = "Test 4.4 Wine UPDATE",
                WhenPurchased = "Test 4.4 WhenPurchased UPDTED",
                BottlesDrank  = 2,
                Vintage       = "Test 4.4 Vintage UPDATED"
            };

            // Act
            _controller.PutWine(wineEntity.Id + 1, wine);
            var result = _dbContext.Wines.Find(wineEntity.Id);

            // Assert
            Assert.Equal(wineEntity.Name, result.Name);
        }
        public async Task UpdateAsync_given_wine_updates_it()
        {
            using (var connection = await CreateConnectionAsync())
                using (var context = await CreateContextAsync(connection))
                {
                    var entity = new Wine
                    {
                        Name = "name",
                        Year = 2019,
                    };

                    context.Wines.Add(entity);
                    await context.SaveChangesAsync();

                    var id = entity.Id;

                    var repository = new WineRepository(context);

                    var wine = new WineDTO
                    {
                        Id   = id,
                        Name = "new name",
                        Year = 2018,
                    };

                    var updated = await repository.UpdateAsync(wine);

                    Assert.True(updated);

                    var updatedEntity = await context.Wines.FindAsync(id);

                    Assert.Equal("new name", updatedEntity.Name);
                    Assert.Equal(2018, updatedEntity.Year);
                }
        }
Example #19
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (_drink == null)
            {
                var wine = new Wine()
                {
                    Bottle = new Bottle()
                };

                if (!SetWineProperties(wine))
                {
                    return;
                }

                _modelService.AddDrink(wine);
            }
            else
            {
                var wine = (Wine)_drink;

                if (!SetWineProperties(wine))
                {
                    return;
                }
            }

            DialogResult = DialogResult.OK;
        }
        public async Task DeleteAsync_given_existing_wineId_deletes_it()
        {
            using (var connection = await CreateConnectionAsync())
                using (var context = await CreateContextAsync(connection))
                {
                    var entity = new Wine {
                        Name = "name"
                    };

                    context.Wines.Add(entity);
                    await context.SaveChangesAsync();

                    var id = entity.Id;

                    var repository = new WineRepository(context);

                    var deleted = await repository.DeleteAsync(id);

                    Assert.True(deleted);

                    var deletedEntity = await context.Wines.FindAsync(id);

                    Assert.Null(deletedEntity);
                }
        }
Example #21
0
        public Task <int> UpdateWineAsync(Wine wine)
        {
            WineContext.Wines.Update(wine);
            var result = WineContext.SaveChanges();

            return(Task.FromResult(result));
        }
        public async Task Read_returns_mapped_WineDTO()
        {
            using (var connection = await CreateConnectionAsync())
                using (var context = await CreateContextAsync(connection))
                {
                    var entity = new Wine
                    {
                        Name = "name",
                        Year = 2019
                    };

                    context.Wines.Add(entity);
                    await context.SaveChangesAsync();

                    var id = entity.Id;

                    var repository = new WineRepository(context);

                    var wines = await repository.ReadAsync();

                    var wine = wines.FirstOrDefault();
                    Assert.Equal(1, wines.Count);
                    Assert.Equal(entity.Name, wine.Name);
                    Assert.Equal(entity.Year, wine.Year);
                }
        }
Example #23
0
        public ActionResult UpdateWine(WineViewModel model)
        {
            Wine wine = _wineRepository.GetByID(model.WineID);

            if (wine == null)
            {
                return(Json(new { success = false, message = "No item found" }));
            }
            wine.Name         = model.Name;
            wine.RegionID     = model.RegionID;
            wine.CountryID    = model.CountryID;
            wine.BottleSizeID = model.BottleSizeID;
            wine.Description  = model.Description;
            wine.Vintage      = model.Vintage;
            wine.Price        = model.Price;
            wine.WineID       = model.WineID;
            wine.SubTypeID    = model.SubTypeID;
            wine.TypeID       = model.TypeID;

            if (model.File != null && model.File.ContentLength > 0)
            {
                var uploadDir = "~/Content/img/uploads";
                var imagePath = Path.Combine(Server.MapPath(uploadDir), model.File.FileName);
                var imageUrl  = Path.Combine(uploadDir, model.File.FileName);
                model.File.SaveAs(imagePath);
                wine.ImagePath = imageUrl;
            }

            _wineRepository.Update(wine);

            //return Json(new { success = true }, JsonRequestBehavior.AllowGet);
            return(RedirectToAction("Index"));
        }
Example #24
0
        // GET: Wines/Edit/5
        public ActionResult Edit(int?id)    ///////////////////////////////////////////////////////////////////////////////////////
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //***************
            Wine wine = db.Wines.Include(i => i.Winery).Where(i => i.Id == id).FirstOrDefault();

            //***************
            if (wine == null)
            {
                return(HttpNotFound());
            }

            //new code


            var        getWinerList = db.Wineries.ToList();
            SelectList list         = new SelectList(getWinerList, "Id", "Name", wine.Winery.Id);

            ViewBag.WineriesName = list;
            return(View(wine));

            //////////////////

            // ViewBag.Items = new SelectList(db.Wineries, "Id", "Name", wine.WineryID);
            // return View(wine);
        }
        public void GivenThereIsAGameOfPlayerAWithHealthAndPlayerBHasHealth(int p0, int p1)
        {
            playerA = new Player(0, "PA", "Player A", p0);
            playerB = new Player(1, "PB", "Player B", p1);
            Player[] players = new Player[2];
            players[0] = playerA;
            players[1] = playerB;
            List <Card> ls = new List <Card>();

            wine = new Wine(CardSuit.Club, 1);
            ls.Add(wine);
            ls.Add(wine);
            ls.Add(wine);
            ls.Add(wine);
            ls.Add(wine);
            attack = new Attack(CardSuit.Club, 2);
            ls.Add(attack);
            ls.Add(attack);
            ls.Add(attack);
            ls.Add(attack);
            ls.Add(attack);
            peach = new Peach(CardSuit.Heart, 3);
            ls.Add(peach);
            ls.Add(peach);
            ls.Add(peach);
            ls.Add(peach);
            game = new Game(players, new FakeCardSet(ls));
            game.start(0);
        }
Example #26
0
        public IHttpActionResult PostWine(Wine wine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Wines.Add(wine);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (WineExists(wine.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = wine.id }, wine));
        }
Example #27
0
        public void getCardIDTest()
        {
            List <Card> ls = new List <Card>();
            Card        a  = new Attack(CardSuit.Club, 0);

            ls.Add(a);
            Card b = new Miss(CardSuit.Club, 1);

            ls.Add(b);
            Card c = new Miss(CardSuit.Diamond, 2);

            ls.Add(c);
            Card d = new Attack(CardSuit.Spade, 3);

            ls.Add(d);
            Card e = new Wine(CardSuit.Club, 4);

            ls.Add(e);
            ICardSet s = new CardSet(ls);

            Assert.AreEqual(a, s[s[a]]);
            Assert.AreEqual(b, s[s[b]]);
            Assert.AreEqual(c, s[s[c]]);
            Assert.AreEqual(d, s[s[d]]);
            Assert.AreEqual(e, s[s[e]]);
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,SmallPeg,LargePeg,Unit,SmallPegQuantity,LargePegQuantity")] Wine wine)
        {
            if (id != wine.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(wine);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WineExists(wine.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(wine));
        }
Example #29
0
        private void LoadWines()
        {
            int skip = _pageIndex.GetValue() * WinesPerPage;

            XmlHttpRequest xhr = new XmlHttpRequest();

            xhr.OnReadyStateChange = delegate() {
                if ((xhr.ReadyState == ReadyState.Loaded) &&
                    (xhr.Status == 200))
                {
                    WineResults results = Json.ParseData <WineResults>(xhr.ResponseText);

                    if (results.Count != 0)
                    {
                        _pages.SetValue(Math.Ceil(results.Count / WinesPerPage));
                    }

                    Wines.SetValue(results.Wines);

                    Wine selectedWine = null;
                    if ((results.Wines != null) && (results.Wines.Length != 0))
                    {
                        selectedWine = results.Wines[0];
                    }
                    SelectedWine.SetValue(selectedWine);
                }
            };

            xhr.Open(HttpVerb.Get, "/wines/?skip=" + skip + "&count=" + WinesPerPage, true);
            xhr.Send();
        }
Example #30
0
        public async Task <IActionResult> PutWine(int id, Wine Wine)
        {
            var context = _contextFactory.CreateDbContext();

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

            context.Entry(Wine).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #31
0
 static void Main()
 {
     int Year2;
         string Type3;
         int range3;
         int selection;
         int ThisYear =2016;
         StreamWriter WineFile;
         Console.WriteLine("WineLife 0.2 Text Version");
         Console.WriteLine("______________________________________________");
         Console.WriteLine("Enter the Wine");
         Console.WriteLine("Year?");
         Year2 = Convert.ToInt32(Console.ReadLine());
         Console.WriteLine("Origin?");
         Type3 = (Console.ReadLine());
         Console.WriteLine("Please Select type:");
         Console.WriteLine("1) Tempranillo o joven");
         Console.WriteLine("2) Crianza");
         Console.WriteLine("3)  Reserva");
         Console.WriteLine("4)  Gran Reserva");
         Console.WriteLine("5) Other//Not Listed");
         selection = Convert.ToInt32(Console.ReadLine());
         switch (selection)
         {
             case 1 :
             range3=3;
             break;
             case 2 :
             range3=6;
             break;
             case 3 :
             range3=8;
             break;
             case 4 :
             range3=12;
             break;
             case 5 :
             range3=2;
             break;
             default:
             Console.WriteLine("Other noted down");
             range3=2;
             break;
         }
         WineFile = File.CreateText("WineFile.txt");
         Wine Rioja1 = new Wine (Year2,range3,Type3);
         Console.WriteLine("___________");
         Console.WriteLine("________________________");
         Console.WriteLine("______________________________________________");
         Console.WriteLine("The Year of the wine is: ");
         Console.WriteLine("Year :"+ Rioja1.Year);
          WineFile.WriteLine("You have the following Wine:  ");
         WineFile.Write(" Year :"+ Rioja1.Year);
         Console.WriteLine(" Duration of the wine is: ");
         Console.WriteLine(Rioja1.range + " Years ");
          WineFile.Write(" Duration of the wine is: ");
      WineFile.Write(Rioja1.range + " Years");
         Console.WriteLine(" The type of the wine is: ");
         Console.WriteLine(Rioja1.type );
          WineFile.Write (" The type of the wine is: ");
      WineFile.Write (Rioja1.type);
          Console.WriteLine("Checking state: ");
          Console.WriteLine("______________________");
          Console.WriteLine("______________________________");
          Console.WriteLine("______________________________________________");
             int rangeCalc= (range3+Year2);
             if (rangeCalc < ThisYear)
          {
         Console.WriteLine("The Wine Is past date");
         Console.WriteLine("It has been "+(ThisYear-rangeCalc)+" Years that is due");
         WineFile.Write (" The Wine Is past date");
         WineFile.Write (" It has been "+(ThisYear-rangeCalc)+" Years that is due");
         }
     else  {Console.WriteLine("Its OK to open it");
     Console.WriteLine("It has "+(rangeCalc-ThisYear)+" Years left");
     WineFile.Write (" Its OK to open it");
      WineFile.Write (" It has "+(rangeCalc-ThisYear)+" Years left");}
              WineFile.Close();
 }
        private void InserirRegistos_Click(object sender, RoutedEventArgs e)
        {
            var wine1 = new Wine()
                {
                    Id = 1,
                    Name = "Gazela Vinho Verde 2000",
                    Price = 7.99M,
                    IsAtHome = false,
                    IsFavorite = false,
                    Country = "Portugal",
                };

            var wine2 = new Wine()
                {
                    Id = 2,
                    Name = "Montecillo Blanco 1998",
                    Price = 10.99M,
                    IsAtHome = true,
                    IsFavorite = false,
                    Country = "Spain",
                };

            var wine3 = new Wine()
            {
                Id = 3,
                Name = "Quinta do Noval Ruby Port",
                Price = 8.99M,
                IsAtHome = true,
                IsFavorite = true,
                Country = "Portugal",
            };

            dbContext.Wines.InsertOnSubmit(wine1);
            dbContext.Wines.InsertOnSubmit(wine2);
            dbContext.Wines.InsertOnSubmit(wine3);

            dbContext.SubmitChanges();

            MessageBox.Show("Registos inseridos!");
        }