Exemplo n.º 1
0
 public override void Validate()
 {
     FormId.ThrowIfEmpty(nameof(FormId));
     Name.ThrowIfNullOrWhiteSpace(nameof(Name));
     SortOrder.ThrowIfOutOfRange(nameof(SortOrder), 0);
     CreatorId.ThrowIfNullOrWhiteSpace(nameof(CreatorId));
 }
 /// <summary>Serves as the default hash function.</summary>
 /// <returns>A hash code for the current object.</returns>
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = Id.GetHashCode();
         hashCode = (hashCode * 397) ^ CreatorId.GetHashCode();
         hashCode = (hashCode * 397) ^ Name.GetHashCode();
         hashCode = (hashCode * 397) ^ Description.GetHashCode();
         hashCode = (hashCode * 397) ^ Participants.GetHashCode();
         hashCode = (hashCode * 397) ^ BannedUsers.GetHashCode();
         return(hashCode);
     }
 }
Exemplo n.º 3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is V1Payment other &&
                   ((Context == null && other.Context == null) || (Context?.Equals(other.Context) == true)) &&
                   ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) &&
                   ((MerchantId == null && other.MerchantId == null) || (MerchantId?.Equals(other.MerchantId) == true)) &&
                   ((CreatedAt == null && other.CreatedAt == null) || (CreatedAt?.Equals(other.CreatedAt) == true)) &&
                   ((CreatorId == null && other.CreatorId == null) || (CreatorId?.Equals(other.CreatorId) == true)) &&
                   ((Device == null && other.Device == null) || (Device?.Equals(other.Device) == true)) &&
                   ((PaymentUrl == null && other.PaymentUrl == null) || (PaymentUrl?.Equals(other.PaymentUrl) == true)) &&
                   ((ReceiptUrl == null && other.ReceiptUrl == null) || (ReceiptUrl?.Equals(other.ReceiptUrl) == true)) &&
                   ((InclusiveTaxMoney == null && other.InclusiveTaxMoney == null) || (InclusiveTaxMoney?.Equals(other.InclusiveTaxMoney) == true)) &&
                   ((AdditiveTaxMoney == null && other.AdditiveTaxMoney == null) || (AdditiveTaxMoney?.Equals(other.AdditiveTaxMoney) == true)) &&
                   ((TaxMoney == null && other.TaxMoney == null) || (TaxMoney?.Equals(other.TaxMoney) == true)) &&
                   ((TipMoney == null && other.TipMoney == null) || (TipMoney?.Equals(other.TipMoney) == true)) &&
                   ((DiscountMoney == null && other.DiscountMoney == null) || (DiscountMoney?.Equals(other.DiscountMoney) == true)) &&
                   ((TotalCollectedMoney == null && other.TotalCollectedMoney == null) || (TotalCollectedMoney?.Equals(other.TotalCollectedMoney) == true)) &&
                   ((ProcessingFeeMoney == null && other.ProcessingFeeMoney == null) || (ProcessingFeeMoney?.Equals(other.ProcessingFeeMoney) == true)) &&
                   ((NetTotalMoney == null && other.NetTotalMoney == null) || (NetTotalMoney?.Equals(other.NetTotalMoney) == true)) &&
                   ((RefundedMoney == null && other.RefundedMoney == null) || (RefundedMoney?.Equals(other.RefundedMoney) == true)) &&
                   ((SwedishRoundingMoney == null && other.SwedishRoundingMoney == null) || (SwedishRoundingMoney?.Equals(other.SwedishRoundingMoney) == true)) &&
                   ((GrossSalesMoney == null && other.GrossSalesMoney == null) || (GrossSalesMoney?.Equals(other.GrossSalesMoney) == true)) &&
                   ((NetSalesMoney == null && other.NetSalesMoney == null) || (NetSalesMoney?.Equals(other.NetSalesMoney) == true)) &&
                   ((InclusiveTax == null && other.InclusiveTax == null) || (InclusiveTax?.Equals(other.InclusiveTax) == true)) &&
                   ((AdditiveTax == null && other.AdditiveTax == null) || (AdditiveTax?.Equals(other.AdditiveTax) == true)) &&
                   ((Tender == null && other.Tender == null) || (Tender?.Equals(other.Tender) == true)) &&
                   ((Refunds == null && other.Refunds == null) || (Refunds?.Equals(other.Refunds) == true)) &&
                   ((Itemizations == null && other.Itemizations == null) || (Itemizations?.Equals(other.Itemizations) == true)) &&
                   ((SurchargeMoney == null && other.SurchargeMoney == null) || (SurchargeMoney?.Equals(other.SurchargeMoney) == true)) &&
                   ((Surcharges == null && other.Surcharges == null) || (Surcharges?.Equals(other.Surcharges) == true)) &&
                   ((IsPartial == null && other.IsPartial == null) || (IsPartial?.Equals(other.IsPartial) == true)));
        }
        public void SetNextRun(bool isServiceCall = false)
        {
            DateTime     dateOnly  = StartDateUtc.Date;
            DateTime     timeOnly  = default(DateTime).Add(StartDateUtc.TimeOfDay);
            DayOfWeek    dayOfWeek = DayOfWeek.Sunday;
            int          dayDiff   = 0;
            User         creator   = Users.GetUser(LoginUser.Anonymous, CreatorId);
            TimeZoneInfo tz        = TimeZoneInfo.Local;

            if (!string.IsNullOrWhiteSpace(creator.TimeZoneID))
            {
                tz = TimeZoneInfo.FindSystemTimeZoneById(creator.TimeZoneID);
                Debug(string.Format("CreatorId: {0} TimeZoneID: {1} tz.DisplayName: {2}", CreatorId.ToString(), creator.TimeZoneID.ToString(), tz.DisplayName));
            }

            DateTime StartDateToCreatorTimeZone = TimeZoneInfo.ConvertTimeFromUtc(StartDateUtc, tz);
            DateTime nextRunToCreatorTimeZone   = NextRunUtc != null?TimeZoneInfo.ConvertTimeFromUtc(NextRunUtc.Value, tz) : TimeZoneInfo.ConvertTimeFromUtc(StartDateUtc, tz);

            // The initialDayDiff should not be calculated against our local time but the user's local time.
            int initialDayDiff = StartDateUtc.DayOfWeek - StartDateToCreatorTimeZone.DayOfWeek;

            if (LastRunUtc != null)
            {
                DateTime lastRunToCreatorTimeZone = TimeZoneInfo.ConvertTimeFromUtc(LastRunUtc.Value, tz);
                dateOnly       = StartDateUtc > LastRunUtc ? StartDateUtc.Date : ((DateTime)LastRunUtc).Date;
                initialDayDiff = ((DateTime)LastRunUtc).DayOfWeek - lastRunToCreatorTimeZone.DayOfWeek;

                //Difference in day (due to the UTC) between Sund-Sat or Sat-Sun will be handled here because the substraction will return 6 or -6, we only need to know if it's 1 or -1 (day ahead or day behind)
                if (initialDayDiff == -6) //Sun (0) back to Sat (6)
                {
                    initialDayDiff = 1;
                }
                else if (initialDayDiff == 6) //Sat (6) onto Sun (0)
                {
                    initialDayDiff = -1;
                }
            }

            switch ((ScheduledReportFrequency)RecurrencyId)
            {
            case ScheduledReportFrequency.Once:
                NextRun = StartDateUtc;
                break;

            case ScheduledReportFrequency.Weekly:
                //we need: startdate, every, weekday (1:Sun, ..., 7:Sat)
                //The list in the UI is: 1: Sunday, ..., 7: Saturday. So we need to substract 1 to convert it to DayOfWeek
                dayOfWeek = (DayOfWeek)(byte)Weekday - 1;

                if (dateOnly.Add(timeOnly.TimeOfDay) > DateTime.UtcNow)
                {
                    while (dateOnly.DayOfWeek != dayOfWeek)
                    {
                        dateOnly = dateOnly.AddDays(1);
                    }
                }
                else
                {
                    int totalDaysInAWeek = 7;
                    int totalDays        = (byte)Every * totalDaysInAWeek;

                    while (dateOnly < DateTime.UtcNow)
                    {
                        dateOnly = dateOnly.AddDays(totalDays);

                        if (dateOnly.DayOfWeek != dayOfWeek)
                        {
                            dateOnly = dateOnly.AddDays(-totalDaysInAWeek);
                            dateOnly = dateOnly.AddDays(dayOfWeek - dateOnly.DayOfWeek);
                        }
                    }
                }

                NextRun = dateOnly.Add(timeOnly.TimeOfDay).AddDays(initialDayDiff);
                nextRunToCreatorTimeZone = TimeZoneInfo.ConvertTimeFromUtc(NextRunUtc.Value, tz);

                // The day of the week check must be done on the creator timezone as well.
                if (nextRunToCreatorTimeZone.DayOfWeek != dayOfWeek)
                {
                    dayDiff = dayOfWeek - nextRunToCreatorTimeZone.DayOfWeek;
                    NextRun = dateOnly.AddDays(dayDiff).Add(timeOnly.TimeOfDay);
                }

                break;

            case ScheduledReportFrequency.Monthly:
                //we need: startdate, every, weekday (1:Sun, ..., 7:Sat),
                //				monthday (if < 5 then weekday can have a value: the 1st monday.. the 3rd wednesday, etc;
                //						else weekday has to be null: the 5th of the month, the 20th of the month, etc)

                DateTime startOfTheMonth = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1);

                while (dateOnly < DateTime.UtcNow)
                {
                    if (Monthday < 5 && Weekday != null && Weekday > 0)
                    {
                        int totalDaysInAWeek = 7;
                        dayOfWeek       = (DayOfWeek)(byte)Weekday - 1;
                        startOfTheMonth = new DateTime(dateOnly.Year, dateOnly.Month, 1);
                        startOfTheMonth = startOfTheMonth.AddMonths((byte)Every);

                        // set the first ocurrence of the monthday
                        int diff = dayOfWeek - startOfTheMonth.DayOfWeek;

                        if (diff < 0)
                        {
                            startOfTheMonth = startOfTheMonth.AddDays(totalDaysInAWeek + diff);
                            diff            = 0;
                        }

                        dateOnly = startOfTheMonth.AddDays(diff + (((byte)Monthday - 1) * totalDaysInAWeek));
                    }
                    else
                    {
                        Weekday = null;

                        if (startOfTheMonth.AddDays((byte)Monthday - 1).Add(timeOnly.TimeOfDay) < new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 0, 0, 0).Add(timeOnly.TimeOfDay) || isServiceCall)
                        {
                            dateOnly = startOfTheMonth.AddMonths((byte)Every);
                        }
                        else
                        {
                            dateOnly = startOfTheMonth;
                        }

                        int monthTemp = dateOnly.Month;
                        dateOnly = dateOnly.AddDays((byte)Monthday - 1);     //Calculation starts on first of the month, so substract it.

                        if (dateOnly.Month > monthTemp)
                        {
                            dateOnly = dateOnly.AddDays(-dateOnly.Day);
                        }
                    }
                }

                Debug("Exited while. Monthly Next Run calculation. DateOnly: " + dateOnly.ToString());

                NextRun = dateOnly.Add(timeOnly.TimeOfDay);

                if (Monthday < 5 && Weekday != null && Weekday > 0 && NextRun.Value.DayOfWeek != dayOfWeek)
                {
                    dayDiff = dayOfWeek - NextRun.Value.DayOfWeek;
                    NextRun = dateOnly.AddDays(dayDiff).Add(timeOnly.TimeOfDay);
                }

                dayDiff = (int)(dateOnly.Date - NextRun.Value.Date).TotalDays;

                if (dayDiff != 0)
                {
                    NextRun = dateOnly.AddDays(dayDiff).Add(timeOnly.TimeOfDay);
                }

                if (NextRunUtc.Value.DayOfYear < NextRun.Value.DayOfYear)
                {
                    NextRun = NextRun.Value.AddDays(1);
                }

                break;

            case ScheduledReportFrequency.Daily:
                DateTime now = DateTime.UtcNow;
                Debug(string.Format("now : {0}", now.ToString("MM/dd/yyyy HH:mm")));

                if (dateOnly.Add(timeOnly.TimeOfDay) < now)
                {
                    dateOnly = now.Date;
                    Debug("dateOnly = now.Date : " + dateOnly.ToString("MM/dd/yyyy HH:mm"));
                }

                if (dateOnly.Add(timeOnly.TimeOfDay) < now || isServiceCall)
                {
                    NextRun = dateOnly.AddDays(1).Add(timeOnly.TimeOfDay);
                    Debug(string.Format("NextRun = dateOnly.AddDays(1).Add(timeOnly.TimeOfDay) : {0}", NextRun.Value.ToString("MM/dd/yyyy HH:mm")));
                }
                else
                {
                    NextRun = dateOnly.Add(timeOnly.TimeOfDay);
                    Debug(string.Format("NextRun = dateOnly.Add(timeOnly.TimeOfDay) : ", NextRun.Value.ToString("MM/dd/yyyy HH:mm")));
                }

                break;

            default:
                break;
            }

            //Check for DLS and update if needed
            if (NextRun.HasValue)
            {
                nextRunToCreatorTimeZone = TimeZoneInfo.ConvertTimeFromUtc(NextRunUtc.Value, tz);
                Debug(string.Format("StartDateToCreatorTimeZone = TimeZoneInfo.ConvertTimeFromUtc(StartDateUtc, tz): {0}", StartDateToCreatorTimeZone.ToString("MM/dd/yyyy HH:mm")));
                Debug(string.Format("nextRunToCreatorTimeZone = TimeZoneInfo.ConvertTimeFromUtc(NextRunUtc.Value, tz): {0}", nextRunToCreatorTimeZone.ToString("MM/dd/yyyy HH:mm")));

                if (TimeSpan.Compare(StartDateToCreatorTimeZone.TimeOfDay, nextRunToCreatorTimeZone.TimeOfDay) != 0)
                {
                    DateTime fixedDateForDLS = TimeZoneInfo.ConvertTimeToUtc(new DateTime(NextRun.Value.Year, NextRun.Value.Month, NextRun.Value.Day, StartDateToCreatorTimeZone.Hour, StartDateToCreatorTimeZone.Minute, 0), tz);
                    Debug(string.Format("fixedDateForDLS = TimeZoneInfo.ConvertTimeToUtc(new DateTime(NextRun.Value.Year, NextRun.Value.Month, NextRun.Value.Day, StartDateToCreatorTimeZone.Hour, StartDateToCreatorTimeZone.Minute, 0), tz): {0}", fixedDateForDLS.ToString("MM/dd/yyyy HH:mm")));

                    //Last check to see if after converting to the right time zone and fixing for DLS the datetime is not ealier than the converted nextrun, if so add 1 day.
                    if (DateTime.Compare(fixedDateForDLS, nextRunToCreatorTimeZone) < 0)
                    {
                        fixedDateForDLS = fixedDateForDLS.AddDays(1);
                    }

                    NextRun = fixedDateForDLS;
                    Debug(string.Format("NextRun: {0}", NextRun.Value.ToString("MM/dd/yyyy HH:mm")));
                }
            }
        }
Exemplo n.º 5
0
 public override int GetHashCode()
 {
     return((CreatorId.GetHashCode() * 17 + OwnerId.GetHashCode()) * 17 + Key.ToLower().GetHashCode());
 }
Exemplo n.º 6
0
 public bool CanDeletePasta(ulong userId)
 {
     return(userId == CreatorId.FromDbLong() ||
            Bot.instance.Events.Developers.Contains(userId));
 }
Exemplo n.º 7
0
 public bool CanDeletePasta(ulong userId)
 {
     return(userId == CreatorId.FromDbLong() ||
            EventSystem.Instance.DeveloperIds.Contains(userId));
 }
Exemplo n.º 8
0
        public override int GetHashCode()
        {
            int hashCode = -215174345;

            if (Context != null)
            {
                hashCode += Context.GetHashCode();
            }

            if (Id != null)
            {
                hashCode += Id.GetHashCode();
            }

            if (MerchantId != null)
            {
                hashCode += MerchantId.GetHashCode();
            }

            if (CreatedAt != null)
            {
                hashCode += CreatedAt.GetHashCode();
            }

            if (CreatorId != null)
            {
                hashCode += CreatorId.GetHashCode();
            }

            if (Device != null)
            {
                hashCode += Device.GetHashCode();
            }

            if (PaymentUrl != null)
            {
                hashCode += PaymentUrl.GetHashCode();
            }

            if (ReceiptUrl != null)
            {
                hashCode += ReceiptUrl.GetHashCode();
            }

            if (InclusiveTaxMoney != null)
            {
                hashCode += InclusiveTaxMoney.GetHashCode();
            }

            if (AdditiveTaxMoney != null)
            {
                hashCode += AdditiveTaxMoney.GetHashCode();
            }

            if (TaxMoney != null)
            {
                hashCode += TaxMoney.GetHashCode();
            }

            if (TipMoney != null)
            {
                hashCode += TipMoney.GetHashCode();
            }

            if (DiscountMoney != null)
            {
                hashCode += DiscountMoney.GetHashCode();
            }

            if (TotalCollectedMoney != null)
            {
                hashCode += TotalCollectedMoney.GetHashCode();
            }

            if (ProcessingFeeMoney != null)
            {
                hashCode += ProcessingFeeMoney.GetHashCode();
            }

            if (NetTotalMoney != null)
            {
                hashCode += NetTotalMoney.GetHashCode();
            }

            if (RefundedMoney != null)
            {
                hashCode += RefundedMoney.GetHashCode();
            }

            if (SwedishRoundingMoney != null)
            {
                hashCode += SwedishRoundingMoney.GetHashCode();
            }

            if (GrossSalesMoney != null)
            {
                hashCode += GrossSalesMoney.GetHashCode();
            }

            if (NetSalesMoney != null)
            {
                hashCode += NetSalesMoney.GetHashCode();
            }

            if (InclusiveTax != null)
            {
                hashCode += InclusiveTax.GetHashCode();
            }

            if (AdditiveTax != null)
            {
                hashCode += AdditiveTax.GetHashCode();
            }

            if (Tender != null)
            {
                hashCode += Tender.GetHashCode();
            }

            if (Refunds != null)
            {
                hashCode += Refunds.GetHashCode();
            }

            if (Itemizations != null)
            {
                hashCode += Itemizations.GetHashCode();
            }

            if (SurchargeMoney != null)
            {
                hashCode += SurchargeMoney.GetHashCode();
            }

            if (Surcharges != null)
            {
                hashCode += Surcharges.GetHashCode();
            }

            if (IsPartial != null)
            {
                hashCode += IsPartial.GetHashCode();
            }

            return(hashCode);
        }
Exemplo n.º 9
0
 public override void Validate()
 {
     FormId.ThrowIfEmpty(nameof(FormId));
     HtmlTemplateId.ThrowIfEmpty(nameof(HtmlTemplateId));
     CreatorId.ThrowIfNullOrWhiteSpace(nameof(CreatorId));
 }