64 lines
1.8 KiB
C#
64 lines
1.8 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 StatusModel : IBaseModel<Status>
|
|
{
|
|
public Guid Id { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(100)]
|
|
[Display(Name = "Status")]
|
|
public string Name { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(8)]
|
|
public string Color { get; set; }
|
|
|
|
[Display(Name = "Number of Projects")]
|
|
public int ProjectsCount { get; set; }
|
|
|
|
[Display(Name="100% probability")]
|
|
public string Probability100 { get; set; }
|
|
|
|
/// <summary>
|
|
/// Casts a <see cref="Status"/> obect to the object of type <see cref="StatusModel"/>.
|
|
/// </summary>
|
|
/// <param name="obj">A <see cref="Status"/> object.</param>
|
|
/// <returns>A <see cref="StatusModel"/> object filled with data from db.</returns>
|
|
public static explicit operator StatusModel(Status obj)
|
|
{
|
|
if (obj == null)
|
|
return null;
|
|
var model = new StatusModel
|
|
{
|
|
Id = obj.Id,
|
|
Name = obj.Name,
|
|
Color = obj.Color,
|
|
ProjectsCount = obj.Projects.Count,
|
|
Probability100 = obj.Probability100 ? "Yes" : "No"
|
|
};
|
|
model.TrimStringProperties();
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copies data from model to DAL object.
|
|
/// </summary>
|
|
/// <param name="dbObj">A target DAL object.</param>
|
|
public void CopyTo(Status dbObj)
|
|
{
|
|
if (dbObj == null)
|
|
throw new ArgumentNullException();
|
|
|
|
dbObj.Name = Name;
|
|
dbObj.Color = Color.Replace("#", "");
|
|
dbObj.Probability100 = Probability100 == "Yes";
|
|
}
|
|
}
|
|
} |