public App.Support.Common.Models.PromotionService.DiscountCampaigns.DiscountCampaign GenerateDiscountCampaignFromViewModel(DiscountCampaignRequestViewModel viewModel)
        {
            var discountCampaign =
                new App.Support.Common.Models.PromotionService.DiscountCampaigns.DiscountCampaign
            {
                Id   = Guid.NewGuid(),
                Name = viewModel.Name,
                DiscountCampaignType    = viewModel.DiscountCampaignType,
                DiscountValue           = viewModel.DiscountValue,
                DiscountUnitId          = viewModel.DiscountUnitId,
                StartDate               = viewModel.StartDate,
                ExpirationDate          = viewModel.ExpirationDate,
                DiscountCampaignApplyOn = viewModel.DiscountCampaignApplyOn,
                ApplyOnId               = viewModel.DiscountCampaignApplyOnId,
                CodePrefix              = viewModel.CodePrefix
            };

            discountCampaign.DiscountValidations =
                new List <App.Support.Common.Models.PromotionService.DiscountValidations.DiscountValidation>();
            foreach (var discountValidation in viewModel.DiscountValidations.Select(viewModelDiscountValidation => _discountValidationService.GenerateDiscountValidationFromViewModel(viewModelDiscountValidation)))
            {
                discountCampaign.DiscountValidations.Add(discountValidation);
            }

            var discountCodes = _discountCodeService.GenerateDiscountCodesFromDiscountCampaignViewModel(viewModel);

            discountCampaign.DiscountCodes = discountCodes;

            return(discountCampaign);
        }
示例#2
0
        public static DiscountCampaign GenerateDiscountCampaignFromGrpcDto(DiscountCampaignDTO discountCampaignDto)
        {
            var discountCampaign = new DiscountCampaign
            {
                Id             = Guid.Parse(discountCampaignDto.Id),
                Name           = discountCampaignDto.Name,
                CodePrefix     = discountCampaignDto.CodePrefix,
                DiscountValue  = discountCampaignDto.DiscountValue.ToDecimal(),
                ExpirationDate = DateTimeOffset.Parse(discountCampaignDto.ExpirationDate),
                StartDate      = DateTimeOffset.Parse(discountCampaignDto.StartDate)
            };

            if (!discountCampaignDto.ApplyOnId.Equals(""))
            {
                discountCampaign.ApplyOnId = Guid.Parse(discountCampaignDto.ApplyOnId);
            }
            if (!discountCampaignDto.DiscountUnitId.Equals(""))
            {
                discountCampaign.DiscountUnitId = Guid.Parse(discountCampaignDto.DiscountUnitId);
            }

            discountCampaign.DiscountCampaignType =
                DiscountCampaignTypeEnum.Convert((int)discountCampaignDto.DiscountCampaignType);

            discountCampaign.DiscountCampaignApplyOn =
                DiscountCampaignApplyOnEnum.Convert((int)discountCampaignDto.DiscountCampaignApplyOn);
            return(discountCampaign);
        }