Пример #1
0
class BrandFacade(BaseFacade):
    def __init__(self, context):
        self._repository = BrandRepository()
        super(BrandFacade, self).__init__(context)
    def get(self, entity_id):
        entity = self._repository.get(entity_id)
        if (entity is None or (not self.is_accessable(entity))):
            return None
        return obj_map(entity, BrandViewModel)
    def list(self, param = None):
        if (not param):
            param = BrandQueryModel()
        param.user_id = self._context.user_id
        entities = self._repository.list(param)
        return map(lambda e: obj_map(e, BrandViewModel, rules={
                                                                   'photos':lambda e: map(lambda f:UploadFileViewModel({'id':f.id}), e.uploadFiles),
                                                                   }), entities)
    def save(self, viewModel):
        entity = obj_map(viewModel, Brand)
        if (entity.user_id > 0 and (not self.is_accessable(entity))):
            return
        return self._repository.save(entity)
    def delete(self, entity_id):
        entity = self.get(entity_id)
        if entity is None:
            return
        return self._repository.delete(entity_id)
    def delete_file(self, brand_id, file_id):
        entity = self.get(brand_id)
        if entity is None:
            return
        return self._repository.delete_file(brand_id, file_id)
    def add_file(self, brand_id, file_id, file_type):
        entity = self.get(brand_id)
        if entity is None:
            return
        return self._repository.add_file(brand_id, file_id, file_type)
Пример #2
0
 def __init__(self, context):
     self._repository = BrandRepository()
     super(BrandFacade, self).__init__(context)