EnVisageOnline/Main-RMO/Source/EnVisage/Models/StrategicGoalModel.cs

91 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using EnVisage.Code;
using System.Linq;
namespace EnVisage.Models
{
public class StrategicGoalModel : IBaseModel<StrategicGoal>
{
public Guid Id { get; set; }
[Required]
[MaxLength(100)]
[Display(Name = "Goal")]
public string Name { get; set; }
[Display(Name = "Description")]
public string Description { get; set; }
[Display(Name = "Number of Projects")]
public int NbrProjects { get; set; }
[Required]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/dd/yy}", ApplyFormatInEditMode = true)]
[Display(Name = "Start Date")]
public DateTime? StartDate { get; set; }
[Required]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/dd/yy}", ApplyFormatInEditMode = true)]
[Display(Name = "End Date")]
public DateTime? EndDate { get; set; }
[Display(Name = "Color")]
public string Color { get; set; }
public List<Company> Companies { get; set; }
[UIHint("MultipleSelect")]
[Display(Name = "Companies")]
public List<Guid> CompanyId { get; set; }
public StrategicGoalModel()
{
Companies = new List<Company>();
}
/// <summary>
/// Casts a <see cref="Type"/> obect to the object of type <see cref="TypeModel"/>.
/// </summary>
/// <param name="obj">A <see cref="Type"/> object.</param>
/// <returns>A <see cref="TypeModel"/> object filled with data from db.</returns>
public static explicit operator StrategicGoalModel(StrategicGoal obj)
{
if (obj == null)
return null;
var model = new StrategicGoalModel
{
Id = obj.Id,
Name = obj.Name,
Description = obj.Description,
StartDate = obj.StartDate.Value,
EndDate = obj.EndDate.Value,
Color = obj.Color,
Companies = obj.StrategicGoal2Company.Select(x => new Company(){
Id = x.Company.Id,
Name = x.Company.Name
}).ToList()
};
model.TrimStringProperties();
return model;
}
/// <summary>
/// Copies data from model to DAL object.
/// </summary>
/// <param name="dbObj">A target DAL object.</param>
public void CopyTo(StrategicGoal dbObj)
{
if (dbObj == null)
throw new ArgumentNullException();
dbObj.Id = Id;
dbObj.Name = Name;
dbObj.Description = Description;
dbObj.StartDate = StartDate;
dbObj.EndDate = EndDate;
dbObj.Color = Color;
}
}
}