Пример #1
0
 private void DeleteCarryForwardRule(ICarryForwardBusinessConfiguration carryFwdConfig)
 {
     // If pending rule execution is successfull, the corresponding carry forward rule will be deleted from the carryforward table.
     using (LADAutomationEntities context = new LADAutomationEntities())
     {
         var record = context.CarryForwardRules.Where(e => e.Id.Equals(carryFwdConfig.Id)).FirstOrDefault();
         context.CarryForwardRules.Remove(record);
         context.SaveChanges();
     }
 }
Пример #2
0
 private void AddCarryForwardRule(IBusinessConfiguration businessConfiguration)
 {
     // If the rule execution is not successful, add record the carryforward table
     using (LADAutomationEntities context = new LADAutomationEntities())
     {
         var carryForward = new CarryForwardRule();
         carryForward.PendingSince = DateTime.Now;
         carryForward.Rule_Id      = businessConfiguration.RuleId;
         context.CarryForwardRules.Add(carryForward);
         context.SaveChanges();
     }
 }
 private BusinessConfiguration GetBusinessRule(int countryId, int dayOfTheMonth, bool isFromEnd)
 {
     CountryId = countryId;
     //connect to the database and fetch the list of Business rules greater than the nth day
     using (LADAutomationEntities context = new LADAutomationEntities())
     {
         var bc = (from businessConfig in context.Rules
                   join userCountryRole in context.UserCountryRoles on businessConfig.UserCountryRole_Id equals userCountryRole.Id
                   join owner in context.Users on userCountryRole.User_Id equals owner.Id
                   join userCountryRole1 in context.UserCountryRoles on businessConfig.UserCountryRole_Id equals userCountryRole1.Id
                   join recipient in context.Users on userCountryRole1.User_Id equals recipient.Id
                   join country in context.Countries on userCountryRole.Country_Id equals country.Id
                   where country.Id == countryId && businessConfig.BusinessDay == dayOfTheMonth
                   select new BusinessConfiguration()
         {
             RuleId = businessConfig.Id,
             Rule = businessConfig.Name,
             Owner = owner.Email,
             Recipient = recipient.Email
         }).FirstOrDefault();
     }
     return(this);
 }
Пример #4
0
        public void ExecuteCarryForwardTasks(int countryId)
        {
            List <CarryForwardBusinessConfiguration> carryForwardRules = new List <CarryForwardBusinessConfiguration>();

            //connect to the database and fetch the list of carry forward rules
            using (LADAutomationEntities context = new LADAutomationEntities())
            {
                carryForwardRules = (from carryRules in context.CarryForwardRules
                                     join rules in context.Rules on carryRules.Rule_Id equals rules.Id
                                     join owner1 in context.UserCountryRoles on rules.UserCountryRole_Id equals owner1.Id
                                     join recipient1 in context.UserCountryRoles on rules.UserCountryRole1_Id equals recipient1.Id
                                     join owner in context.Users on owner1.User_Id equals owner.Id
                                     join recipient in context.Users on recipient1.User_Id equals recipient.Id
                                     join country in context.Countries on owner1.Country_Id equals country.Id
                                     where country.Id == countryId
                                     select new CarryForwardBusinessConfiguration
                {
                    RuleId = rules.Id,
                    NthWorkingDayOfMonth = rules.BusinessDay,                  //Will be used while logging
                    PendingSince = carryRules.PendingSince                     //will be used while logging
                }).ToList();
            }
            BusinessConfiguration bc;

            System.Threading.Tasks.Parallel.ForEach <CarryForwardBusinessConfiguration>(carryForwardRules, (carryRule) => {
                bc = new BusinessConfiguration(countryId, carryRule.NthWorkingDayOfMonth, false);
                if (bc.ExecuteBusinessRule(bc))
                {
                    DeleteCarryForwardRule(carryRule);
                }
                else
                {
                    //logging
                }
            });
        }