コード例 #1
0
ファイル: EventApiHelper.cs プロジェクト: rickeygalloway/Test
        private static void UpdateExistingCode(ObjectContext context, DiscountCode existingCode, DiscountCodeDtoV2 updatedCode)
        {
            int discountTypeId = LookupDiscountType(context, updatedCode.DiscountType);

            existingCode.Description = string.IsNullOrWhiteSpace(updatedCode.Description) ? existingCode.Description : updatedCode.Description;
            existingCode.DiscountTypeId = discountTypeId;
            existingCode.DiscountValue = Convert.ToDecimal(updatedCode.DiscountValue, CultureInfo.InvariantCulture);
            existingCode.StartDate = string.IsNullOrEmpty(updatedCode.StartDate) ? existingCode.StartDate : DateTime.Parse(updatedCode.StartDate, CultureInfo.InvariantCulture);
            existingCode.EndDate = string.IsNullOrEmpty(updatedCode.StartDate) ? existingCode.EndDate : DateTime.Parse(updatedCode.EndDate, CultureInfo.InvariantCulture);
            existingCode.IsEnabled = string.IsNullOrWhiteSpace(updatedCode.IsEnabled) ? existingCode.IsEnabled : bool.Parse(updatedCode.IsEnabled);
            existingCode.IsGroupCode = string.IsNullOrWhiteSpace(updatedCode.IsGroupCode) ? existingCode.IsGroupCode : bool.Parse(updatedCode.IsGroupCode);
            existingCode.RequiredGroupSize = string.IsNullOrWhiteSpace(updatedCode.RequiredGroupSize) ? existingCode.RequiredGroupSize : int.Parse(updatedCode.RequiredGroupSize, CultureInfo.InvariantCulture);
        }
コード例 #2
0
ファイル: EventApiHelper.cs プロジェクト: rickeygalloway/Test
 private static DiscountCode FindEventDiscountCode(ObjectContext context, DiscountCodeDtoV2 code)
 {
     var discountCode = context.CreateObjectSet<DiscountCode>()
         .Where(e => e.Code.ToUpper() == code.Code.ToUpper())
         .Where(e => e.IsFromOrgUnit == false)
         .FirstOrDefault();
     if (discountCode != null)
         return discountCode;
     else
         return null;
 }
コード例 #3
0
ファイル: EventApiHelper.cs プロジェクト: rickeygalloway/Test
        private static DiscountCode FindOrgUnitDiscountCode(ObjectContext context, Event theEvent, DiscountCodeDtoV2 discount)
        {
            var discountCode = context.CreateObjectSet<OrgUnitDiscountCode>()
                .Where(o => o.DiscountCode.Code.ToUpper() == discount.Code.ToUpper())
                .SingleOrDefault();

            if (discountCode != null)
            {
                if (discountCode.OrgUnitId != theEvent.OrgUnitId.Value)
                    throw new BusinessException("Discount code is associated with an org unit different from the event org unit.");

                return discountCode.DiscountCode;
            }
            else
                return null;
        }
コード例 #4
0
ファイル: EventApiHelper.cs プロジェクト: rickeygalloway/Test
        private static DiscountCode CreateEventDiscountCode(ObjectContext context, DiscountCodeDtoV2 code)
        {
            int discountTypeId = LookupDiscountType(context, code.DiscountType);

            var discountCode = new DiscountCode
            {
                Code = code.Code,
                Description = code.Description,
                DiscountTypeId = discountTypeId,
                DiscountValue = Convert.ToDecimal(code.DiscountValue, CultureInfo.InvariantCulture),
                StartDate = string.IsNullOrEmpty(code.StartDate) ? new DateTime?() : DateTime.Parse(code.StartDate, CultureInfo.InvariantCulture),
                EndDate = string.IsNullOrEmpty(code.StartDate) ? new DateTime?() : DateTime.Parse(code.EndDate, CultureInfo.InvariantCulture),
                IsEnabled = bool.Parse(code.IsEnabled),
                IsGroupCode = bool.Parse(code.IsGroupCode),
                IsFromOrgUnit = false,
                RequiredGroupSize = int.Parse(code.RequiredGroupSize, CultureInfo.InvariantCulture),
            };

            context.AddObject("DiscountCodes", discountCode);

            return discountCode;
        }