public PartialViewResult CommentsList(int id)
        {
            Whisky lot = _whiskyRepository.GetWhiskyById(id);

            lot.Comments = _whiskyRepository.GetCommentsByWhiskyId(id);
            return(PartialView(lot.Comments));
        }
        public async Task <IActionResult> Create([Bind("Name,Tags,Price,Brand,Vintage,Bottled,Strength,Size")] Whisky whisky, IFormFile uploadedImage, int coll_Id)
        {
            if (ModelState.IsValid)
            {
                if (uploadedImage != null && uploadedImage.Length > 0)
                {
                    string coll_url = await _imageManagment.UploadImageAsync(whisky.Name, uploadedImage.OpenReadStream());

                    whisky.Img = coll_url;
                }

                User user = await _userManager.GetUserAsync(HttpContext.User);

                whisky.UserId       = user.Id;
                whisky.User         = user;
                whisky.Created      = DateTime.Now;
                whisky.CollectionId = coll_Id;

                await _context.AddAsync(whisky);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(whisky));
        }
 public void Store(Whisky whisky)
 {
     if (!whiskyStore.Contains(whisky))
     {
         whiskyStore.Add(whisky);
     }
 }
        public void LoadWhiskies()
        {
            var whiskyFileContent = File.ReadAllLines(WhiskiesFilePath);

            foreach (var whiskyLine in whiskyFileContent)
            {
                var whiskyData = whiskyLine.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                if (whiskyData.Length == 3)
                {
                    var distilleryName    = whiskyData[0];
                    var whiskyName        = whiskyData[1];
                    var alcoholPercentage = Convert.ToSingle(whiskyData[2]);

                    var distillery = distilleryRepository.Find(distilleryName);

                    if (distillery != null)
                    {
                        var whisky = new Whisky
                        {
                            Id   = Guid.NewGuid(),
                            Name = whiskyName,
                            AlcoholPercentage = alcoholPercentage,
                            DistilleryId      = distillery.Id
                        };

                        whiskyRepository.Store(whisky);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public ActionResult DeleteConfirmed(int id)
        {
            Whisky whisky = db.Whisky.Find(id);

            db.Whisky.Remove(whisky);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public void addWhisky()
        {
            TextInputEditText whiskyNameTextInput = FindViewById <TextInputEditText>(Resource.Id.whisky_name_text_input);
            string            WhiskyName          = whiskyNameTextInput.Text;

            RatingBar SmellRatingBar = FindViewById <RatingBar>(Resource.Id.smellRatingBar);
            float     SmellRating    = SmellRatingBar.Rating;

            RatingBar TasteRatingBar = FindViewById <RatingBar>(Resource.Id.tasteRatingBar);
            float     TasteRating    = TasteRatingBar.Rating;

            RatingBar BalansRatingBar = FindViewById <RatingBar>(Resource.Id.balansRatingBar);
            float     BalansRating    = BalansRatingBar.Rating;

            RatingBar FinishRatingBar = FindViewById <RatingBar>(Resource.Id.finishRatingBar);
            float     FinishRating    = FinishRatingBar.Rating;

            if (!DataValidator.ValidateWhiskyName(WhiskyName))
            {
            }


            Whisky whisky = new Whisky(WhiskyName)
            {
                Smell  = SmellRating,
                Taste  = TasteRating,
                Balans = BalansRating,
                Finish = FinishRating
            };


            string path     = Application.Context.FilesDir.Path;
            var    filePath = Path.Combine(path, WhiskyListFileName);

            if (!File.Exists(filePath))
            {
                using (StreamWriter sw = File.CreateText(filePath))
                {
                    sw.WriteLine(whisky.Name);
                }
            }
            else
            {
                using (StreamWriter sw = File.AppendText(filePath))
                {
                    sw.WriteLine(whisky.Name);
                }
            }

            using (StreamReader sr = File.OpenText(filePath))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    Console.WriteLine(s);
                }
            }
        }
Ejemplo n.º 7
0
        public void ValidateDecorator_Concepts()
        {
            var whisky     = new Whisky();
            var icedWhisky = new IcedWhisky(whisky);

            Assert.Equal("Whisky", whisky.GetDescription());
            Assert.Equal("Whisky, 2 Ice cubes", icedWhisky.GetDescription());
            Assert.Equal(new Currency(5m).Value, whisky.Cost().Value);
            Assert.Equal(new Currency(5.25m).Value, icedWhisky.Cost().Value);
        }
        public ActionResult <Whisky> Create(Whisky whisky)
        {
            whisky.Id = _random.Next(100000000);
            _redis.Execute(async redis =>
            {
                await redis.StringSetAsync($"whiskey:{whisky.Id}", JsonSerializer.Serialize(whisky));
            });

            return(new StatusCodeResult(201));
        }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "WhiskyID,Nazwa,Kategoria,Oko,Nos,Język,Finisz,Ocena,Cena")] Whisky whisky)
 {
     if (ModelState.IsValid)
     {
         db.Entry(whisky).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(whisky));
 }
Ejemplo n.º 10
0
        public ActionResult Create([Bind(Include = "WhiskyID,Nazwa,Kategoria,Oko,Nos,Język,Finisz,Ocena,Cena")] Whisky whisky)
        {
            if (ModelState.IsValid)
            {
                db.Whisky.Add(whisky);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(whisky));
        }
Ejemplo n.º 11
0
        // GET: Whiskies/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Whisky whisky = db.Whisky.Find(id);

            if (whisky == null)
            {
                return(HttpNotFound());
            }
            return(View(whisky));
        }
Ejemplo n.º 12
0
 public static Repository.Data.Entities.Whisky MapWhisky(Whisky whisky)
 {
     return(new Repository.Data.Entities.Whisky
     {
         Name = whisky.Name,
         Price = whisky.Price,
         InStock = whisky.InStock,
         Type = whisky.Type,
         Content = whisky.Content,
         Store = whisky.Store,
         Taste = whisky.Taste,
         Country = whisky.Country
     });
 }
Ejemplo n.º 13
0
        public void AddWhisky(Whisky whisky, int?originalId = null)
        {
            whisky.CreateDt = DateTime.Now;
            whisky.ModifyDt = DateTime.Now;
            whisky.IsActive = true;
            _context.Whiskies.Add(whisky);

            // Save to get the new id
            _context.SaveChanges();

            // Set original id, based on existing, or just inserted entity
            whisky.OriginalId = originalId ?? whisky.Id;

            // Finally, update the record with the original id
            _context.Whiskies.Update(whisky);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Tags,Price,Brand,Vintage,Bottled,Strength,Size,Img")] Whisky whisky, IFormFile uploadedImage)
        {
            if (id != whisky.Id)
            {
                return(NotFound());
            }

            if (uploadedImage != null && uploadedImage.Length > 0)
            {
                string coll_url = await _imageManagment.UploadImageAsync(whisky.Name, uploadedImage.OpenReadStream());

                whisky.Img = coll_url;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var whiskyFromDb = _whiskyRepository.GetWhiskyById(whisky.Id);
                    whiskyFromDb.Img      = whisky.Img;
                    whiskyFromDb.Name     = whisky.Name;
                    whiskyFromDb.Brand    = whisky.Brand;
                    whiskyFromDb.Vintage  = whisky.Vintage;
                    whiskyFromDb.Bottled  = whisky.Bottled;
                    whiskyFromDb.Strength = whisky.Strength;
                    whiskyFromDb.Size     = whisky.Size;
                    whiskyFromDb.Tags     = whisky.Tags;
                    whiskyFromDb.User     = await _userManager.FindByIdAsync(whiskyFromDb.UserId);

                    _whiskyRepository.Update(whiskyFromDb);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WhiskyExists(whisky.Id))
                    {
                        return(RedirectPermanent("~/Error/Index?statusCode=404"));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(whisky));
        }
Ejemplo n.º 15
0
        public void OneLeading0_CorrectlyProcessed()
        {
            var whisky = new Whisky(LoggerMock.Object, JustSomeString, "0.57", JustSomeString, JustSomeBool, JustSomeString);

            Assert.Equal(ExpectedPrice, whisky.Price);
        }
Ejemplo n.º 16
0
        public static void Main(string[] args)
        {
            // setting up localization, just in case
            var appLocale = ConfigurationManager.AppSettings.Get("appLocale");

            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(appLocale);

            // declaring variables
            bool isProgramStarted = true;
            bool isCartEmpty      = true;

            int userCommandInput;
            int userQtyInput;

            // creating null objects for further work
            Beer   beer   = null;
            Wine   wine   = null;
            Vodka  vodka  = null;
            Gin    gin    = null;
            Cognac cognac = null;
            Whisky whisky = null;

            // saying hello to user
            Console.Clear();
            MessageLib.SayHello();
            Console.ReadKey();

            do
            {
                // showing menu to user
                Console.Clear();
                MessageLib.Menu();

                // accepting and validating input from user
                ParseUserInputToInt(true, out userCommandInput);

                switch (userCommandInput)
                {
                // adding beer to cart
                case (int)MenuActions.AddBeer:
                    MessageLib.AskHowMuchBottles();
                    ParseUserInputToInt(false, out userQtyInput);

                    beer = new Beer(userQtyInput);

                    isCartEmpty = false;

                    break;

                // adding wine to cart
                case (int)MenuActions.AddWine:
                    MessageLib.AskHowMuchBottles();
                    ParseUserInputToInt(false, out userQtyInput);

                    wine = new Wine(userQtyInput);

                    isCartEmpty = false;

                    break;

                // adding vodka to cart
                case (int)MenuActions.AddVodka:
                    MessageLib.AskHowMuchBottles();
                    ParseUserInputToInt(false, out userQtyInput);

                    vodka = new Vodka(userQtyInput);

                    isCartEmpty = false;

                    break;

                // adding gin to cart
                case (int)MenuActions.AddGin:
                    MessageLib.AskHowMuchBottles();
                    ParseUserInputToInt(false, out userQtyInput);

                    gin = new Gin(userQtyInput);

                    isCartEmpty = false;

                    break;

                // adding cognac to cart
                case (int)MenuActions.AddCognac:
                    MessageLib.AskHowMuchBottles();
                    ParseUserInputToInt(false, out userQtyInput);

                    cognac = new Cognac(userQtyInput);

                    isCartEmpty = false;

                    break;

                // adding whisky to cart
                case (int)MenuActions.AddWhisky:
                    MessageLib.AskHowMuchBottles();
                    ParseUserInputToInt(false, out userQtyInput);

                    whisky = new Whisky(userQtyInput);

                    isCartEmpty = false;

                    break;

                // showing user his cart
                case (int)MenuActions.ShowCart:

                    // if cart is empty show user appropriate message
                    if (isCartEmpty)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("\nYour cart is empty!");
                        Console.ResetColor();

                        Console.WriteLine("\nPress any key to return to menu...");
                        Console.ReadKey();

                        break;
                    }

                    // otherwise user's cart will be processed and shown
                    Inventory.ShowInventory(beer, wine, vodka, gin, cognac, whisky);

                    Console.WriteLine("\nPress any key to return to menu...");
                    Console.ReadKey();

                    break;

                // exiting the program
                case (int)MenuActions.Exit:
                    MessageLib.SayGoodbye();

                    isProgramStarted = false;

                    break;

                // otherwise throw an error
                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("\nInvalid input! Please try again: ");
                    Console.ResetColor();

                    break;
                }
            }while (isProgramStarted);
        }
Ejemplo n.º 17
0
 public void EditWhisky(Whisky whisky)
 {
     whisky.ModifyDt = DateTime.Now;
     whisky.IsActive = false;
     _context.Whiskies.Update(whisky);
 }
Ejemplo n.º 18
0
        public void TripleLeading0_Removed()
        {
            var whisky = new Whisky(LoggerMock.Object, JustSomeString, "000.57", JustSomeString, JustSomeBool, JustSomeString);

            Assert.Equal(ExpectedPrice, whisky.Price);
        }
 public void AddWhisky(Whisky whisky)
 {
     whiskiesRep.Insert(whisky);
 }
Ejemplo n.º 20
0
        public void Price_As_WeirdString_ConvertsTo_0()
        {
            var whisky = new Whisky(LoggerMock.Object, JustSomeString, "adl.k,.wet346347ryhadffkjasd;flkj", JustSomeString, JustSomeBool, JustSomeString);

            Assert.Equal(0, whisky.Price);
        }
Ejemplo n.º 21
0
        public void Price_As_EmptyString_ConvertsTo_0()
        {
            var whisky = new Whisky(LoggerMock.Object, JustSomeString, string.Empty, JustSomeString, JustSomeBool, JustSomeString);

            Assert.Equal(0, whisky.Price);
        }
 public void Update(Whisky whisky)
 {
     whiskiesRep.Update(whisky);
 }
 public void DeleteWhisky(Whisky whisky)
 {
     whiskiesRep.Delete(whisky);
 }