59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using EnVisage.Code;
|
|
|
|
namespace EnVisage.Models
|
|
{
|
|
public class UOMModel : IBaseModel<UOM>
|
|
{
|
|
public Guid Id { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(50)]
|
|
[Display(Name="Unit of Measure Name")]
|
|
public string Name { get; set; }
|
|
|
|
[Display(Name = "Value")]
|
|
public decimal UOMValue { get; set; }
|
|
|
|
[Display(Name = "Number of Expenditure Categories")]
|
|
public int ExpenditureCategoryCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// Casts a <see cref="UOM"/> obect to the object of type <see cref="UOMModel"/>.
|
|
/// </summary>
|
|
/// <param name="obj">A <see cref="UOM"/> object.</param>
|
|
/// <returns>A <see cref="UOMModel"/> object filled with data from db.</returns>
|
|
public static explicit operator UOMModel(UOM obj)
|
|
{
|
|
if (obj == null)
|
|
return null;
|
|
var model = new UOMModel
|
|
{
|
|
Id = obj.Id,
|
|
Name = obj.Name,
|
|
UOMValue = obj.UOMValue,
|
|
ExpenditureCategoryCount = obj.ExpenditureCategory.Count
|
|
};
|
|
model.TrimStringProperties();
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copies data from model to DAL object.
|
|
/// </summary>
|
|
/// <param name="dbObj">A target DAL object.</param>
|
|
public void CopyTo(UOM dbObj)
|
|
{
|
|
if (dbObj == null)
|
|
throw new ArgumentNullException();
|
|
|
|
dbObj.Name = Name;
|
|
dbObj.UOMValue = UOMValue;
|
|
}
|
|
|
|
}
|
|
} |