RecipeController.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using ProductionLineMonitor.Core.Dtos;
  5. using ProductionLineMonitor.Core.Services;
  6. using ProductionLineMonitor.Web.Filters;
  7. using System.Collections.Generic;
  8. using System.ComponentModel.DataAnnotations;
  9. using System.Xml.Linq;
  10. using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
  11. namespace ProductionLineMonitor.Web.Controllers
  12. {
  13. public class RecipeController : BaseController
  14. {
  15. private readonly IRecipeService _recipeService;
  16. public RecipeController(IRecipeService recipeService)
  17. {
  18. _recipeService = recipeService;
  19. }
  20. [HttpGet("/Recipe")]
  21. public IActionResult Index()
  22. {
  23. return View();
  24. }
  25. [HttpGet("/Recipe/GetRecipes")]
  26. public IActionResult GetRecipes(int pageNumber, int pageSize, string keyword)
  27. {
  28. pageNumber = pageNumber == 0 ? 1 : pageNumber;
  29. pageSize = pageSize == 0 ? 10 : pageSize;
  30. keyword ??= "";
  31. return Ok(_recipeService.GetPageList(pageNumber, pageSize, keyword));
  32. }
  33. [HttpPost("/Recipe/CreateRecipe")]
  34. public IActionResult CreateRecipe([FromBody] RecipeCreateOrUpdateDto dto)
  35. {
  36. return Ok(_recipeService.Create(dto));
  37. }
  38. [HttpGet("/Recipe/{id}")]
  39. public IActionResult GetRecipe([FromRoute] string id)
  40. {
  41. return Ok(_recipeService.GetById(id));
  42. }
  43. [HttpPost("/Recipe/UpdateRecipe/{id}")]
  44. public IActionResult UpdateRecipe([FromRoute] string id, [FromBody] RecipeCreateOrUpdateDto dto)
  45. {
  46. return Ok(_recipeService.Update(id, dto));
  47. }
  48. [HttpPost("/Recipe/DeleteRecipe/{id}")]
  49. public IActionResult DeleteRecipe([FromRoute] string id)
  50. {
  51. return Ok(_recipeService.Delete(id));
  52. }
  53. }
  54. }