Ejemplo n.º 1
0
        public AvailabilityDefinition CheckAvailability(AvailabilityDefinition definition) //işlemin saat,periyod,tatil gibi uygunlukların kontrolü
        {
            definition.AvailabilityStatus = AvailabilityStatusType.NotCalculated;
            if (definition != null)
            {
                var startFinish = AvailabilityTimeFrame(definition.Start, definition.Finish);

                if (DateTime.Now >= startFinish["start"] && DateTime.Now <= startFinish["finish"])
                {
                    if (definition.Exceptions != null)
                    {
                        foreach (var exception in definition.Exceptions)
                        {
                            var exStartDateCron = exception.Start.Split('?')[0].Trim();
                            var exStartDateYear = int.Parse(exception.Start.Split('?')[1].Trim());
                            if (exStartDateYear > DateTime.Now.Year)
                            {
                                continue;
                            }

                            var exFinishDateCron = exception.Finish.Split('?')[0].Trim();
                            var exFinishDateYear = int.Parse(exception.Finish.Split('?')[1].Trim());

                            CheckCrons(new List <string>()
                            {
                                exStartDateCron, exFinishDateCron
                            });

                            var exStartDate  = CrontabSchedule.Parse(exStartDateCron).GetNextOccurrence(new DateTime(exStartDateYear, 1, 1));
                            var exFinishDate = CrontabSchedule.Parse(exFinishDateCron).GetNextOccurrence(new DateTime(exFinishDateYear, 1, 1));

                            if (DateTime.Now >= exStartDate && DateTime.Now <= exFinishDate)
                            {
                                definition.AvailabilityStatus = AvailabilityStatusType.Exception;
                                definition.Exceptions[0]      = exception;
                                break;
                            }
                            else
                            {
                                definition.AvailabilityStatus = AvailabilityStatusType.Available;
                            }
                        }
                    }
                    else
                    {
                        definition.AvailabilityStatus = AvailabilityStatusType.Available;
                    }
                }
                else
                {
                    definition.AvailabilityStatus = AvailabilityStatusType.NotInRange;
                }
            }
            return(definition);
        }
Ejemplo n.º 2
0
 public void InsertDefinition(string path, string currencyCode, decimal?transactionMinAmount, decimal?transactionMaxAmount, decimal?amountLimit, decimal?timerLimit, string duration, RenewalType?renewalType, AvailabilityDefinition availability, decimal?amountRemainingLimit, decimal amountUtilizedLimit, int timerRemainingLimit, decimal?maxAmountLimit, string maxAmountLimitCurrencyCode, decimal?defaultAmountLimit, int?defaultTimerLimit, int?maxTimerLimit, bool?isActive, string alsoLook)
 {
     using (var connection = new SqlConnection(_configuration.GetConnectionString("DefaultConnection")))
     {
         using (SqlCommand command = new SqlCommand("insert-update-limit-definition"))
         {
             command.CommandType = System.Data.CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@amountRemainingLimit", amountRemainingLimit);
             command.Parameters.AddWithValue("@path", path);
             command.Parameters.AddWithValue("@amountLimit", amountLimit);
             command.Parameters.AddWithValue("@timerLimit", timerLimit);
             command.Parameters.AddWithValue("@duration", duration);
             command.Parameters.AddWithValue("@isActive", isActive);
             command.Parameters.AddWithValue("@renewal", renewalType);
             command.Parameters.AddWithValue("@transactionMin", transactionMinAmount);
             command.Parameters.AddWithValue("@transactionMax", transactionMaxAmount);
             command.Parameters.AddWithValue("@currencyCode", currencyCode);
             command.Parameters.AddWithValue("@renewedAt", DateTime.Now);
             command.Parameters.AddWithValue("@createdAt", DateTime.Now);
             command.Parameters.AddWithValue("@availability", JsonConvert.SerializeObject(availability));
             command.Parameters.AddWithValue("@amountUtilizedLimit", amountUtilizedLimit);
             command.Parameters.AddWithValue("@timerRemainingLimit", timerRemainingLimit);
             command.Parameters.AddWithValue("@maxAmountLimit", maxAmountLimit);
             command.Parameters.AddWithValue("@maxAmountLimitCurrencyCode", maxAmountLimitCurrencyCode);
             command.Parameters.AddWithValue("@maxTimerLimit", maxTimerLimit);
             command.Parameters.AddWithValue("@defaultTimerLimit", defaultTimerLimit);
             command.Parameters.AddWithValue("@defaultAmountLimit", defaultAmountLimit);
             command.Parameters.AddWithValue("@alsoLook", alsoLook);
             command.Connection = connection;
             connection.Open();
             command.ExecuteNonQuery();
             connection.Close();
         }
     }
 }