114 lines
4.6 KiB
C#
114 lines
4.6 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 StatusModelBrief
|
|
{
|
|
public Guid Id { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(100)]
|
|
[Display(Name = "Status")]
|
|
public string Name { get; set; }
|
|
}
|
|
|
|
public class StatusModel : StatusModelBrief, IBaseModel<Status>
|
|
{
|
|
[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; }
|
|
|
|
[Display(Name = "Change notification")]
|
|
public bool NotifyOnProjectChange { get; set; }
|
|
|
|
[RequiredIf("NotifyOnProjectChange", true)]
|
|
[Display(Name = "Change notification Contacts")]
|
|
public List<Guid> ChangeNotificationContacts { get; set; }
|
|
|
|
[Display(Name = "Delete notification")]
|
|
public bool NotifyOnProjectDelete { get; set; }
|
|
|
|
[RequiredIf("NotifyOnProjectDelete", true)]
|
|
[Display(Name = "Create notification Contacts")]
|
|
public List<Guid> DeleteNotificationContacts { get; set; }
|
|
|
|
[Display(Name = "Create notification")]
|
|
public bool NotifyOnProjectCreate { get; set; }
|
|
|
|
[RequiredIf("NotifyOnProjectCreate", true)]
|
|
[Display(Name = "Create notification Contacts")]
|
|
public List<Guid> CreateNotificationContacts { get; set; }
|
|
|
|
[Display(Name = "Deactive Scenario")]
|
|
public bool ResetScenariosToInactive { get; set; }
|
|
|
|
|
|
[Display(Name = "Set workflow state")]
|
|
public string WorkflowState { 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;
|
|
return getStatusModel(obj, new EnVisageEntities());
|
|
}
|
|
public static StatusModel getStatusModel(Status obj,EnVisageEntities context)
|
|
{
|
|
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",
|
|
NotifyOnProjectChange = obj.NotifyOnProjectChange.HasValue ? obj.NotifyOnProjectChange.Value : false,
|
|
WorkflowState = obj.WorkFlowState,
|
|
NotifyOnProjectCreate = obj.NotifyOnProjectCreate.HasValue ? obj.NotifyOnProjectCreate.Value : false,
|
|
NotifyOnProjectDelete = obj.NotifyOnProjectDelete.HasValue ? obj.NotifyOnProjectDelete.Value : false,
|
|
ResetScenariosToInactive = obj.ResetScenariosToInactive.HasValue ? obj.ResetScenariosToInactive.Value : false,
|
|
};
|
|
|
|
model.ChangeNotificationContacts = context.WorkFlowContacts.Where(x => x.NotificationType == (int) WorkFlowContactNotificationType.ProjectUpdate && x.PartentId == model.Id).Select(x => x.ContactId).ToList();
|
|
model.CreateNotificationContacts = context.WorkFlowContacts.Where(x => x.NotificationType == (int) WorkFlowContactNotificationType.ProjectCreate && x.PartentId == model.Id).Select(x => x.ContactId).ToList();
|
|
model.DeleteNotificationContacts = context.WorkFlowContacts.Where(x => x.NotificationType == (int) WorkFlowContactNotificationType.ProjectDelete && x.PartentId == model.Id).Select(x => x.ContactId).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(Status dbObj)
|
|
{
|
|
if (dbObj == null)
|
|
throw new ArgumentNullException();
|
|
|
|
dbObj.Name = Name;
|
|
dbObj.Color = Color.Replace("#", "");
|
|
dbObj.Probability100 = Probability100 == "Yes";
|
|
dbObj.NotifyOnProjectChange = this.NotifyOnProjectChange;
|
|
dbObj.WorkFlowState = this.WorkflowState;
|
|
dbObj.NotifyOnProjectCreate = this.NotifyOnProjectCreate;
|
|
dbObj.NotifyOnProjectDelete = this.NotifyOnProjectDelete;
|
|
dbObj.ResetScenariosToInactive = this.ResetScenariosToInactive;
|
|
|
|
}
|
|
}
|
|
} |