Software_Engineering_Field_.../SiteManagementSystem(Softwa.../Service/PythonServiceFile/layer.py

38 lines
1.3 KiB
Python
Raw Normal View History

2024-11-03 11:21:47 +08:00
import clr
from user import User
from field import Field
2024-11-04 22:26:45 +08:00
from user_field import FieldRecord
2024-11-03 11:21:47 +08:00
clr.AddReference('System')
from System import Guid, DateTime
class Layer:
def __init__(self, layer):
self._field_db = layer.FieldDb
self._record_db = layer.RecordDb
def add_field(self, field: Field) -> 'Layer':
self._field_db.Add(field.parse_to_csharp_object(self._field_db.GetDefaultEntity()))
return self
# The value property will
def find_field(self, key: str, value: str) -> [Field]:
return [Field(t) for t in self._field_db.FindAll(key, Guid.Parse(value))]
def remove_field(self, field: Field) -> 'Layer':
self._field_db.TryDelete(field.id, field.parse_to_csharp_object(self._field_db.GetDefaultEntity()).Id)
return self
2024-11-04 22:26:45 +08:00
def add_record(self, record: FieldRecord) -> 'Layer':
2024-11-03 11:21:47 +08:00
self._record_db.Add(record.parse_to_csharp_object(self._record_db.GetDefaultEntity()))
return self
2024-11-04 22:26:45 +08:00
def find_record(self, key: str, value: str) -> [FieldRecord]:
return [FieldRecord(t) for t in self._record_db.FindAll(key, Guid.Parse(value))]
2024-11-03 11:21:47 +08:00
# One User only allowed to book one field at a time
2024-11-04 22:26:45 +08:00
def remove_record(self, record: FieldRecord) -> 'Layer':
2024-11-03 11:21:47 +08:00
self._record_db.TryDelete("Uid", record.parse_to_csharp_object(self._record_db.GetDefaultEntity()).Uid)
return self