Skip to content

Commit 3c81115

Browse files
committed
Edit mapper methods
1 parent ea8d893 commit 3c81115

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,32 @@ private CampaignDTO MapCampaignModelToDto(Campaign campaign)
125125
{
126126
var campaignDto = new CampaignDTO
127127
{
128+
Id = campaign.Id,
128129
Description = campaign.Description,
129130
From = campaign.From,
130131
To = campaign.To,
131132
Url = campaign.Url,
132133
};
133134

134-
campaign.Rules.ForEach(c =>
135+
campaign.Rules.ForEach(rule =>
135136
{
136-
switch (RuleType.From(c.RuleTypeId))
137+
var ruleDto = new RuleDTO
138+
{
139+
Id = rule.Id,
140+
RuleTypeId = rule.RuleTypeId,
141+
Description = rule.Description,
142+
CampaignId = rule.CampaignId
143+
};
144+
145+
switch (RuleType.From(rule.RuleTypeId))
137146
{
138147
case RuleTypeEnum.UserLocationRule:
139-
var userLocationRule = c as UserLocationRule;
140-
campaignDto.Rules.Add(new RuleDTO
141-
{
142-
LocationId = userLocationRule.LocationId,
143-
RuleTypeId = userLocationRule.RuleTypeId,
144-
Description = userLocationRule.Description
145-
});
148+
var userLocationRule = rule as UserLocationRule;
149+
ruleDto.LocationId = userLocationRule.LocationId;
146150
break;
147151
}
152+
153+
campaignDto.Rules.Add(ruleDto);
148154
});
149155

150156
return campaignDto;
@@ -154,22 +160,24 @@ private Campaign MapCampaignDtoToModel(CampaignDTO campaignDto)
154160
{
155161
var campaingModel = new Campaign
156162
{
163+
Id = campaignDto.Id,
157164
Description = campaignDto.Description,
158165
From = campaignDto.From,
159166
To = campaignDto.To,
160167
Url = campaignDto.Url
161168
};
162169

163-
campaignDto.Rules.ForEach(c =>
170+
campaignDto.Rules.ForEach(ruleDto =>
164171
{
165-
switch (RuleType.From(c.RuleTypeId))
172+
switch (RuleType.From(ruleDto.RuleTypeId))
166173
{
167174
case RuleTypeEnum.UserLocationRule:
168175
campaingModel.Rules.Add(new UserLocationRule
169176
{
170-
LocationId = c.LocationId.Value,
171-
RuleTypeId = c.RuleTypeId,
172-
Description = c.Description,
177+
Id = ruleDto.Id,
178+
LocationId = ruleDto.LocationId.Value,
179+
RuleTypeId = ruleDto.RuleTypeId,
180+
Description = ruleDto.Description,
173181
Campaign = campaingModel
174182
});
175183
break;

0 commit comments

Comments
 (0)