public async Task <IActionResult> PurgeCoffee(DeleteCoffeeViewModel coffee) { var model = new CoffeeDBO(); model.ID = coffee.ID; await _coffeeRepository.DeleteExistingCoffee(model); return(RedirectToAction("CoffeesMenu")); }
public IActionResult AddCoffee(AddCoffeeViewModel postModel) { var dboCoffee = new CoffeeDBO(); dboCoffee.Name = postModel.Name; dboCoffee.Price = postModel.Price; dboCoffee.Description = postModel.Description; _coffeeRepository.InsertIntoCoffee(dboCoffee); return(RedirectToAction(nameof(Coffees))); }
public async Task <IActionResult> InsertCoffee(GenerateCoffeeViewModel coffee) { var model = new CoffeeDBO(); model.Name = coffee.Name; model.Description = coffee.Description; model.Price = coffee.Price; await _coffeeRepository.InsertIntoCoffee(model); return(RedirectToAction("CoffeesMenu")); }
public async Task <IActionResult> UpdatedCoffee(UpdateCoffeeViewModel coffee) { var model = new CoffeeDBO(); model.Name = coffee.Name; model.Description = coffee.Description; model.Price = coffee.Price; model.ID = coffee.ID; await _coffeeRepository.UpdateExistingCoffee(model); return(RedirectToAction("CoffeesMenu")); }
public async Task <IActionResult> DeleteExistingCoffee([FromBody] CoffeeDBO model) { var coffees = _coffeeRepository.DeleteExistingCoffee(model).Result; if (coffees) { return(Ok("Coffee removed from database.")); } else { return(BadRequest("Coffee not modified. Check model ID property.")); } }
public async Task <IActionResult> UpdateExistingCoffee([FromBody] CoffeeDBO model) { var coffees = _coffeeRepository.UpdateExistingCoffee(model).Result; if (coffees) { return(Ok("Coffee updated in database.")); } else { return(BadRequest("Coffee not modified. Check model properties.")); } }
public IActionResult UpdateCoffee(UpdateCoffeeViewModel model) { var dboCoffee = new CoffeeDBO(); dboCoffee.Name = model.NewName; dboCoffee.Price = model.NewPrice; dboCoffee.Description = model.NewDescription; dboCoffee.ID = model.ID; _coffeeRepository.UpdateSelectedCoffee(dboCoffee); return(RedirectToAction(nameof(Coffees))); }
public async Task <IActionResult> InsertIntoCoffee([FromBody] CoffeeDBO model) { var coffees = _coffeeRepository.InsertIntoCoffee(model).Result; // I can't use await here. Is Task and async really needed in an API? if (coffees) { return(Ok("Coffee added to database.")); } else { return(BadRequest("Coffee not added to database. Check model properties.")); } }
public async Task <IActionResult> ShowCoffeeDetails(int ID) { var model = new CoffeeDBO(); var viewModel = new ShowCoffeeDetailsViewModel(); model.ID = ID; var showMeThisCoffee = await _coffeeRepository.ShowCoffeeDetails(model); viewModel.Description = showMeThisCoffee.Description; viewModel.Name = showMeThisCoffee.Name; viewModel.ID = showMeThisCoffee.ID; viewModel.Price = showMeThisCoffee.Price; return(View(viewModel)); }
public bool InsertIntoCoffee(CoffeeDBO model) { var queryString = @$ "INSERT INTO Coffee (Name, Price, Description) VALUES(@{nameof(CoffeeDBO.Name)}, @{nameof(CoffeeDBO.Price)}, @{nameof(CoffeeDBO.Description)});";