forked from CloudBreadProject/CloudBread
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19993f8
commit ba9acb4
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/** | ||
* @file CBComSelCouponController.cs | ||
* @brief Get 1 coupon data from Coupon table \n | ||
* @author Dae Woo Kim | ||
* @param string CouponID | ||
* @param string MemberID | ||
* @return Coupon table object | ||
* @see uspComSelCoupon SP, BehaviorID : B71 | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Web.Http; | ||
using Microsoft.Azure.Mobile.Server; | ||
using Microsoft.Azure.Mobile.Server.Config; | ||
|
||
using System.Threading.Tasks; | ||
using System.Diagnostics; | ||
using Logger.Logging; | ||
using CloudBread.globals; | ||
using CloudBreadLib.BAL.Crypto; | ||
using System.Data; | ||
using System.Data.Sql; | ||
using System.Data.SqlClient; | ||
using Newtonsoft.Json; | ||
using CloudBreadAuth; | ||
using System.Security.Claims; | ||
using Microsoft.Practices.TransientFaultHandling; | ||
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure; | ||
|
||
namespace CloudBread.Controllers | ||
{ | ||
[MobileAppController] | ||
public class CBComSelCouponController : ApiController | ||
{ | ||
|
||
public class InputParams | ||
{ | ||
public string MemberID; // log purpose | ||
public string CouponID; | ||
} | ||
|
||
public class Model | ||
{ | ||
public string CouponID { get; set; } | ||
public string CouponCategory1 { get; set; } | ||
public string CouponCategory2 { get; set; } | ||
public string CouponCategory3 { get; set; } | ||
public string ItemListID { get; set; } | ||
public string ItemCount { get; set; } | ||
public string ItemStatus { get; set; } | ||
public string TargetGroup { get; set; } | ||
public string TargetOS { get; set; } | ||
public string TargetDevice { get; set; } | ||
public string Title { get; set; } | ||
public string Content { get; set; } | ||
public string sCol1 { get; set; } | ||
public string sCol2 { get; set; } | ||
public string sCol3 { get; set; } | ||
public string sCol4 { get; set; } | ||
public string sCol5 { get; set; } | ||
public string sCol6 { get; set; } | ||
public string sCol7 { get; set; } | ||
public string sCol8 { get; set; } | ||
public string sCol9 { get; set; } | ||
public string sCol10 { get; set; } | ||
|
||
} | ||
|
||
public List<Model> Post(InputParams p) | ||
{ | ||
// Get the sid or memberID of the current user. | ||
var claimsPrincipal = this.User as ClaimsPrincipal; | ||
string sid = CBAuth.getMemberID(p.MemberID, claimsPrincipal); | ||
p.MemberID = sid; | ||
|
||
Logging.CBLoggers logMessage = new Logging.CBLoggers(); | ||
string jsonParam = JsonConvert.SerializeObject(p); | ||
|
||
List<Model> result = new List<Model>(); | ||
|
||
try | ||
{ | ||
/// Database connection retry policy | ||
RetryPolicy retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds)); | ||
using (SqlConnection connection = new SqlConnection(globalVal.DBConnectionString)) | ||
{ | ||
using (SqlCommand command = new SqlCommand("uspComSelCoupon", connection)) | ||
{ | ||
command.CommandType = CommandType.StoredProcedure; | ||
command.Parameters.Add("@CouponID", SqlDbType.NVarChar, -1).Value = p.CouponID; | ||
connection.OpenWithRetry(retryPolicy); | ||
|
||
using (SqlDataReader dreader = command.ExecuteReaderWithRetry(retryPolicy)) | ||
{ | ||
while (dreader.Read()) | ||
{ | ||
Model workItem = new Model() | ||
{ | ||
CouponID = dreader[0].ToString(), | ||
CouponCategory1 = dreader[1].ToString(), | ||
CouponCategory2 = dreader[2].ToString(), | ||
CouponCategory3 = dreader[3].ToString(), | ||
ItemListID = dreader[4].ToString(), | ||
ItemCount = dreader[5].ToString(), | ||
ItemStatus = dreader[6].ToString(), | ||
TargetGroup = dreader[7].ToString(), | ||
TargetOS = dreader[8].ToString(), | ||
TargetDevice = dreader[9].ToString(), | ||
Title = dreader[10].ToString(), | ||
Content = dreader[11].ToString(), | ||
sCol1 = dreader[12].ToString(), | ||
sCol2 = dreader[13].ToString(), | ||
sCol3 = dreader[14].ToString(), | ||
sCol4 = dreader[15].ToString(), | ||
sCol5 = dreader[16].ToString(), | ||
sCol6 = dreader[17].ToString(), | ||
sCol7 = dreader[18].ToString(), | ||
sCol8 = dreader[19].ToString(), | ||
sCol9 = dreader[20].ToString(), | ||
sCol10 = dreader[21].ToString(), | ||
|
||
}; | ||
result.Add(workItem); | ||
} | ||
dreader.Close(); | ||
} | ||
connection.Close(); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
catch (Exception ex) | ||
{ | ||
// error log | ||
logMessage.memberID = p.MemberID; | ||
logMessage.Level = "ERROR"; | ||
logMessage.Logger = "CBComSelCouponController"; | ||
logMessage.Message = jsonParam; | ||
logMessage.Exception = ex.ToString(); | ||
Logging.RunLog(logMessage); | ||
|
||
throw; | ||
} | ||
} | ||
|
||
} | ||
} |