private static List <ScheduledUsersBL> BuildFromTable(DataTable dtTable) { List <ScheduledUsersBL> list = new List <ScheduledUsersBL>(); if (dtTable != null) { foreach (DataRow dr in dtTable.Rows) { ScheduledUsersBL thisMember = new ScheduledUsersBL(dr); list.Add(thisMember); } } return(list); }
/// <summary> /// Method to add reoccuring and scheuduled campaign for delivered vehicle status /// </summary> /// <param name="iShopId">Shop Id</param> /// <param name="iUserId">User Id</param> /// <param name="dtDeliveryDate">Delivery Date</param> private void CreateReoccuringScheduledUser() { if (isRunning) { //MessageLogs.WriteLog("Service is still processing old thread."); return; } try { if (DateTime.Now.Hour >= startTime.Hour || DateTime.Now.Hour < endTime.Hour) { isRunning = true; List <AIManageRecurringActivityBL> lstAIManageRecurringActivityBL = AIManageRecurringActivityBL.GetUnprocessedDataForAddingRecurringInfo(); if (lstAIManageRecurringActivityBL != null) { foreach (AIManageRecurringActivityBL objAIManageRecurringActivityBL in lstAIManageRecurringActivityBL) { Int32 iShopId = objAIManageRecurringActivityBL.iShopId; Int32 iUserId = objAIManageRecurringActivityBL.iUserId; DateTime dtDeliveryDate = objAIManageRecurringActivityBL.dtDeliveryDate; System.Collections.Generic.List <SummitShopApp.BL.FrequencyBL> lstFrequency = SummitShopApp.BL.FrequencyBL.getFrequencyList(); if (lstFrequency != null && lstFrequency.Count > 0) { //code to delete null entries from ReocurringCampaignUsers Table to remove duplicates SummitShopApp.BL.ReocurringCampaignUsersBL.deleteRecordsForNull(iUserId, iShopId); foreach (SummitShopApp.BL.FrequencyBL objFrequency in lstFrequency) { try { /* * Dev 1 : 16 Aug 2016 * Added code for connect api shop as we are fetching data on next day * eg: customer added data on 12th aug and we are fetchechin them at 13th. * to resolve the issue of one day delivered * */ Boolean isAddRecords = false; ConnectAPIBL objConnectApi = ConnectAPIBL.getDataByShopId(iShopId); if (objConnectApi != null) { isAddRecords = objFrequency.iDays >= DateTime.Now.Subtract(dtDeliveryDate).Days; } else { isAddRecords = objFrequency.iDays > DateTime.Now.Subtract(dtDeliveryDate).Days; } //schedule only if days are not elasped if (isAddRecords) { SummitShopApp.BL.ReocurringCampaignUsersBL ReoccuringUser = null; ReoccuringUser = SummitShopApp.BL.ReocurringCampaignUsersBL.getDataByShopIdUserIdAndFreqId(iShopId, iUserId, objFrequency.iID); if (ReoccuringUser == null) { ReoccuringUser = new SummitShopApp.BL.ReocurringCampaignUsersBL(); } ReoccuringUser.bIsMailSent = true; ReoccuringUser.bIsSmsSent = true; ReoccuringUser.dtDeliveredDate = dtDeliveryDate; ReoccuringUser.iUserID = iUserId; ReoccuringUser.iShopID = iShopId; ReoccuringUser.iFrequencyID = objFrequency.iID; if (ReoccuringUser.Save()) { //save the schedule user SummitShopApp.BL.ScheduledUsersBL objScheduleUser = SummitShopApp.BL.ScheduledUsersBL.getDataByUserIdShopIdAndFrequencyId(ReoccuringUser.iUserID.Value, ReoccuringUser.iShopID.Value, objFrequency.iID); if (objScheduleUser == null) { objScheduleUser = new SummitShopApp.BL.ScheduledUsersBL(); } objScheduleUser.iUserId = ReoccuringUser.iUserID.Value; objScheduleUser.iShopId = ReoccuringUser.iShopID.Value; objScheduleUser.iFrequency = objFrequency.iID; objScheduleUser.dtSendDate = dtDeliveryDate.AddDays(objFrequency.iDays); objScheduleUser.bIsMailSent = true; objScheduleUser.bIsSmsSent = true; objScheduleUser.Save(); } } } catch (Exception ex) { //Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex, SummitShopApp.Utility.Constants.ExceptionPolicy); } } } //Update AIManageRecurringActivity table objAIManageRecurringActivityBL.IsProcessed = true; objAIManageRecurringActivityBL.dtProcessedDate = DateTime.Now; objAIManageRecurringActivityBL.Save(); } } } } catch (Exception ex) { } finally { isRunning = false; } }