프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM_API / MarkusService.svc.cs @ 92c9cab8

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

1
using KCOMDataModel.DataModel;
2
using System;
3
using System.Collections.Generic;
4
using System.Configuration;
5
using System.Linq;
6
using System.Runtime.Serialization;
7
using System.ServiceModel;
8
using System.ServiceModel.Activation;
9
using System.ServiceModel.Web;
10
using System.Text;
11

    
12
namespace KCOM_API
13
{
14
    [ServiceContract(Namespace = "")]
15
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
16
    public class MarkusService : System.Web.Services.WebService
17
    {
18
        [WebGet(UriTemplate = "AddMember?UserId={UserId}&Name={Name}&Company={Company}&Department={Department}&Position={Position}&email={email}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
19
        [OperationContract]
20
        public AddMemberResults AddMember(string UserId,string Name, string Company, string Department,string Position,string email)
21
        {
22
            AddMemberResults results = new AddMemberResults(false,null);
23

    
24
            try
25
            {
26
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
27
                using (CIEntities _ci = new CIEntities(sCIConnString))
28
                {
29
                    if (_ci.MEMBER.Count(x => x.ID == UserId) == 0)
30
                    {
31
                        _ci.AddToMEMBER(new MEMBER
32
                        {
33
                            ID = UserId,
34
                            NAME = Name,
35
                            COMPANY = Company,
36
                            DEPARTMENT = Department,
37
                            POSITION = Position,
38
                            EMAIL_ADDRESS = email,
39
                            MODIFIED_DATETIME = DateTime.Now,
40
                            CREATE_DATETIME = DateTime.Now
41
                        });
42

    
43
                        _ci.SaveChanges();
44

    
45
                        results.IsSuccess = true;
46
                    }
47
                    else
48
                    {
49
                        results.Message = "User already exists.";
50
                    }
51
                }
52
            }
53
            catch (Exception ex)
54
            {
55
                results.Message = "system Error";
56
            }
57
            finally
58
            {
59

    
60
            }
61

    
62
            return results;
63
        }
64

    
65
        [WebInvoke(UriTemplate = "GetMembers",Method ="POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
66
        [OperationContract]
67
        public GetMembersResults GetMembers()
68
        {
69
            GetMembersResults results = new GetMembersResults();
70

    
71
            try
72
            {
73
                string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
74
                using (CIEntities _ci = new CIEntities(sCIConnString))
75
                {
76
                    if (_ci.MEMBER.Count() > 0)
77
                    {
78
                        results.Members = _ci.MEMBER.Select(m => new Member
79
                        {
80
                            ID = m.ID,
81
                            NAME = m.NAME,
82
                            COMPANY = m.COMPANY,
83
                            DEPARTMENT = m.DEPARTMENT,
84
                            POSITION = m.POSITION,
85
                            EMAIL_ADDRESS = m.EMAIL_ADDRESS
86
                        }).ToArray();
87
                    }
88
                }
89
            }
90
            catch (Exception ex)
91
            {
92
            }
93
            finally
94
            {
95

    
96
            }
97

    
98
            return results;
99
        }
100
    }
101
}
클립보드 이미지 추가 (최대 크기: 500 MB)