demo20230512/Models/Company.cs

141 lines
5.1 KiB
C#
Raw Permalink Normal View History

2023-05-12 10:20:28 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using Microsoft.AspNet.Identity.EntityFramework;
using Newtonsoft.Json;
using Resources;
using Weee.DAL;
namespace Weee.Models
{
public enum CompanyStatus
{
[Display(Name = "CompanyStatusNew", ResourceType = typeof(Resource))]
New,
[Display(Name = "CompanyStatusActive", ResourceType = typeof(Resource))]
Active,
[Display(Name = "CompanyStatusInactive", ResourceType = typeof(Resource))]
Inactive
}
public abstract class Company : IValidatableObject
{
public Company()
{
UID = Guid.NewGuid();
Users = new HashSet<User>();
Status = CompanyStatus.New;
RegisterDate = DateTime.UtcNow;
LastStatusUpdateDate = DateTime.UtcNow;
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public int ID { get; set; }
public Guid UID { get; set; }
public string LogoUrl { get; set; }
[Display(Name = "CompanyName", ResourceType = typeof(Resource))]
//[Required(ErrorMessageResourceType = typeof(Resource),
// ErrorMessageResourceName = "RequiredMessage")]
[StringLength(100, ErrorMessageResourceType = typeof(Resource),
ErrorMessageResourceName = "CompanyNameMaxLength")]
public string Name { get; set; }
[Display(Name = "EnglishName", ResourceType = typeof(Resource))]
//[Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "RequiredMessage")]
public string EnglishName { get; set; }
[Display(Name = "CompanyAddress", ResourceType = typeof(Resource))]
//[Required(ErrorMessageResourceType = typeof(Resource),
// ErrorMessageResourceName = "RequiredMessage")]
[StringLength(300, ErrorMessageResourceType = typeof(Resource),
ErrorMessageResourceName = "CompanyAddressMaxLength")]
public string Address { get; set; }
[Display(Name = "CompanyVATNumber", ResourceType = typeof(Resource))]
public string VATNumber { get; set; }
[Display(Name = "CEOName", ResourceType = typeof(Resource))]
public string CEOName { get; set; }
[Display(Name = "CompanyIndustryDescription", ResourceType = typeof(Resource))]
public string IndustryDescription { get; set; }
[Display(Name = "CompanyDescription", ResourceType = typeof(Resource))]
public string Description { get; set; }
[Display(Name = "Capital", ResourceType = typeof(Resource))]
[Range(0, Int32.MaxValue)]
public int Capital { get; set; }
[Display(Name = "CompanyWebSiteUrl", ResourceType = typeof(Resource))]
[StringLength(50, ErrorMessageResourceType = typeof(Resource),
ErrorMessageResourceName = "CompanyWebSiteUrlMaxLength")]
public string WebSiteUrl { get; set; }
[Display(Name = "CompanyRegisterDate", ResourceType = typeof(Resource))]
public DateTime RegisterDate { get; set; }
[Display(Name = "CompanyLastStatusUpdateDate", ResourceType = typeof(Resource))]
public DateTime LastStatusUpdateDate { get; set; }
[Display(Name = "EnabledStatus", ResourceType = typeof(Resource))]
public CompanyStatus Status { get; set; }
[InverseProperty("Company")]
[JsonIgnore]
[IgnoreDataMember]
public virtual ICollection<User> Users { get; set; }
[NotMapped]
[JsonIgnore]
[IgnoreDataMember]
public Type CompanyType
{
get
{
return ObjectContext.GetObjectType(this.GetType());
}
}
[NotMapped]
[JsonIgnore]
[IgnoreDataMember]
public string CompanyTypeDisplayName
{
get
{
if (this.CompanyType == typeof(NormalCompany))
{
return Resource.StaticLabelNormalCompany;
}
else
{
return Resource.StaticLabelCertificationCompany;
}
}
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var result = new List<ValidationResult>();
if (string.IsNullOrWhiteSpace(Name))
result.Add(new ValidationResult(Resource.RequiredMessage, new[] { nameof(Name) }));
if (string.IsNullOrWhiteSpace(EnglishName))
result.Add(new ValidationResult(Resource.RequiredMessage, new[] { nameof(EnglishName) }));
if (string.IsNullOrWhiteSpace(Address))
result.Add(new ValidationResult(Resource.RequiredMessage, new[] { nameof(Address) }));
if (string.IsNullOrWhiteSpace(VATNumber))
result.Add(new ValidationResult(Resource.RequiredMessage, new[] { nameof(VATNumber) }));
return result;
}
}
}