프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / AttFileRepository.cs @ 677a1d1f

이력 | 보기 | 이력해설 | 다운로드 (2.55 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

    
7
using ID2.Manager.Data.Models;
8

    
9
namespace ID2.Manager.Dapper.Repository
10
{
11
    public class AttFileRepository : BaseRepository
12
    {
13
        public AttFileRepository(string connectionStr) : base(connectionStr) { }
14

    
15
        public IEnumerable<AttFileInfo> GetAttFileList(string refID, string category)
16
        {
17
            try
18
            {
19
                string query = $@"
20
select * from dbo.AttachFIles where RefID=@RefID and Category=@Category order by CreatedDate";
21
                return Query<AttFileInfo>(query, new { RefID = refID, Category = category });
22
            }
23
            catch (Exception ex)
24
            {
25
                throw ex;
26
            }
27
        }
28

    
29
        public AttFileInfo GetAttFileInfo(string refID, string category)
30
        {
31
            try
32
            {
33
                string query = $@"
34
select top 1 * from dbo.AttachFIles where RefID=@RefID and Category=@Category order by CreatedDate";
35
                return QueryFirstOrDefault<AttFileInfo>(query, new { RefID = refID, Category = category });
36
            }
37
            catch (Exception ex)
38
            {
39
                throw ex;
40
            }
41
        }
42

    
43
        public bool SetAttFiles(List<AttFileInfo> attFiles, string userId)
44
        {
45
            bool isSuccess = false;
46

    
47
            try
48
            {
49
                string query = string.Empty;
50

    
51
                using (var transaction = base.BeginTransaction())
52
                {
53
                    foreach (AttFileInfo attFile in attFiles)
54
                    {
55
                        attFile.Creator = userId;
56

    
57
                        switch (attFile.Category)
58
                        {
59
                            case "notice":
60
                                query = $@"delete dbo.AttachFIles where RefID=@RefID and Category=@Category";
61
                                break;
62
                        }
63
                        query += $@"
64
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator)
65
values
66
(
67
    lower(newid())
68
   ,@RefID
69
   ,@Category
70
   ,@FileType
71
   ,@FileName
72
   ,@FilePath
73
   ,@FileExtension
74
   ,@FileData
75
   ,@Creator
76
)";
77

    
78
                        base.Execute(query, attFile, transaction);
79
                    }
80

    
81
                    transaction.Commit();
82
                    isSuccess = true;
83
                }
84
            }
85
            catch (Exception ex)
86
            {
87
                throw ex;
88
            }
89

    
90
            return isSuccess;
91
        }
92
    }
93
}
클립보드 이미지 추가 (최대 크기: 500 MB)