public bool FromDataTable(DataTable table) { try { foreach (DataRow row in table.Rows) { var item = new AdHistoryData(); item.FromDBTable(row); Items.Add(item); } return(true); } catch { return(false); } }
public async Task <IActionResult> AdResource([FromQuery, Required] PageAdModels.AdResource.Request request) { try { if (request == null || request.IsValidParameters() == false) { return(NotFound()); } AdInfo ai = request.CreateFromAi(); AdHistoryData ahd = new AdHistoryData(); if (await ahd.FromDBAsync(ai.AdHistoryData.AdHistoryId) == false) { return(NotFound()); } if (ahd.IsDisplayed) { return(Redirect(ai.AdResourceData.Url)); } var updateDisplayQuery = new DBQuery_AdHistory_Update_Display(); updateDisplayQuery.IN.AdHistoryId = ai.AdHistoryData.AdHistoryId; updateDisplayQuery.IN.IsDisplayed = true; if (await DBThread.Instance.ReqQueryAsync(updateDisplayQuery)) { // 수익 지급 if (ai.AdHistoryData.CampaignType == CampaignTypes.CPM) { // 각 뷰당 1/1000로 계산 var cost = ahd.Cost * 0.001m; await ProvideRevenueToDBAsync(ahd.AdHistoryId, ahd.PublisherId, ahd.CustomerId, cost * 0.6m, cost * 0.4m); await PaymentCostToDBAsync(ahd.AdvertiserId, cost); } } return(Redirect(ai.AdResourceData.Url)); } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex); return(NotFound()); } }
public async Task <IActionResult> AdClick([FromQuery] PageAdModels.AdClick.Request request) { try { if (request == null || request.IsValidParameters() == false) { return(APIResponse(ErrorCode.InvalidParameters)); } AdInfo ai = request.CreateFromAi(); AdHistoryData ahd = new AdHistoryData(); if (await ahd.FromDBAsync(ai.AdHistoryData.AdHistoryId) == false) { return(Redirect(ai.AdDesignData.GetDestinationUrl())); } if (ahd.IsClicked) { return(Redirect(ai.AdDesignData.GetDestinationUrl())); } var updateClickQuery = new DBQuery_AdHistory_Update_Click(); updateClickQuery.IN.AdHistoryId = ai.AdHistoryData.AdHistoryId; updateClickQuery.IN.IsClicked = true; if (await DBThread.Instance.ReqQueryAsync(updateClickQuery)) { // 수익 지급 if (ai.AdHistoryData.CampaignType == CampaignTypes.CPC) { await ProvideRevenueToDBAsync(ahd.AdHistoryId, ahd.PublisherId, ahd.CustomerId, ahd.Cost * 0.6m, ahd.Cost * 0.4m); await PaymentCostToDBAsync(ahd.AdvertiserId, ahd.Cost); } } return(Redirect(ai.AdDesignData.GetDestinationUrl())); } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex); return(View("")); } }