public async Task <CoffeeModel> GetCoffeeByIdAsync(int id) { var CoffeeModel = new CoffeeModel(); var coffee = await _context.Set <Coffee>().FindAsync(id); return(CoffeeModel.Assign(coffee)); }
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"); }
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()); } }
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)); }
// 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); } }
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); }
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); }
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); }
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); }
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); }
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); }
public IActionResult OnGet() { Coffee = TempData.Get <CoffeeModel>("jsonString"); if (Coffee != null) { return(new PageResult()); } else { return(RedirectToPage("Index")); } }
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); }
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); }
public void ReferenceTypes() { var coffeModel = new CoffeeModel { Name = "Test123" }; var secondeCoffeeModel = coffeModel; coffeModel.Name = "My changed name"; Assert.AreEqual(coffeModel.Name, secondeCoffeeModel.Name); }
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); }
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)); }
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); }
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); } }
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); }
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)); }
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(); }
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()); } }
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); }
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)); }
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); }
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); }
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); }