EnVisageOnline/Main/Source/EnVisage/Models/ViewModel.cs

97 lines
2.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 ViewModel : IBaseModel<View>
{
public Guid Id { get; set; }
[Required]
[MaxLength(100)]
[Display(Name="Name")]
public string Name { get; set; }
[Display(Name = "Number of Teams")]
public int TeamCount { get; set; }
public string backController{ get; set; }
public string backAction { get; set; }
[Required]
[UIHint("MultipleSelect")]
[Display(Name = "Watchers")]
public IList<Guid> Watchers { get; set; }
[EitherOfRequired("Companies", "At least one Team or Business Unit must me selected", "", true)]
[UIHint("MultipleSelect")]
[Display(Name = "Teams")]
public IList<Guid> Teams { get; set; }
[UIHint("MultipleSelect")]
[Display(Name = "Business Units")]
public IList<Guid> Companies { get; set; }
public IEnumerable<AspNetUser> AvailableUsers
{
get
{
EnVisageEntities DbContext = new EnVisageEntities();
return DbContext.AspNetUsers;
}
}
public ViewModel()
{
this.Watchers = new List<Guid>();
this.Teams = new List<Guid>();
this.Companies = new List<Guid>();
}
/// <summary>
/// Casts a <see cref="View"/> obect to the object of type <see cref="ViewModel"/>.
/// </summary>
/// <param name="obj">A <see cref="View"/> object.</param>
/// <returns>A <see cref="GLAccountModel"/> object filled with data from db.</returns>
public static explicit operator ViewModel(View obj)
{
if (obj == null)
return null;
var model = new ViewModel
{
Id = obj.Id,
Name = obj.Name,
TeamCount = obj.Team2View.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(View dbObj)
{
if (dbObj == null)
throw new ArgumentNullException();
dbObj.Name = Name;
}
}
/// <summary>
/// An UI representation of client to be displayed as list items
/// </summary>
public class ViewListModel
{
public Guid Id { get; set; }
public string Name { get; set; }
/// <summary>
/// Gets or sets a value indicating that View is virtual. It is set only if this is an virtual company view, otherwise it is null.
/// </summary>
public Guid? CompanyId { get; set; }
}
}