Ejemplo n.º 1
0
 public Whiskey Add(Whiskey newWhiskey)
 {
     whiskeys.Add(newWhiskey);
     //test
     newWhiskey.Id = whiskeys.Max(w => w.Id) + 1;
     return(newWhiskey);
 }
Ejemplo n.º 2
0
        public Whiskey Add(Whiskey newWhiskey)
        {
            _context.Whiskies.Add(newWhiskey);
            _context.SaveChanges();

            return(newWhiskey);
        }
Ejemplo n.º 3
0
        public Whiskey CreateWhiskey(Whiskey whiskey)
        {
            if (string.IsNullOrEmpty(whiskey.WhiskeyName))
            {
                throw new Exception("There must be a Whiskey name assigned to the whiskey for creation");
            }
            if (whiskey.WhiskeyType == null || whiskey.WhiskeyType.Id <= 0)
            {
                throw new Exception("There must be a Whiskey type assigned to the whiskey for creation");
            }
            if (string.IsNullOrEmpty(whiskey.Description))
            {
                throw new Exception("There must be a Whiskey description assigned to the whiskey for creation");
            }
            if (whiskey.Price <= 0)
            {
                throw new Exception("There must be a valid Whiskey price assigned to the whiskey for creation");
            }
            if (whiskey.Year == 0)
            {
                throw new Exception("There must be a Whiskey year assigned to the whiskey for creation");
            }

            return(_whiskeyRepo.CreateWhiskey(whiskey));
        }
Ejemplo n.º 4
0
 public Whiskey Add(Whiskey newWhiskey)
 {
     whiskeys.Add(newWhiskey);
     newWhiskey.Id        = whiskeys.Max(r => r.Id) + 1;
     newWhiskey.isDeleted = false;
     return(newWhiskey);
 }
Ejemplo n.º 5
0
        public async Task <Whiskey> Update(Whiskey updatedWhiskey)
        {
            var entity = await Task.FromResult(_db.Whiskeys.Attach(updatedWhiskey));

            entity.State = EntityState.Modified;
            return(await Task.FromResult(updatedWhiskey));
        }
Ejemplo n.º 6
0
        protected void gridViewWhiskeys_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // When the 'edit' button in the gridview is clicked, the info from that row wil be translated to the form's drop down lists. Those van be used to update the info
            if (e.CommandName == "EditWhiskey")
            {
                addwhiskeyForm.Visible = true;
                updateWhiskey.Visible  = true;

                var     rowIndex      = int.Parse(e.CommandArgument.ToString());
                var     selectedRow   = ((GridView)sender).Rows[rowIndex];
                Whiskey currentValues = dal.getWhiskey(Convert.ToInt32(selectedRow.Cells[15].Text));

                idLabel.Text      = currentValues.getId().ToString();
                whiskeyName.Value = currentValues.getName();
                whiskeyAge.Value  = currentValues.getAge();;
                dropDownCategory.SelectedIndex = currentValues.getCategoryId() - 1;
                currentWhiskeyValue.Value      = currentValues.getCurrentMarketValue().ToString();
                whiskeyPurchasePrice.Value     = currentValues.getPurchasePrice().ToString();
                whiskeyDescription.Value       = currentValues.getDescription();
                whiskeyBrand.SelectedIndex     = currentValues.getBrandId() - 1;
                whiskeyAlcoholPercentage.Value = currentValues.getAlcoholPercentage();
                isWhiskeySealed.SelectedValue  = currentValues.getIsSealed();
                whiskeyBaseIngredient.Value    = currentValues.getBaseIngredient();
            }
            // When the 'delete' button in the gridview is clicked, it will delete that record from the database, using it's ID
            else if (e.CommandName == "deleteWhiskey")
            {
                var rowIndex    = int.Parse(e.CommandArgument.ToString());
                var selectedRow = ((GridView)sender).Rows[rowIndex];
                int id          = Convert.ToInt32(selectedRow.Cells[15].Text);

                dal.deleteWhiskey(id);
            }
        }
Ejemplo n.º 7
0
 public IActionResult OnGet(int whiskeyId)
 {
     Whiskey = whiskeyData.GetById(whiskeyId);
     if (Whiskey == null)
     {
         return(RedirectToPage("./NotFound"));
     }
     return(Page());
 }
Ejemplo n.º 8
0
        public Whiskey Edit(Whiskey editwhiskey, int searcharea)
        {
            int ID = editwhiskey.Id;

            editwhiskey.Area = locations.FirstOrDefault(i => i.Id == searcharea);
            whiskeys.Remove(whiskeys.FirstOrDefault(o => o.Id == ID));
            whiskeys.Add(editwhiskey);
            return(editwhiskey);
        }
Ejemplo n.º 9
0
        protected void addAWhiskey_Click(object sender, EventArgs e)
        {
            // Makes an object from the filled-in form. No checks on input. Triggers the method to add a whiskey to the database

            Whiskey newWhiskey = new Whiskey(0, whiskeyName.Value, whiskeyAge.Value, Convert.ToInt32(dropDownCategory.SelectedValue),
                                             Convert.ToDouble(currentWhiskeyValue.Value), Convert.ToDouble(whiskeyPurchasePrice.Value), whiskeyDescription.Value,
                                             Convert.ToInt32(whiskeyBrand.SelectedValue), whiskeyAlcoholPercentage.Value, isWhiskeySealed.SelectedValue, whiskeyBaseIngredient.Value, Convert.ToInt32(dropdownCollections.SelectedValue));

            dal.addWhiskey(newWhiskey);
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> OnGet(int productId)
        {
            Whiskey = await _whiskeys.GetById(productId);

            if (Whiskey == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            return(Page());
        }
        public async Task <IActionResult> OnGet(int whiskeyId)
        {
            Product = await _whiskeysDb.GetById(whiskeyId);

            if (Product == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            return(Page());
        }
Ejemplo n.º 12
0
 public ActionResult <Whiskey> Post([FromBody] Whiskey whiskey)
 {
     try
     {
         return(Ok(_whiskeyService.CreateWhiskey(whiskey)));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 13
0
        public async Task <IActionResult> OnPost(int productId)
        {
            Whiskey = await _whiskeyDb.Delete(productId);

            if (Whiskey == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            await _whiskeyDb.Commit();

            return(RedirectToPage("./ListWhiskey"));
        }
Ejemplo n.º 14
0
 public ActionResult <Whiskey> Patch(int id, [FromBody] Whiskey whiskey)
 {
     try
     {
         whiskey.Id = id;
         return(Ok(_whiskeyService.Update(whiskey)));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 15
0
        public async Task <Whiskey> GetById(string id)
        {
            var whiskey = new Whiskey();

            using (var result = await Collection.FindAsync(new BsonDocument {
                { "_id", new ObjectId(id) }
            }))
            {
                var batch = result.Current.SingleOrDefault();
                if (batch != null)
                {
                    whiskey = batch;
                }
            }
            return(whiskey);
        }
Ejemplo n.º 16
0
        public IActionResult Create(WhiskeyEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newWhiskey = new Whiskey();
                newWhiskey.Name = model.Name;
                newWhiskey.Type = model.Type;

                newWhiskey = _whiskeyData.Add(newWhiskey);

                return(RedirectToAction("Details", new { Id = newWhiskey.Id }));
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Create(Whiskey whiskey)
        {
            ModelState.Remove("UserId");
            ModelState.Remove("User");
            var user = await GetCurrentUserAsync();


            if (ModelState.IsValid)
            {
                whiskey.UserId = user.Id;
                _context.Add(whiskey);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(whiskey));
        }
Ejemplo n.º 18
0
        public Whiskey Update(Whiskey updatedWhiskey)
        {
            var whiskey = whiskeys.SingleOrDefault(w => w.Id == updatedWhiskey.Id);

            if (whiskey != null)
            {
                whiskey.Name       = updatedWhiskey.Name;
                whiskey.Price      = updatedWhiskey.Price;
                whiskey.Brand      = updatedWhiskey.Brand;
                whiskey.Type       = updatedWhiskey.Type;
                whiskey.Area       = updatedWhiskey.Area;
                whiskey.Percentage = updatedWhiskey.Percentage;
                //whiskey.IsDeleted = updatedWhiskey.IsDeleted;
                //whiskey.AreaOptional = updatedWhiskey.AreaOptional;
                //whiskey.WhiskeyLabel = updatedWhiskey.WhiskeyLabel;
            }
            return(whiskey);
        }
        public void CreateWhiskeyWithWhiskeyTypeMissing()
        {
            var whiskeyRepo = new Mock <IWhiskeyRepository>();

            IWhiskeyService service = new WhiskeyService(whiskeyRepo.Object);

            var whiskey = new Whiskey()
            {
                WhiskeyName = "Test Whiskey Name",
                Description = "Test Description",
                Price       = 2500,
                Stock       = 10,
                Year        = 1997
            };

            Exception ex = Assert.Throws <Exception>(() => service.CreateWhiskey(whiskey));

            Assert.Equal("There must be a Whiskey type assigned to the whiskey for creation", ex.Message);
        }
Ejemplo n.º 20
0
 public IActionResult OnGet(int?whiskeyId)
 {
     WhiskeyTypes  = htmlHelper.GetEnumSelectList <WhiskeyType>();
     WhiskeyBrands = htmlHelper.GetEnumSelectList <WhiskeyBrand>();
     WhiskeyArea   = htmlHelper.GetEnumSelectList <WhiskeyArea>();
     if (whiskeyId.HasValue)
     {
         Whiskey = whiskeyData.GetById(whiskeyId.Value);
     }
     else
     {
         Whiskey = new Whiskey();
     }
     if (Whiskey == null)
     {
         return(RedirectToPage("./NotFound"));
     }
     return(Page());
 }
Ejemplo n.º 21
0
        protected void updateWhiskey_Click(object sender, EventArgs e)
        {
            // Creates an object based on the filled in form, and updates the whiskey data
            Whiskey currentValue = dal.getWhiskey(Convert.ToInt32(idLabel.Text));

            currentValue.setWhiskeyName(whiskeyName.Value);
            currentValue.setWhiskeyAge(whiskeyAge.Value);
            currentValue.setCategoryId(Convert.ToInt32(dropDownCategory.SelectedValue));
            currentValue.setCurrentValue(Convert.ToDouble(currentWhiskeyValue.Value));
            currentValue.setPurchasePrice(Convert.ToDouble(whiskeyPurchasePrice.Value));
            currentValue.setBrandId(Convert.ToInt32(whiskeyBrand.SelectedValue));
            currentValue.setDescription(whiskeyDescription.Value);
            currentValue.setAlcoholPercantage(whiskeyAlcoholPercentage.Value);
            currentValue.setSealed(isWhiskeySealed.SelectedValue);
            currentValue.setBaseIngredient(whiskeyBaseIngredient.Value);


            dal.updateWhiskey(currentValue);
        }
Ejemplo n.º 22
0
        public void InitializeWhiskeys()
        {
            var WhiskeyList = File.ReadLines(appPath + @"\Whiskeys.txt");

            foreach (var line in WhiskeyList)
            {
                var WhiskeysData = line.Split(',');
                if (WhiskeysData.Count() == 0)
                {
                    continue;
                }
                var WhiskeyData = new Whiskey()
                {
                    WhiskeyId = WhiskeysData[0],
                    Name      = WhiskeysData[1],
                    Assays    = GetAssayData(WhiskeysData)
                };
                Whiskeys.Add(WhiskeyData);
            }
        }
Ejemplo n.º 23
0
        public static void Main()
        {
            Appetizer almonds = new Almond();
            Appetizer cashew  = new Cashew();
            Appetizer peanuts = new Peanut();

            Drink whiskey = new Whiskey("Johny Walker", 50, cashew);

            Console.WriteLine("--------- Drink with cashew appetizer:");
            whiskey.DisplayInformation();
            Console.WriteLine();

            whiskey.Appetizer = almonds;
            Console.WriteLine("--------- Drink with almonds appetizer:");
            whiskey.DisplayInformation();
            Console.WriteLine();

            whiskey.Appetizer = peanuts;
            Console.WriteLine("--------- Drink with peanuts appetizer:");
            whiskey.DisplayInformation();
            Console.WriteLine();
        }
Ejemplo n.º 24
0
        public async Task AddWhiskeyAsync(WhiskeyInputModel whiskeyInputModel)
        {
            var whiskey = this.context
                          .Whiskeys
                          .Where(x => x.Brand == whiskeyInputModel.Brand)
                          .FirstOrDefault();

            if (whiskey == null)
            {
                string image = await this.UploadImageAsync(whiskeyInputModel);

                var whiskeyToAdd = new Whiskey()
                {
                    Image    = image,
                    Brand    = whiskeyInputModel.Brand,
                    Year     = whiskeyInputModel.Year,
                    Quantity = whiskeyInputModel.Quantity,
                };

                await this.context.Whiskeys.AddAsync(whiskeyToAdd);

                await this.context.SaveChangesAsync();
            }
        }
Ejemplo n.º 25
0
 public Whiskey Update(Whiskey updateWhiskey, int NewSupply)
 {
     updateWhiskey.Supply = NewSupply;
     return(updateWhiskey);
 }
Ejemplo n.º 26
0
        public async Task <Whiskey> Insert(Whiskey whiskey)
        {
            await Collection.InsertOneAsync(whiskey);

            return(await GetById(whiskey.Id.ToString()));
        }
Ejemplo n.º 27
0
 public void Update(Whiskey whiskey)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 28
0
        public async Task <Whiskey> Create(Whiskey newWhiskey)
        {
            await _db.Whiskeys.AddAsync(newWhiskey);

            return(newWhiskey);
        }
Ejemplo n.º 29
0
        static void LoopHappyVersion()
        {
            Whiskey ardbeg = new Whiskey { Name = "Ardbeg 1998", Age = 12, Price = 49.95m, Country = "Scotland" };
            Whiskey glenmorangie = new Whiskey { Name = "Glenmorangie", Age = 10, Price = 28.95m, Country = "Scotland" };
            Whiskey talisker = new Whiskey { Name = "Talisker", Age = 18, Price = 57.95m, Country = "Scotland" };
            Whiskey cragganmore = new Whiskey { Name = "Cragganmore", Age = 12, Price = 30.95m, Country = "Scotland" };
            Whiskey redbreast = new Whiskey { Name = "Redbreast", Age = 12, Price = 27.95m, Country = "Ireland" };
            Whiskey greenspot = new Whiskey { Name = "Green spot", Age = 8, Price = 44.48m, Country = "Ireland" };

            List<Whiskey> whiskies = new List<Whiskey> { ardbeg, glenmorangie, talisker, cragganmore, redbreast, greenspot };

            // project to a different type
            var whiskeyNames = new List<string> ();
            foreach (var whiskey in whiskies) {
                whiskeyNames.Add (whiskey.Name);
            }

            Console.WriteLine("Whiskey names: {0}", String.Join(", ", whiskeyNames.ToArray()));

            // filter down to good value whiskey

            var goodValueWhiskies = whiskies.Where(x=> x.Price <= 30m).ToList();
            Console.WriteLine("Found {0} good value whiskeys", goodValueWhiskies.Count);

            var howMany12YearOldWhiskies = whiskies.Count(x=> x.Age == 12);

            Console.WriteLine ("How many 12 year old whiskies do we have {0}", howMany12YearOldWhiskies);

            var allAreScottish = whiskies.All(x=> x.Country == "Scotland");

            Console.Out.WriteLine ("All are scottish? {0}", allAreScottish);

            var isThereIrishWhiskey = whiskies.Any(x=> x.Country == "Ireland");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.WriteLine("Is there Irish whiskey? {0}", isThereIrishWhiskey);

            // doing too much example - first split up the for
            var scottishWhiskiesCount = 0;
            var scottishWhiskeyTotal = 0m;
            foreach (var whiskey in whiskies) {
            if (whiskey.Country == "Scotland") {
            scottishWhiskiesCount++;
            scottishWhiskeyTotal += whiskey.Price;
            }
            }

            var scottishWhiskies = whiskies.Where(x=> x.Country == "Scotland").ToList();
            scottishWhiskiesCount = scottishWhiskies.Count();
            scottishWhiskeyTotal = scottishWhiskies.Sum(x=> x.Price);

            scottishWhiskies = new List<Whiskey> ();
            foreach (var whiskey in whiskies) {
            if (whiskey.Country == "Scotland") {
            scottishWhiskies.Add (whiskey);
            }
            }

            foreach (var whiskey in scottishWhiskies) {
            if (whiskey != null)
            scottishWhiskiesCount++;
            }

            foreach (var whiskey in scottishWhiskies) {
            scottishWhiskeyTotal += whiskey.Price;
            }
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine ("{0} scottish whiskies costing {1}", scottishWhiskiesCount, scottishWhiskeyTotal);

            /*
            var blendedWhiskey = new Whiskey() { Name="Tesco value whiskey", Age=3, Country="Scotland" };
            foreach (var whiskey in whiskies)
            {
            if (whiskey.Country != "Scotland")
            {
            continue;
            }

            blendedWhiskey.Ingredients.Add(whiskey);
            blendedWhiskey.Price = blendedWhiskey.Price + (whiskey.Price / 10);
            };

            Console.WriteLine("Blended Whiskey Name: {0}", blendedWhiskey.Name);
            Console.WriteLine("Blended Whiskey Price: {0}", blendedWhiskey.Price);
            Console.WriteLine("Blended Whiskey Ingredients: {0}", blendedWhiskey.IngredientsAsString);
            */
            var blendedWhiskey = whiskies.Where(x=> x.Country == "Scotland")
            .Aggregate(new Whiskey() { Name="Tesco value whiskey", Age=3, Country="Scotland" },
            (newWhiskey, nextWhiskey) =>
            {
            newWhiskey.Ingredients.Add(nextWhiskey);
            newWhiskey.Price += (nextWhiskey.Price / 10);
            return newWhiskey;
            });

            Console.WriteLine("Blended Whiskey Name: {0}", blendedWhiskey.Name);
            Console.WriteLine("Blended Whiskey Price: {0}", blendedWhiskey.Price);
            Console.WriteLine("Blended Whiskey Ingredients: {0}", blendedWhiskey.IngredientsAsString);

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Blended Whiskey");
            ObjectDumper.Write (blendedWhiskey);

            /*   		 List<string> whiskeyNamesFromOwners = new List<string>();
            foreach (var owner in owners)
            {
                foreach (var whiskey in owner.Whiskies)
                {
                    whiskeyNamesFromOwners.Add(whiskey.Name);
                }
            }
             */
            // max - aggregation examples
            Whiskey mostExpensiveWhiskey = null;
            foreach (var challenger in whiskies)
            {
            if (mostExpensiveWhiskey == null)
            {
            mostExpensiveWhiskey = challenger;
            }
            if (challenger.Price > mostExpensiveWhiskey.Price)
            {
            mostExpensiveWhiskey = challenger;
            }
            }
            Console.WriteLine("Most expensive is {0}", mostExpensiveWhiskey.Name);

            mostExpensiveWhiskey = whiskies.Aggregate((champion, challenger) => challenger.Price > champion.Price ? challenger : champion);
            Console.WriteLine("Most expensive is {0}", mostExpensiveWhiskey.Name);
        }
 public Whiskey CreateWhiskey(Whiskey whiskey)
 {
     _ctx.Attach(whiskey).State = EntityState.Added;
     _ctx.SaveChanges();
     return(whiskey);
 }
 public Whiskey Update(Whiskey whiskey)
 {
     _ctx.Attach(whiskey).State = EntityState.Modified;
     _ctx.SaveChanges();
     return(whiskey);
 }