using System; using System.Collections.Generic; using Common; namespace SharedDatabase.Entities { public class Process { public virtual int Id { get; protected set; } public virtual int ItemNr { get; set; } public virtual string Name { get; set; } public virtual string Description { get; set; } public virtual string CreatedBy { get; set; } public virtual DateTime TimeStamp { get; set; } public virtual string ApprovedBy { get; set; } public virtual DateTime TimeStamp2 { get; set; } public virtual string ReleaseNotes { get; set; } public virtual ReleaseStatus ReleaseStatus { get; set; } public virtual IList Parts { get; set; } public virtual IList Worksteps { get; set; } /// /// Default (private) constructor inicializing lists /// protected Process() { Parts = new List(); Worksteps = new List(); } /// /// Constructor used when this process is created /// /// public Process(string name) : this() { Name = name; Description = string.Empty; ReleaseNotes = string.Empty; CreatedBy = "admin"; TimeStamp = DateTime.Now; ApprovedBy = string.Empty; TimeStamp2 = DateTime.Now; ReleaseStatus = ReleaseStatus.In_preparation; } /// /// Create a copy of a process with a new name and original 'Created by' user. /// /// /// public virtual Process Clone(string name) { return Clone(name, CreatedBy); } /// /// Create a copy of a process with a new name. /// /// /// public virtual Process Clone(string name, string userName) { Process rslt = new Process(name); rslt.Description = Description; rslt.ReleaseNotes = ReleaseNotes; rslt.CreatedBy = userName; rslt.TimeStamp = DateTime.Now; rslt.ApprovedBy = string.Empty; rslt.ReleaseStatus = ReleaseStatus.In_preparation; foreach (var part in Parts) rslt.Parts.Add(part.Clone(rslt)); foreach (var workstep in Worksteps) rslt.Worksteps.Add(workstep.Clone(rslt)); return rslt; } /// /// Gets a process with a specified name from a list of processes. /// /// List of processes (ReleasedActive processs) /// Process name /// Process or null if not found public static Process GetProcessFromName(IList processes, string processName) { foreach (var proc in processes) { if (proc.Name == processName) return proc; } return null; } public override string ToString() { return string.IsNullOrEmpty(Name) ? string.Empty : ((Id != 0) ? Name : string.Format("{0} ({1})", Name, SharedDatabase.Resources.Strings.unsaved)); } } }