|
| 1 | +/** |
| 2 | +* @file CBComSelCouponController.cs |
| 3 | +* @brief Get 1 coupon data from Coupon table \n |
| 4 | +* @author Dae Woo Kim |
| 5 | +* @param string CouponID |
| 6 | +* @param string MemberID |
| 7 | +* @return Coupon table object |
| 8 | +* @see uspComSelCoupon SP, BehaviorID : B71 |
| 9 | +*/ |
| 10 | + |
| 11 | +using System; |
| 12 | +using System.Collections.Generic; |
| 13 | +using System.Linq; |
| 14 | +using System.Net; |
| 15 | +using System.Net.Http; |
| 16 | +using System.Web.Http; |
| 17 | +using Microsoft.Azure.Mobile.Server; |
| 18 | +using Microsoft.Azure.Mobile.Server.Config; |
| 19 | + |
| 20 | +using System.Threading.Tasks; |
| 21 | +using System.Diagnostics; |
| 22 | +using Logger.Logging; |
| 23 | +using CloudBread.globals; |
| 24 | +using CloudBreadLib.BAL.Crypto; |
| 25 | +using System.Data; |
| 26 | +using System.Data.Sql; |
| 27 | +using System.Data.SqlClient; |
| 28 | +using Newtonsoft.Json; |
| 29 | +using CloudBreadAuth; |
| 30 | +using System.Security.Claims; |
| 31 | +using Microsoft.Practices.TransientFaultHandling; |
| 32 | +using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure; |
| 33 | + |
| 34 | +namespace CloudBread.Controllers |
| 35 | +{ |
| 36 | + [MobileAppController] |
| 37 | + public class CBComSelCouponController : ApiController |
| 38 | + { |
| 39 | + |
| 40 | + public class InputParams |
| 41 | + { |
| 42 | + public string MemberID; // log purpose |
| 43 | + public string CouponID; |
| 44 | + } |
| 45 | + |
| 46 | + public class Model |
| 47 | + { |
| 48 | + public string CouponID { get; set; } |
| 49 | + public string CouponCategory1 { get; set; } |
| 50 | + public string CouponCategory2 { get; set; } |
| 51 | + public string CouponCategory3 { get; set; } |
| 52 | + public string ItemListID { get; set; } |
| 53 | + public string ItemCount { get; set; } |
| 54 | + public string ItemStatus { get; set; } |
| 55 | + public string TargetGroup { get; set; } |
| 56 | + public string TargetOS { get; set; } |
| 57 | + public string TargetDevice { get; set; } |
| 58 | + public string Title { get; set; } |
| 59 | + public string Content { get; set; } |
| 60 | + public string sCol1 { get; set; } |
| 61 | + public string sCol2 { get; set; } |
| 62 | + public string sCol3 { get; set; } |
| 63 | + public string sCol4 { get; set; } |
| 64 | + public string sCol5 { get; set; } |
| 65 | + public string sCol6 { get; set; } |
| 66 | + public string sCol7 { get; set; } |
| 67 | + public string sCol8 { get; set; } |
| 68 | + public string sCol9 { get; set; } |
| 69 | + public string sCol10 { get; set; } |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + public List<Model> Post(InputParams p) |
| 74 | + { |
| 75 | + // Get the sid or memberID of the current user. |
| 76 | + var claimsPrincipal = this.User as ClaimsPrincipal; |
| 77 | + string sid = CBAuth.getMemberID(p.MemberID, claimsPrincipal); |
| 78 | + p.MemberID = sid; |
| 79 | + |
| 80 | + Logging.CBLoggers logMessage = new Logging.CBLoggers(); |
| 81 | + string jsonParam = JsonConvert.SerializeObject(p); |
| 82 | + |
| 83 | + List<Model> result = new List<Model>(); |
| 84 | + |
| 85 | + try |
| 86 | + { |
| 87 | + /// Database connection retry policy |
| 88 | + RetryPolicy retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds)); |
| 89 | + using (SqlConnection connection = new SqlConnection(globalVal.DBConnectionString)) |
| 90 | + { |
| 91 | + using (SqlCommand command = new SqlCommand("uspComSelCoupon", connection)) |
| 92 | + { |
| 93 | + command.CommandType = CommandType.StoredProcedure; |
| 94 | + command.Parameters.Add("@CouponID", SqlDbType.NVarChar, -1).Value = p.CouponID; |
| 95 | + connection.OpenWithRetry(retryPolicy); |
| 96 | + |
| 97 | + using (SqlDataReader dreader = command.ExecuteReaderWithRetry(retryPolicy)) |
| 98 | + { |
| 99 | + while (dreader.Read()) |
| 100 | + { |
| 101 | + Model workItem = new Model() |
| 102 | + { |
| 103 | + CouponID = dreader[0].ToString(), |
| 104 | + CouponCategory1 = dreader[1].ToString(), |
| 105 | + CouponCategory2 = dreader[2].ToString(), |
| 106 | + CouponCategory3 = dreader[3].ToString(), |
| 107 | + ItemListID = dreader[4].ToString(), |
| 108 | + ItemCount = dreader[5].ToString(), |
| 109 | + ItemStatus = dreader[6].ToString(), |
| 110 | + TargetGroup = dreader[7].ToString(), |
| 111 | + TargetOS = dreader[8].ToString(), |
| 112 | + TargetDevice = dreader[9].ToString(), |
| 113 | + Title = dreader[10].ToString(), |
| 114 | + Content = dreader[11].ToString(), |
| 115 | + sCol1 = dreader[12].ToString(), |
| 116 | + sCol2 = dreader[13].ToString(), |
| 117 | + sCol3 = dreader[14].ToString(), |
| 118 | + sCol4 = dreader[15].ToString(), |
| 119 | + sCol5 = dreader[16].ToString(), |
| 120 | + sCol6 = dreader[17].ToString(), |
| 121 | + sCol7 = dreader[18].ToString(), |
| 122 | + sCol8 = dreader[19].ToString(), |
| 123 | + sCol9 = dreader[20].ToString(), |
| 124 | + sCol10 = dreader[21].ToString(), |
| 125 | + |
| 126 | + }; |
| 127 | + result.Add(workItem); |
| 128 | + } |
| 129 | + dreader.Close(); |
| 130 | + } |
| 131 | + connection.Close(); |
| 132 | + } |
| 133 | + return result; |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + catch (Exception ex) |
| 138 | + { |
| 139 | + // error log |
| 140 | + logMessage.memberID = p.MemberID; |
| 141 | + logMessage.Level = "ERROR"; |
| 142 | + logMessage.Logger = "CBComSelCouponController"; |
| 143 | + logMessage.Message = jsonParam; |
| 144 | + logMessage.Exception = ex.ToString(); |
| 145 | + Logging.RunLog(logMessage); |
| 146 | + |
| 147 | + throw; |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + } |
| 152 | +} |
0 commit comments