137 lines
4.1 KiB
C#
137 lines
4.1 KiB
C#
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Org.BouncyCastle.Asn1.Cms;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace _2021_backend.Models
|
|
{
|
|
public class Submission
|
|
{
|
|
public Submission()
|
|
{
|
|
Id = 0;
|
|
SubmitTime = DateTime.Now;
|
|
}
|
|
public Submission(SubmissionDto Dto, string ip)
|
|
{
|
|
Email = Dto.Email;
|
|
Grade = (grade)(Dto.Grade);
|
|
Sex = (sex)Dto.Sex;
|
|
Stuid = Dto.Stuid;
|
|
Major = Dto.Major;
|
|
Name = Dto.Name;
|
|
Tel = Dto.Tel;
|
|
Exp = (experience)Dto.Exp;
|
|
Yard = (yard)Dto.Yard;
|
|
Timelist = new List<int>();
|
|
Id = 0;
|
|
SubmitTime = DateTime.Now;
|
|
Address = ip;
|
|
}
|
|
[Key]
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
[Display(Name = "ID")]
|
|
public int Id { get; set; }
|
|
[Display(Name = "Host")]
|
|
public int Host { get; set; }
|
|
[Display(Name = "姓名")]
|
|
public string Name { get; set; }
|
|
[Display(Name = "学号")]
|
|
public string Stuid { get; set; }
|
|
[Display(Name = "性别")]
|
|
public sex Sex { get; set; }
|
|
|
|
[Display(Name = "学园")]
|
|
public yard Yard { get; set; }
|
|
[Display(Name = "年级")]
|
|
public grade Grade { get; set; }
|
|
[Display(Name = "专业")]
|
|
public string Major { get; set; }
|
|
[Display(Name = "电子邮件")]
|
|
public string Email { get; set; }
|
|
[Display(Name = "电话")]
|
|
public string Tel { get; set; }
|
|
|
|
[Display(Name = "经验程度")]
|
|
public experience Exp { get; set; }
|
|
|
|
[Display(Name = "时间列表")]
|
|
public List<int> Timelist { get; set; }
|
|
[Display(Name = "Ip Address")]
|
|
public string Address { get; set; }
|
|
[Display(Name = "提交时间")]
|
|
[DisplayFormat(DataFormatString = "{0:g}", ApplyFormatInEditMode = true)]
|
|
public DateTime SubmitTime { get; set; }
|
|
//活动场次ID
|
|
|
|
}
|
|
public class TimeSpec
|
|
{
|
|
public DateTime Day { get; set; }
|
|
public DateTime BeginTime { get; set; }
|
|
}
|
|
|
|
public class SubmissionDto
|
|
{
|
|
[Required()]
|
|
public string Name { get; set; }
|
|
[Required()]
|
|
public string Stuid { get; set; }
|
|
[Required()]
|
|
public int Sex { get; set; }
|
|
[Required()]
|
|
public int Grade { get; set; }
|
|
[Required()]
|
|
public int Yard { get; set; }
|
|
[Required()]
|
|
public string Major { get; set; }
|
|
[Required()]
|
|
public string Email { get; set; }
|
|
[Required()]
|
|
public string Tel { get; set; }
|
|
|
|
|
|
[Required()]
|
|
public int Exp { get; set; }
|
|
[Required()]
|
|
public List<TimeSpec> Timelist { get; set; }
|
|
|
|
|
|
public static Regex r = new Regex("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
|
|
public static Regex phone_regex = new Regex("^1\\d{10}$");
|
|
|
|
public bool Iscomplete() => Name != null && Stuid != null && (Sex == 0 || Sex == 1) && Major != null && Email != null && Tel != null && Yard > 0 && Yard < 6;
|
|
public bool Check()
|
|
{
|
|
if (Name.Length > 15)
|
|
return false;
|
|
if (Regex.Matches(Name, @"\d").Count > 0)
|
|
return false;
|
|
if (Stuid.Length > 10 || Stuid.Length < 7)
|
|
return false;
|
|
if (Sex > 1 || Sex < 0)
|
|
return false;
|
|
if (Grade < 0 || Grade > 4)
|
|
return false;
|
|
if (Major.Length > 20)
|
|
return false;
|
|
if (Yard >= 6 && Yard <= 0) return false;
|
|
if (Exp >= 5 && Exp <= 0) return false;
|
|
if (!r.IsMatch(Email))
|
|
{
|
|
return false;
|
|
}
|
|
if (!phone_regex.IsMatch(Tel))
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|