refactoring

vnext
Paul Schneider 8 years ago
parent 167a9861a4
commit c5274146e3
3 changed files with 46 additions and 53 deletions

@ -0,0 +1,7 @@
namespace Yavsc.Models.Market {
public interface IUnit<VType> {
string Name { get; }
bool CanConvertFrom(IUnit<VType> other);
VType ConvertFrom (IUnit<VType> other, VType orgValue) ;
}
}

@ -0,0 +1,37 @@
using System;
namespace Yavsc.Models.Market {
public class Money : IUnit<decimal>
{
public Money(string name, decimal euroExchangeRate)
{
Name = name;
EuroExchangeRate = euroExchangeRate;
}
public string Name
{
get; private set ;
}
public decimal EuroExchangeRate
{
get; private set ;
}
public bool CanConvertFrom(IUnit<decimal> other)
{
if (other is Money)
return true;
return false;
}
public decimal ConvertFrom(IUnit<decimal> other, decimal orgValue)
{
if (other is Money) {
var om = other as Money;
return orgValue * om.EuroExchangeRate / EuroExchangeRate;
}
throw new NotImplementedException();
}
}
}

@ -1,66 +1,15 @@
namespace Yavsc.Models.Market {
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
public enum BillingMode { 
Unitary,
SetPrice,
ByExecutionTime
}
public interface IUnit<VType> {
string Name { get; }
bool CanConvertFrom(IUnit<VType> other);
VType ConvertFrom (IUnit<VType> other, VType orgValue) ;
}
public class Money : IUnit<decimal>
{
public Money(string name, decimal euroExchangeRate)
{
Name = name;
EuroExchangeRate = euroExchangeRate;
}
public string Name
{
get; private set ;
}
public decimal EuroExchangeRate
{
get; private set ;
}
public bool CanConvertFrom(IUnit<decimal> other)
{
if (other is Money)
return true;
return false;
}
public decimal ConvertFrom(IUnit<decimal> other, decimal orgValue)
{
if (other is Money) {
var om = other as Money;
return orgValue * om.EuroExchangeRate / EuroExchangeRate;
}
throw new NotImplementedException();
}
}
public partial class Service : BaseProduct
{
public string ContextId { get; set; }
[ForeignKey("ContextId")]
public virtual Activity Context { get; set; }
public BillingMode? Billing { get; set; }
// TODO public ServiceSpecification Specification { get; set; }
/// <summary>
/// In euro
/// </summary>
/// <returns></returns>
public decimal? Pricing { get; set; }
public List<IBillingClause> Billing { get; set; }
}

Loading…