CommandDAL.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using OHV.Common.Model;
  7. using OHV.Common.Shareds;
  8. namespace OHV.SqliteDAL.DAL
  9. {
  10. public class CommandDAL : GenericDAL<Command>
  11. {
  12. public Command GetCmd()
  13. {
  14. Command cmd;
  15. using (var db = new OHVDbContext("OHVDb"))
  16. {
  17. cmd = db.Set<Command>().FirstOrDefault();
  18. }
  19. return cmd;
  20. }
  21. public void UpdateState(string id, eCommandState state)
  22. {
  23. using (var db = new OHVDbContext("OHVDb"))
  24. {
  25. var cmd = db.Set<Command>().Where(c => c.CommandID.Equals(id)).SingleOrDefault();
  26. cmd.State = state;
  27. db.SaveChanges();
  28. }
  29. }
  30. public void UpdateResult(string id, eCommandResult result)
  31. {
  32. using (var db = new OHVDbContext("OHVDb"))
  33. {
  34. var cmd = db.Set<Command>().Where(c => c.CommandID.Equals(id)).SingleOrDefault();
  35. cmd.Result = result;
  36. db.SaveChanges();
  37. }
  38. }
  39. public int GetCount()
  40. {
  41. int count = 0;
  42. using (var db = new OHVDbContext("OHVDb"))
  43. {
  44. count = db.Set<Command>().Count();
  45. }
  46. return count;
  47. }
  48. }
  49. }