using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; using EnVisage.Code; using EnVisage.Models.Entities; using System.Web.Mvc; //using Excel; namespace EnVisage.Models { #region Skill and SkillGroup Models public class SkillGroupModel : IBaseModel, IValidatableObject { public Guid Id { get; set; } [Required] [MaxLength(512, ErrorMessage = "Name should not exceed 512 characters")] [Display(Name = "Name")] public string Name { get; set; } [Display(Name = "Skill Group has multiple Skills")] public bool HasChildren { get; set; } public bool InitialHasChildrenState { get; set; } public Dictionary Children { get; set; } public string Timestamp { get; set; } public Guid? ParentId { get; private set; } public bool IsNew { get; set; } public bool IsDeleted { get; set; } public bool IsChanged { get; set; } public bool HasS2RData { get; set; } public bool CopyDataUponDelete { get; set; } /// /// Casts a entity to the object of type . /// /// A object. /// A object filled with data from db. public static explicit operator SkillGroupModel(Skill obj) { if (obj == null) return null; var model = new SkillGroupModel { Id = obj.Id, Name = obj.Name, HasChildren = obj.HasChildren, InitialHasChildrenState = obj.HasChildren, ParentId = obj.ParentId, Timestamp = obj.EditTimestamp.ByteArrayToString(), HasS2RData = obj.Skill2Resource.Any() }; model.TrimStringProperties(); if (model.HasChildren && obj.Skills != null) { foreach (var child in obj.Skills.OrderBy(pp => pp.Name)) { var skill = (SkillModel)child; model.Children.Add(skill.Id.ToString(), skill); } } model.TrimStringProperties(); return model; } /// /// Copies data from model to DAL object. /// /// A target DAL object. public void CopyTo(Skill dbObj) { if (dbObj == null) throw new ArgumentNullException(); dbObj.Name = Name; dbObj.HasChildren = HasChildren; } public SkillGroupModel Clone() { return new SkillGroupModel { Id = this.Id, Name = this.Name, HasChildren = this.HasChildren, InitialHasChildrenState = this.HasChildren, Children = this.Children, HasS2RData = this.HasS2RData, CopyDataUponDelete = this.CopyDataUponDelete, IsChanged = this.IsChanged, IsDeleted = this.IsDeleted, IsNew = this.IsNew, ParentId = this.ParentId, Timestamp = this.Timestamp }; } public SkillGroupModel() { Children = new Dictionary(); CopyDataUponDelete = true; } public IEnumerable Validate(ValidationContext validationContext) { if (HasChildren && Children != null && Children.Count > 0) { foreach (var key in Children.Keys) { if (string.IsNullOrEmpty(Children[key].Name)) yield return new ValidationResult(string.Format(Constants.ERROR_TEMPLATE_REQUIRED, "Skill Name"), null); } } } } public class SkillModel : IBaseModel { public Guid Id { get; set; } [Required] [MaxLength(512, ErrorMessage = "Name should not exceed 512 characters")] public string Name { get; set; } public string Timestamp { get; set; } public Guid? ParentId { get; set; } public bool IsNew { get; set; } public bool IsDeleted { get; set; } public bool IsChanged { get; set; } public bool HasS2RData { get; set; } public static explicit operator SkillModel(Skill obj) { if (obj == null) return null; var model = new SkillModel { Id = obj.Id, Name = obj.Name, ParentId = obj.ParentId, Timestamp = obj.EditTimestamp.ByteArrayToString(), HasS2RData = obj.Skill2Resource.Any() }; model.TrimStringProperties(); return model; } /// /// Copies data from model to DAL object. /// /// A target DAL object. public void CopyTo(Skill dbObj) { if (dbObj == null) throw new ArgumentNullException(); dbObj.Name = Name; dbObj.HasChildren = false; dbObj.ParentId = ParentId; } public SkillModel Clone() { return new SkillModel { Id = this.Id, Name = this.Name, ParentId = this.ParentId, Timestamp = this.Timestamp, HasS2RData = this.HasS2RData, IsNew = this.IsNew, IsDeleted = this.IsDeleted, IsChanged = this.IsChanged }; } } /// /// An UI representation of skill to be displayed as list item /// public class EditSkillsModel : Dictionary { } #endregion #region SkillMatrix Models public class SkillsMatrixQueryModelBase { public long DatePoint { get; set; } public Skill2ResourceType DataType { get; set; } public bool ReadOnly { get; set; } } /// /// Model for managing Skills Matrix display on a page /// public class SkillsMatrixPageLoadModel : SkillsMatrixQueryModelBase { public class FilterOptionsModel { public List Companies = new List(); public List Teams = new List(); public List Views = new List(); public List Skills = new List(); public List SkillLevels = new List(); public List SkillInterests = new List(); } public ApplicationDashboards OpenerType; public string OpenerId; public FilterOptionsModel FilterOptions; public string ActivityCalendarUrl; public SkillsMatrixPageLoadModel() { FilterOptions = new FilterOptionsModel(); } } public class SkillsMatrixBarChartModel { public List> Titles { get; set; } public List> GTitles { get; set; } public string[] Colors { get; set; } public List Data { get; set; } public List GroupData { get; set; } public int MaxVal { get; set; } public int GMaxVal { get; set; } //public List[] Data { get; set; } } public class SkillsMatrixBarChartPartModel { public Guid Id { get; set; } public int Count { get; set; } public int Level0 { get; set; } public int Level1 { get; set; } public int Level2 { get; set; } public int Level3 { get; set; } public int Level4 { get; set; } } public class SkillsMatrixPieChartPartModel { public List TypeId { get; set; } public string Label { get; set; } public decimal Value { get; set; } public string PresetColor { get; set; } } public class SkillsMatrixPieChartModel { public List PastData { get; set; } public List PresentData { get; set; } public List FutureData { get; set; } public List PastGroupedData { get; set; } public List PresentGroupedData { get; set; } public List FutureGroupedData { get; set; } } public class SkillsMatrixPiePanelModel { public List> PieCharts { get; set; } } /// /// Model to query Skills Matrix from server /// public class SkillsMatrixQueryModel : SkillsMatrixQueryModelBase { public SkillsMaxtrixFilterModel Filter { get; set; } } /// /// Filtering Model for Skills matrix /// public class SkillsMaxtrixFilterModel { public List Teams { get; set; } public List Views { get; set; } public List Resources { get; set; } public List Companies { get; set; } public List Skills { get; set; } public List SkillLevels { get; set; } public bool? IncludeInterested { get; set; } public bool? GroupMode { get; set; } // Retrive the only skills and groups, that has data public bool SkillsWithDataOnly { get; set; } } /// /// Model for transfering Skills Matrix data between client and server /// public class SkillsMatrixSaveModel { public class SkillGroupDisplayModel { public Guid Id { get; set; } public string Name { get; set; } public List Skills { get; set; } public SkillGroupDisplayModel() { Skills = new List(); } public SkillsMatrixBarChartModel BarChartData { get; set; } public SkillsMatrixPiePanelModel PiePanelData { get; set; } } public class SkillDisplayModel { public Guid Id { get; set; } public string Name { get; set; } public Guid? SkillGroupId { get; set; } public bool IsVirtual { get; set; } } public class DataItem { public Guid SkillId { get; set; } public Guid ResourceId { get; set; } public int? Level { get; set; } public bool Interested { get; set; } public bool LevelChanged { get; set; } public bool InterestChanged { get; set; } } public class Team { public Guid Id { get; set; } public string Name { get; set; } public List Resources { get; set; } public Team() { Resources = new List(); } } public class Resource { public Guid Id { get; set; } public List Teams { get; set; } public string LastName { get; set; } public string FirstName { get; set; } public string FullName { get { return String.Format("{0} {1}", FirstName, LastName).Trim(); } } public Resource() { Teams = new List(); } } public SkillsMatrixBarChartModel BarGraphData { get; set; } public SkillsMatrixPieChartModel PieGraphData { get; set; } public long DatePoint { get; set; } public Skill2ResourceType DataType { get; set; } public List SkillGroups { get; set; } public List Teams { get; set; } public List Resources { get; set; } public Dictionary Values { get; set; } // SA. Key for dictionary values is # public SkillsMatrixSaveModel() { SkillGroups = new List(); Teams = new List(); Resources = new List(); Values = new Dictionary(); } } #endregion } namespace EnVisage { /// /// Extension for Skill class /// public partial class Skill : ITimestampEntity { public void SetUpdatedTimestamp() { } public void SetCreatedTimestamp() { this.DateCreated = DateTime.UtcNow; } public ulong? GetCurrentVersion() { if (this.EditTimestamp != null) return BitConverter.ToUInt64(this.EditTimestamp.Reverse().ToArray(), 0); else return (ulong?)null; } } }