using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web.Mvc; using AutoMapper; using LeafWeb.Core.Entities; using LeafWeb.Core.Utility; namespace LeafWeb.WebCms.Models { public class LeafInputDetails { [HiddenInput(DisplayValue = false)] public int LeafInputId { get; set; } [Display(Name = "Identifier")] [Required(ErrorMessage = "A unique identifier is required")] public string Identifier { get; set; } [Display(Name = "Site Id")] [Required(ErrorMessage = "The site's name is required")] public string SiteId { get; set; } [Display(Name = "Photosyn. Pathway")] [Required(ErrorMessage = "A Photosynthetic pathway must be chosen")] public string PhotosynthesisType { get; set; } [Display(Name = "Name")] [Required(ErrorMessage = "Name required")] [RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Please provide full name")] public string Name { get; set; } [Display(Name = "Email address")] [Required(ErrorMessage = "An email address is required")] [DataType(DataType.EmailAddress)] [RegularExpression(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}", ErrorMessage = "Must be an email address")] public string Email { get; set; } [DataType(DataType.Date)] [Required] public DateTime Added { get; set; } [Display(Name = "Piscal Error")] public string OutputErrorMessage { get; set; } [Display(Name = "Piscal Warning")] public string OutputWarningMessage { get; set; } //[UIHint("Status")] //public string CurrentStatus { get; set; } [UIHint("LeafInputStatusViewModels")] public List StatusHistory { get; set; } [HiddenInput(DisplayValue = false)] public bool HasLeafChart { get; set; } [HiddenInput(DisplayValue = false)] public bool IsRunning { get; set; } [HiddenInput(DisplayValue = false)] public bool IsComplete { get; set; } [HiddenInput(DisplayValue = false)] public bool IsDeletable { get; set; } static LeafInputDetails() { Mapper.CreateMap().ConvertUsing(file => file?.Contents.GetString()); Mapper.CreateMap().ConvertUsing(file => file?.FileContents.Contents.GetString()); Mapper.CreateMap().ConvertUsing(st => st.ToString()); Mapper.CreateMap().ConvertUsing(st => new LeafInputStatus()); Mapper.CreateMap(); Mapper.CreateMap() .ForMember(dest => dest.LeafInputId, opt => opt.MapFrom(src => src.Id)) .ForMember(dest => dest.HasLeafChart, opt => opt.ResolveUsing(src => src.OutputFiles.Any(o => o.IsLeafChartFile))); } public LeafInputDetails(LeafInput leafInput) { Mapper.Map(leafInput, this); } } }