67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using EnVisage.Code;
|
|
|
|
namespace EnVisage.Models
|
|
{
|
|
public class ExpenditureModel : IBaseModel<Expenditure>
|
|
{
|
|
public Guid Id { get; set; }
|
|
[Required]
|
|
[MaxLength(100, ErrorMessage = "Expenditure name should not exceed 100 characters")]
|
|
[Display(Name="Expenditure Name")]
|
|
public string Name { get; set; }
|
|
[Display(Name = "Number of Expenditure Categories")]
|
|
public int CategoriesCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// Casts a <see cref="Expenditure"/> obect to the object of type <see cref="ExpenditureModel"/>.
|
|
/// </summary>
|
|
/// <param name="obj">A <see cref="Expenditure"/> object.</param>
|
|
/// <returns>A <see cref="ExpenditureModel"/> object filled with data from db.</returns>
|
|
public static explicit operator ExpenditureModel(Expenditure obj)
|
|
{
|
|
if (obj == null)
|
|
return null;
|
|
var model = new ExpenditureModel
|
|
{
|
|
Id = obj.Id,
|
|
Name = obj.Name,
|
|
CategoriesCount = 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(Expenditure dbObj)
|
|
{
|
|
if (dbObj == null)
|
|
throw new ArgumentNullException();
|
|
|
|
dbObj.Name = Name;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj == null)
|
|
return false;
|
|
|
|
if (!(obj is ExpenditureModel))
|
|
return false;
|
|
|
|
return (obj as ExpenditureModel).Id == Id;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return Id.GetHashCode();
|
|
}
|
|
}
|
|
} |