BasePointRuleController.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.EntityFrameworkCore;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using wispro.sp.entity;
  8. using wispro.sp.share;
  9. // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  10. namespace wispro.sp.api.Controllers
  11. {
  12. [Route("api/[controller]/[action]")]
  13. [ApiController]
  14. public class BasePointRuleController : ControllerBase
  15. {
  16. spDbContext Context;
  17. public BasePointRuleController(spDbContext context)
  18. {
  19. Context = context;
  20. }
  21. // GET: api/<BasePointRuleController>
  22. [HttpGet]
  23. public IEnumerable<BasePointRule> Get()
  24. {
  25. return Context.BasePointRules.ToList<BasePointRule>();
  26. }
  27. [HttpGet("{id}")]
  28. public BasePointRule Get(int id)
  29. {
  30. return Context.BasePointRules.Where<BasePointRule>(b => b.Id == id).FirstOrDefault<BasePointRule>();
  31. }
  32. // POST api/<BasePointRuleController>
  33. [HttpPost]
  34. public ApiSaveResponse New(BasePointRule value)
  35. {
  36. ApiSaveResponse ret = new ApiSaveResponse();
  37. try
  38. {
  39. Context.BasePointRules.Add(value);
  40. Context.SaveChanges();
  41. ret.Success = true;
  42. }
  43. catch(Exception ex)
  44. {
  45. ret.Success = false;
  46. ret.ErrorMessage = ex.Message;
  47. }
  48. return ret;
  49. }
  50. [HttpPost]
  51. public void Update(int id, string field,string value)
  52. {
  53. string strSQL = $"update basepointrule set {field}={value} where id={id}";
  54. Context.Database.ExecuteSqlRaw(strSQL);
  55. }
  56. [HttpDelete("{id}")]
  57. public bool Delete(int id)
  58. {
  59. Context.BasePointRules.Remove(new BasePointRule() { Id = id });
  60. Context.SaveChanges();
  61. return true;
  62. }
  63. }
  64. }