Skip to content

Commit 99f79da

Browse files
committed
DTO added
Added BannerDetail data transfer object
1 parent edb4ba3 commit 99f79da

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

BannerFlow/BannerFlow.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
<DependentUpon>Global.asax</DependentUpon>
208208
</Compile>
209209
<Compile Include="Models\Banner.cs" />
210+
<Compile Include="Models\BannerDetailDTO.cs" />
210211
<Compile Include="Models\BannerDTO.cs" />
211212
<Compile Include="Properties\AssemblyInfo.cs" />
212213
<Compile Include="Repositories\BannerRepository.cs" />

BannerFlow/Controllers/BannerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public BannerController()
2121
}
2222

2323
// GET api/Banner
24-
public IEnumerable<Banner> Get()
24+
public IEnumerable<BannerDetailDTO> Get()
2525
{
2626
return bannerService.GetAll();
2727
}
2828

2929
// GET api/Banners/int
30-
public Banner Get(int id)
30+
public BannerDetailDTO Get(int id)
3131
{
3232
var banner = bannerService.Get(id);
3333
if (banner == null)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace BannerFlow.Models
7+
{
8+
public class BannerDetailDTO
9+
{
10+
public int Id { get; set; }
11+
public string Html { get; set; }
12+
public DateTime Created { get; set; }
13+
public DateTime? Modified { get; set; }
14+
15+
public BannerDetailDTO(Banner banner)
16+
{
17+
this.Id = banner.Id;
18+
this.Html = banner.Html;
19+
this.Created = banner.Created;
20+
this.Modified = banner.Modified;
21+
}
22+
}
23+
}

BannerFlow/Services/BannerService.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,24 @@ public Banner Add(BannerDTO data)
3636
}
3737

3838
// Return all entries logic
39-
public IEnumerable<Banner> GetAll()
39+
public IEnumerable<BannerDetailDTO> GetAll()
4040
{
41-
return repository.GetAll();
41+
List<BannerDetailDTO> value = new List<BannerDetailDTO>();
42+
IEnumerable<Banner> banners = repository.GetAll();
43+
44+
foreach(Banner x in banners)
45+
{
46+
value.Add(new BannerDetailDTO(x));
47+
}
48+
return value;
4249
}
4350

4451
// Return requested entry logic
45-
public Banner Get(int id)
52+
public BannerDetailDTO Get(int id)
4653
{
47-
return repository.Get(id);
54+
BannerDetailDTO value = new BannerDetailDTO(repository.Get(id));
55+
56+
return value;
4857
}
4958

5059

0 commit comments

Comments
 (0)