BasePointRuleController.cs 2.1 KB

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