예제 #1
0
        public async Task <CoffeeModel> GetCoffeeByIdAsync(int id)
        {
            var CoffeeModel = new CoffeeModel();
            var coffee      = await _context.Set <Coffee>().FindAsync(id);

            return(CoffeeModel.Assign(coffee));
        }
예제 #2
0
        public void DeleteCoffeeWithEmptyId_Throws_NewException()
        {
            var coffeeToDelete = new CoffeeModel();
            var ex             = Assert.Throws <Exception>(() => coffeeService.DeleteCoffee(coffeeToDelete.Id));

            Assert.AreEqual(ex.Message, "The Id given is empty");
        }
예제 #3
0
 public ActionResult Details(Guid id, bool statistics = false)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     try
     {
         CoffeeModel coffeeModel          = _repository.FindCoffee(id);
         var         ingredientsForCoffee = _repository.GetIngredientsInCoffee(coffeeModel.CoffeeId)
                                            .ToList();
         ViewBag.IngredientsForCoffee = ingredientsForCoffee;
         if (statistics)
         {
             ViewBag.Statistics      = true;
             ViewBag.TotalProfit     = _repository.GetTotalProfitCoffee(coffeeModel);
             ViewBag.TotalProfitWeek = _repository.GetTotalProfitWeekCoffee(coffeeModel);
         }
         return(View(coffeeModel));
     }
     catch (Exception)
     {
         return(HttpNotFound());
     }
 }
예제 #4
0
        public IActionResult RepeatSelection(Models.CoffeeType type, int sugar, bool ownMug)
        {
            CoffeeModel model = new CoffeeModel();

            model.Type          = type;
            model.SpoonsOfSugar = sugar;
            model.UseOwnMug     = ownMug;
            return(View("Create", model));
        }
예제 #5
0
        // Map a Domain Entity with a MVC Model

        private CoffeeModel MapTo(Coffee c)
        {
            CoffeeModel coffee = new CoffeeModel();

            coffee.Type          = (Models.CoffeeType)c.Type;
            coffee.SpoonsOfSugar = c.SpoonsOfSugar;
            coffee.UseOwnMug     = c.UseOwnMug;

            return(coffee);
        }
        private void GetCoffeeFiles()
        {
            string[] files = Directory.GetFiles(path);

            foreach (var file in files)
            {
                CoffeeModel coffeeJson = JsonSerializer.Deserialize <CoffeeModel>(System.IO.File.ReadAllText(file));
                Coffees.Add(coffeeJson);
            }
        }
예제 #7
0
        public void AddCoffeWithoutName_DoesNotAddCoffee()
        {
            var CoffeeLenghtList = coffeeService.GetCoffees().Count;
            var AddCoffeeDetails = new CoffeeModel();

            AddCoffeeDetails.Id    = Guid.NewGuid();
            AddCoffeeDetails.Price = 10.68f;
            coffeeService.AddCoffee(AddCoffeeDetails);
            Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count);
        }
예제 #8
0
        public void AddCoffeWithoutId_DoesNotAddCoffee()
        {
            var CoffeeLenghtList = coffeeService.GetCoffees().Count;
            var AddCoffeeDetails = new CoffeeModel();

            AddCoffeeDetails.Name  = "Your coffe name";
            AddCoffeeDetails.Price = 22.20f;
            coffeeService.AddCoffee(AddCoffeeDetails);
            Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count);
        }
예제 #9
0
        public void AddCoffee_ExistingCoffeeId_DoesNotAddCoffee()
        {
            var CoffeeLenghtList = coffeeService.GetCoffees().Count;
            var AddCoffeeDetails = new CoffeeModel();

            AddCoffeeDetails.Name  = "malamala";
            AddCoffeeDetails.Id    = coffeeService.GetCoffees()[0].Id;
            AddCoffeeDetails.Price = 15.58f;

            Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count);
        }
예제 #10
0
        public void AddCoffee_ExistingCoffeePrice_DoesNotAddCoffee()
        {
            var CoffeeLenghtList = coffeeService.GetCoffees().Count;
            var AddCoffeeDetails = new CoffeeModel();

            AddCoffeeDetails.Name  = "hipoooo";
            AddCoffeeDetails.Id    = Guid.NewGuid();
            AddCoffeeDetails.Price = coffeeService.GetCoffees()[0].Price;

            Assert.AreEqual(CoffeeLenghtList, coffeeService.GetCoffees().Count);
        }
예제 #11
0
        public IHttpActionResult PostCoffee(CoffeeModel cafe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            coffeeRepository.Add(cafe);

            return(Ok(true));
        }
        public async Task <CoffeeModel> CreateCoffeeAsync(CoffeeModel model)
        {
            if (model == null)
            {
                throw new Exception("No Data Received");
            }
            model.Validate();
            var newCoffee = await _repo.CreateCoffeeAsync(model);

            return(newCoffee);
        }
예제 #13
0
        public async Task <CoffeeModel> CreateCoffeeAsync(CoffeeModel model)
        {
            var coffee = new Coffee();

            coffee.Assign(model);
            await _context.Set <Coffee>().AddAsync(coffee);

            await _context.SaveChangesAsync();

            model.Assign(coffee);
            return(model);
        }
예제 #14
0
 public IActionResult OnGet()
 {
     Coffee = TempData.Get <CoffeeModel>("jsonString");
     if (Coffee != null)
     {
         return(new PageResult());
     }
     else
     {
         return(RedirectToPage("Index"));
     }
 }
예제 #15
0
        private void MakeOrder(object obj)
        {
            CoffeeModel cm = null;

            if (this.Component.Name == "Coffee")
            {
                cm = this.Component as CoffeeModel;

                //cm.Products.AddRange()
            }

            this.ComponentsList.Add(this.Component);
        }
예제 #16
0
        public void AddCoffee(CoffeeModel coffeeToAdd)
        {
            if (coffeeToAdd == null)
            {
                throw new Exception("You should not add null entries!");
            }
            if (!IsCoffeeValid(coffeeToAdd))
            {
                throw new Exception("The coffee you are trying to add is not valid");
            }

            coffeeModels.Add(coffeeToAdd);
        }
예제 #17
0
        public void ReferenceTypes()
        {
            var coffeModel = new CoffeeModel
            {
                Name = "Test123"
            };

            var secondeCoffeeModel = coffeModel;

            coffeModel.Name = "My changed name";

            Assert.AreEqual(coffeModel.Name, secondeCoffeeModel.Name);
        }
예제 #18
0
        public CoffeeModel GetCoffee(int id)
        {
            CoffeeModel coffeeModel = new CoffeeModel();
            var         coffee      = coffeeRepository.GetById(id);

            if (coffee != null)
            {
                coffeeModel.Id        = coffee.Id;
                coffeeModel.Name      = coffee.Name;
                coffeeModel.PortionId = coffee.PortionId;
                coffeeModel.Price     = coffee.Price;
            }
            return(coffeeModel);
        }
예제 #19
0
        public IActionResult Insert([FromForm] CoffeeModel cm)
        {
            var response = new GenericResponseModel <string>();
            var bl       = new CoffeeBL();

            response = bl.InsertCoffee(cm);

            if (response.Status == false)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }
예제 #20
0
        private string UploadedFile(CoffeeModel model)
        {
            string uniqueFileName = string.Empty;

            if (model.Picture != null)
            {
                string uploadsFolder = Path.Combine(Directory.GetCurrentDirectory() + directory.PathDocument + "/CoffeePicture");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Picture.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Picture.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
예제 #21
0
        public void AddCoffee(CoffeeModel coffeeToAdd)
        {
            if (coffeeToAdd == null)
            {
                throw new Exception("You should not add null entries!");
            }

            if (coffeeModels.Any(i => i == coffeeToAdd))
            {
                throw new Exception("Already exists an entry with the same Id");
            }
            if (!(coffeeToAdd.Id == Guid.Empty || coffeeToAdd.Name == null || coffeeToAdd.Price <= 0.0f || coffeeModels.Any(j => j.Name == coffeeToAdd.Name) || coffeeModels.Any(j => j.Id == coffeeToAdd.Id) || coffeeModels.Any(j => j.Price == coffeeToAdd.Price)))
            {
                coffeeModels.Add(coffeeToAdd);
            }
        }
예제 #22
0
        public async Task <Unit> Handle(CoffeeCreateCommand request, CancellationToken cancellationToken)
        {
            var item = new CoffeeModel
            {
                Currency    = request.Currency,
                Name        = request.Name,
                Description = request.Description,
                Price       = request.Price,
                ImageUrl    = request.ImageUrl
            };

            await _repository.Add(item);

            _repository.Commit();
            return(Unit.Value);
        }
예제 #23
0
        public IActionResult Create([Bind("Type,SpoonsOfSugar,UseOwnMug")] CoffeeModel coffeeModel)
        {
            if (ModelState.IsValid)
            {
                //Mapping model with the Entity
                Coffee coffee = new Coffee();
                coffee.Type          = (Entities.CoffeeType)coffeeModel.Type;
                coffee.SpoonsOfSugar = coffeeModel.SpoonsOfSugar;
                coffee.UseOwnMug     = coffeeModel.UseOwnMug;
                coffee.DateOrdered   = DateTime.Now;

                _logic.CreateCoffee(coffee);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(coffeeModel));
        }
예제 #24
0
        public async Task AddCoffee(CoffeeModel coffeeToAdd)
        {
            if (coffeeToAdd == null)
            {
                throw new Exception("You should not add null entries!");
            }
            if (!IsCoffeeValid(coffeeToAdd))
            {
                throw new Exception("The coffee you are trying to add is not valid");
            }

            var coffeeEntityToAdd = mapper.Map <CoffeeEntity>(coffeeToAdd);

            coffeeEntityToAdd.EspressoMachine = await espressoMachineService.GetEspressoMachine(coffeeToAdd.IsEsspreso);

            await context.Coffees.AddAsync(coffeeEntityToAdd);

            await context.SaveChangesAsync();
        }
예제 #25
0
 public ActionResult LeastSoldWeek()
 {
     try
     {
         CoffeeModel leastSold = _repository.GetLeastSoldCoffeeWeek();
         ViewBag.Statistics = true;
         _repository.FixCoffeeQuantity(leastSold.CoffeeId);
         ViewBag.TotalProfit     = _repository.GetTotalProfitCoffee(leastSold);
         ViewBag.TotalProfitWeek = _repository.GetTotalProfitWeekCoffee(leastSold);
         var ingredientsForCoffee = _repository.GetIngredientsInCoffee(leastSold.CoffeeId)
                                    .ToList();
         ViewBag.IngredientsForCoffee = ingredientsForCoffee;
         return(View("Details", leastSold));
     }
     catch (Exception)
     {
         return(HttpNotFound());
     }
 }
예제 #26
0
        private async void MakeEspresso()
        {
            CounterEspresso++;
            var data = CreateCoffeeMachineData(nameof(CounterEspresso), CounterEspresso);

            await SendDataAsync(data);

            await coffeeDataService.AddCoffeeData(data);

            var coffeeModelToAdd = new CoffeeModel
            {
                IsEsspreso = true,
                Name       = "Espresso",
                Sweetness  = Services.Enums.SweetnessEnum.Bitter,
                Price      = 15
            };

            await coffeeService.AddCoffee(coffeeModelToAdd);
        }
예제 #27
0
        public void CalculateOrderTotal_ShouldReturnTotal_WhenOrderContainsCoffee()
        {
            const int orderId     = 1;
            var       coffeeModel = new CoffeeModel
            {
                AmountOfCream = 3,
                AmountOfSugar = 3,
                OrderId       = orderId,
                Size          = "large"
            };

            _coffeeRepository.Setup(c => c.GetByOrderId(1)).Returns(new List <CoffeeModel> {
                coffeeModel
            });

            var amount = _orderService.CalculateOrderTotal(orderId);

            Assert.That(amount, Is.GreaterThan(0));
        }
예제 #28
0
        public string UpdateCoffee(CoffeeModel cm)
        {
            var result = string.Empty;

            var query = string.Format(@"
            BEGIN TRY
                UPDATE tbl_coffee 
                SET Name = '{0}', Price = {1}, Size = '{2}' where id = {3}
                SELECT 'COMPLETE'
            END TRY
            BEGIN CATCH
                SELECT ERROR_MESSAGE()
            END CATCH
            ", cm.Name, cm.Price, cm.Size, cm.ID);

            result = ExecuteScalar(query);

            return(result);
        }
예제 #29
0
        private async void MakeCappucinno()
        {
            CounterCappuccino++;
            var data = CreateCoffeeMachineData(nameof(CounterCappuccino), CounterCappuccino);

            await SendDataAsync(data);

            await coffeeDataService.AddCoffeeData(data);

            var coffeeModelToAdd = new CoffeeModel
            {
                IsEsspreso = false,
                Name       = "Normal Coffee",
                Sweetness  = Services.Enums.SweetnessEnum.Sweet,
                Price      = 20
            };

            await coffeeService.AddCoffee(coffeeModelToAdd);
        }
예제 #30
0
        public string InsertCoffee(CoffeeModel cm)
        {
            var result = string.Empty;

            cm.PictureName = UploadedFile(cm);
            var query = string.Format(@"
            BEGIN TRY
                INSERT INTO tbl_coffee (Name, Price, Size, Picture)
                VALUES ('{0}', {1}, '{2}', '{3}')
                SELECT 'COMPLETE'
            END TRY
            BEGIN CATCH
                SELECT ERROR_MESSAGE()
            END CATCH
            ", cm.Name, cm.Price, cm.Size, cm.PictureName);

            result = ExecuteScalar(query);

            return(result);
        }