public Attachment GetAttachmentByName(string originName)
 {
     using (var cnn = DataDb.DbConnection())
     {
         return(cnn.Query <Attachment>(typeof(Attachment).GetSelectSql("OriginName=@OriginName", SelectIgnore), new { OriginName = originName }).FirstOrDefault());
     }
 }
 public List <Attachment> LoadAllAttachment()
 {
     using (var cnn = DataDb.DbConnection())
     {
         return(cnn.Query <Attachment>(typeof(Attachment).GetSelectSql(null, SelectIgnore)).ToList <Attachment>());
     }
 }
 public Attachment GetAttachmentById(int attachmentId)
 {
     using (var cnn = DataDb.DbConnection())
     {
         return(cnn.Query <Attachment>(typeof(Attachment).GetSelectSql("AttachmentId=@AttachmentId", SelectIgnore), new { AttachmentId = attachmentId }).FirstOrDefault());
     }
 }
 public bool DeleteAttachment(int attachmentId)
 {
     using (var cnn = DataDb.DbConnection())
     {
         return(cnn.Execute("Delete from Attachment where AttachmentId=@AttachmentId", new { AttachmentId = attachmentId }) > 0);
     }
 }
 public List <Attachment> LoadAttachmentByIds(List <int> attachmentIds)
 {
     using (var cnn = DataDb.DbConnection())
     {
         return(cnn.Query <Attachment>(typeof(Attachment).GetSelectSql("AttachmentId in @ids", SelectIgnore)
                                       , new { ids = attachmentIds.ToArray() }).ToList <Attachment>());
     }
 }
예제 #6
0
 public bool Delete(string key)
 {
     using (var cnn = DataDb.DbConnection())
     {
         int i = cnn.Execute(string.Format("delete from {0} where {1}=@Key", TableName, keyColumn)
                             , new { Key = key });
         return(i > 0);
     }
 }
예제 #7
0
 public dynamic LoadDynamicModel()
 {
     using (var cnn = DataDb.DbConnection())
     {
         var     obj    = cnn.Query <dynamic>(string.Format("select {1} as Name, {2} as Content from {0}", TableName, keyColumn, valueColumn)).ToList();
         dynamic dModel = new DynamicModel();
         logger.Debug(obj);
         foreach (var o in obj)
         {
             dModel.Set(o.Name, o.Content);
         }
         return(dModel);
     }
 }
 public Attachment SaveAttachment(Attachment attachment)
 {
     using (var cnn = DataDb.DbConnection())
     {
         if (attachment.AttachmentId == null || attachment.AttachmentId <= 0)
         {
             attachment.AttachmentId = cnn.Query <int>(attachment.GetSqliteInsertSql(InsertIgnore), attachment).FirstOrDefault();
             return(attachment);
         }
         else
         {
             cnn.Execute(attachment.GetUpdateSql(KeyFiled, UpdateIgnore), attachment);
             return(attachment);
         }
     }
 }
예제 #9
0
 public bool Save(string key, string value)
 {
     using (var cnn = DataDb.DbConnection())
     {
         int i = cnn.Query <int>(string.Format("select count({1}) from {0} where {1}=@Key", TableName, keyColumn)
                                 , new { Key = key }).FirstOrDefault();
         int rows = 0;
         if (i > 0)
         {
             rows = cnn.Execute(string.Format("Update {0} set {2}=@Value where {1}=@Key", TableName, keyColumn, valueColumn)
                                , new { Key = key, Value = value });
         }
         else
         {
             rows = cnn.Execute(string.Format("Insert into {0}({1},{2}) values(@Key,@Value)", TableName, keyColumn, valueColumn)
                                , new { Key = key, Value = value });
         }
         return(rows > 0);
     }
 }