Skip to content

Commit

Permalink
Added order-representation mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonPobiega committed Mar 2, 2011
1 parent be8a917 commit b607083
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 23 deletions.
24 changes: 23 additions & 1 deletion src/Restbucks.Service/Domain/Order.cs
@@ -1,7 +1,29 @@
using System.Collections.Generic;

namespace Restbucks.Service.Domain
{
public class Order
{

protected virtual List<Item> ItemsCollection { get; set; }
public virtual IEnumerable<Item> Items
{
get { return ItemsCollection; }
}

public virtual Location Location { get; protected set; }

public virtual decimal Total { get; protected set; }

public virtual OrderStatus Status { get; protected set; }

protected Order()
{
}

protected Order(Location location, IEnumerable<Item> items)
{
Location = location;
ItemsCollection = new List<Item>(items);
}
}
}
28 changes: 28 additions & 0 deletions src/Restbucks.Service/Mappers/ItemRepresentationMapper.cs
@@ -0,0 +1,28 @@
using Restbucks.Service.Domain;
using Restbucks.Service.Representations;

namespace Restbucks.Service.Mappers
{
public class ItemRepresentationMapper
{
public ItemRepresentation GetRepresentation(Item item)
{
return new ItemRepresentation
{
Drink = item.Drink,
Milk = item.Milk,
Size = item.Size
};
}

public Item GetDomainObject(ItemRepresentation itemRepresentation)
{
return new Item
{
Drink = itemRepresentation.Drink,
Milk = itemRepresentation.Milk,
Size = itemRepresentation.Size
};
}
}
}
21 changes: 21 additions & 0 deletions src/Restbucks.Service/Mappers/OrderRepresentationMapper.cs
@@ -0,0 +1,21 @@
using System.Linq;
using Restbucks.Service.Domain;
using Restbucks.Service.Representations;

namespace Restbucks.Service.Mappers
{
public class OrderRepresentationMapper
{
public OrderRepresentation GetRepresentation(Order order)
{
var itemMapper = new ItemRepresentationMapper();
return new OrderRepresentation
{
Cost = order.Total,
Items = order.Items.Select(itemMapper.GetRepresentation).ToList(),
Location = order.Location,
Status = order.Status,
};
}
}
}
47 changes: 25 additions & 22 deletions src/Restbucks.Service/Representations/OrderRepresentation.cs
Expand Up @@ -26,35 +26,38 @@ public string UpdateLink
set { SetLink(RestbucksRelation.Update, value); }
}

//[XmlIgnore]
//public Link CancelLink
//{
// get { return GetLinkByRel(RestbucksRelation.Cancel); }
//}
[XmlIgnore]
public string CancelLink
{
get { return GetLinkByRel(RestbucksRelation.Cancel).UnlessNull(x => x.Uri); }
set { SetLink(RestbucksRelation.Cancel, value); }
}

//[XmlIgnore]
//public Link PaymentLink
//{
// get { return GetLinkByRel(RestbucksRelation.Payment); }
//}
[XmlIgnore]
public string PaymentLink
{
get { return GetLinkByRel(RestbucksRelation.Payment).UnlessNull(x => x.Uri); }
set { SetLink(RestbucksRelation.Payment, value); }
}

//[XmlIgnore]
//public Link SelfLink
//{
// get { return GetLinkByRel(SelfRelValue); }
//}
[XmlIgnore]
public string SelfLink
{
get { return GetLinkByRel(SelfRelValue).UnlessNull(x => x.Uri); }
set { SetLink(SelfRelValue, value); }
}

public OrderRepresentation()
{

}

public OrderRepresentation(string orderUri, string paymentUri)
{
SetLink(RestbucksRelation.Update, orderUri);
SetLink(RestbucksRelation.Cancel, orderUri);
SetLink(RestbucksRelation.Payment, paymentUri);
SetLink(SelfRelValue, orderUri);
}
//public OrderRepresentation(string orderUri, string paymentUri)
//{
// SetLink(RestbucksRelation.Update, orderUri);
// SetLink(RestbucksRelation.Cancel, orderUri);
// SetLink(RestbucksRelation.Payment, paymentUri);
// SetLink(SelfRelValue, orderUri);
//}
}
}
2 changes: 2 additions & 0 deletions src/Restbucks.Service/Restbucks.Service.csproj
Expand Up @@ -78,6 +78,8 @@
<Compile Include="Domain\Location.cs" />
<Compile Include="Domain\Order.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Mappers\ItemRepresentationMapper.cs" />
<Compile Include="Mappers\OrderRepresentationMapper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Domain\Drink.cs" />
<Compile Include="Domain\Item.cs" />
Expand Down

0 comments on commit b607083

Please sign in to comment.