diff --git a/Sevomin.Models/Helpers/DateAssist.cs b/Sevomin.Models/Helpers/DateAssist.cs new file mode 100644 index 0000000..168b510 --- /dev/null +++ b/Sevomin.Models/Helpers/DateAssist.cs @@ -0,0 +1,213 @@ +using System; +using System.Globalization; + +namespace Sevomin.Models.Helpers +{ + public class DateAssist + { + public class FromToDate + { + public DateTime Start; + public DateTime End; + public string startShamsi; + public string endShamsi; + } + + /// + /// None Zero-Based month number + /// + /// + /// + public static string GetPersianMonthName(int monthNumber) + { + switch (monthNumber) + { + case 1: + return "فروردین"; + case 2: + return "اردیبهشت"; + case 3: + return "خرداد"; + case 4: + return "تیر"; + case 5: + return "مرداد"; + case 6: + return "شهریور"; + case 7: + return "مهر"; + case 8: + return "آبان"; + case 9: + return "آذر"; + case 10: + return "دی"; + case 11: + return "بهمن"; + case 12: + return "اسفند"; + default: + throw new ArgumentException("شماره ماه باید بین 1 تا 12 باشد.", "monthNumber", null); + } + } + + public static string GetFullPersianDate(DateTime value) + { + PersianCalendar pc = new PersianCalendar(); + return string.Format("{0} {1} {2}", + pc.GetDayOfMonth(value), GetPersianMonthName(pc.GetMonth(value)), + pc.GetYear(value)); + } + + public static DateTime? ValidateAndSetToMiladi(string value, DateTime? defaultValue = null) + { + string vd = ValidateDate(value); + if (string.IsNullOrEmpty(vd)) + return defaultValue; + return ToMiladi(vd); + } + + public static DateTime ToMiladi(string value) + { + if (value == "" || value == null) + return DateTime.MinValue; + PersianCalendar pc = new PersianCalendar(); + DateTime mil; + mil = pc.ToDateTime(int.Parse(value.Substring(0, 4)), + int.Parse(value.Substring(5, 2)), int.Parse(value.Substring(8, 2)) + , 0, 0, 0, 0); + return mil; + } + + public static string ToShamsi(DateTime value) + { + if (value == DateTime.MinValue) + return string.Empty; + PersianCalendar pc = new PersianCalendar(); + return string.Format("{0:0000}/{1:00}/{2:00}", + pc.GetYear(value), pc.GetMonth(value), + pc.GetDayOfMonth(value)); + } + + public static string ValidateDate(string value) + { + if (value == null) + return ""; + int offset = 0; + if (value.Length == 8) //13801010 + { + value = value.Insert(4, "/"); + value = value.Insert(7, "/"); + } + if (int.TryParse(value, out offset)) + { + if (offset > 500 || offset < -500) + return ""; + return ToShamsi(DateTime.Today.AddDays(offset)); + } + else + { + try + { + DateTime val = ToMiladi(value); + if (val < DateTime.Today.AddYears(-5) || + val > DateTime.Today.AddYears(10)) + return ""; + return value; + } + catch (Exception) + { + return ""; + } + } + } + + public static FromToDate GetThisMonth() + { + PersianCalendar pc = new PersianCalendar(); + DateTime value = DateTime.Today; + return GetMonth(pc.GetMonth(value)); + } + + /// + /// returns date of 1st and last day of month as a + /// FromToDate object + /// + /// Index of Mounth 1-based + /// FromToDate object + public static FromToDate GetMonth(int monthIndex) + { + PersianCalendar pc = new PersianCalendar(); + FromToDate ftd = new FromToDate(); + DateTime value = DateTime.Today; + string startShamsi = string.Format("{0:0000}/{1:00}/{2:00}", + pc.GetYear(value), monthIndex, + 1); + string endShamsi = string.Format("{0:0000}/{1:00}/{2:00}", + pc.GetYear(value), monthIndex, + pc.GetDaysInMonth(pc.GetYear(value), monthIndex)); + ftd.Start = ToMiladi(startShamsi); + ftd.End = ToMiladi(endShamsi); + ftd.startShamsi = startShamsi; + ftd.endShamsi = endShamsi; + return ftd; + } + + public static String NextMonth(string currentDate, int dayOfMonth) + { + return NextMonth(currentDate, dayOfMonth, 1); + } + public static String NextMonth(string currentDate, int dayOfMonth, int monthInterval) + { + try + { + PersianCalendar pc = new PersianCalendar(); + int year = int.Parse(currentDate.Substring(0, 4)); + int month = int.Parse(currentDate.Substring(5, 2)); + month += monthInterval; + if (month > 12) + { + year += 1; + month = 1; + } + if (pc.GetDaysInMonth(year, month) < dayOfMonth) + dayOfMonth = pc.GetDaysInMonth(year, month); + return string.Format("{0:0000}/{1:00}/{2:00}", year, month, dayOfMonth); + + } + catch (Exception) + { + return ""; + } + + } + + public static string ToPersianNumbers(string number) + { + char[] temp = new char[number.Length]; + + for (int i = 0; i < number.Length; i++) + { + char value = number[i]; + + if (value >= 48 && value <= 57) + temp[i] = (char)(value + 1728); + else + temp[i] = value; + } + + return new String(temp); + } + + public static int GetJalaliWeekNumber(DateTime gregorianDate) + { + PersianCalendar pc = new PersianCalendar(); + + DateTime gregYearStart = pc.ToDateTime(pc.GetYear(gregorianDate), 1, 1, 0, 0, 0, 0); + int diff = (gregorianDate - gregYearStart).Days; + int wd = ((int)pc.GetDayOfWeek(gregorianDate) + 2) % 7; + + return (diff - wd + 10) / 7; + } + } +} \ No newline at end of file diff --git a/Sevomin.Models/JobViewModel.cs b/Sevomin.Models/JobViewModel.cs index ac9f31b..3dd2163 100644 --- a/Sevomin.Models/JobViewModel.cs +++ b/Sevomin.Models/JobViewModel.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Sevomin.Models.Helpers; +using System.ComponentModel; namespace Sevomin.Models { @@ -17,17 +18,47 @@ namespace Sevomin.Models [StringLength(128)] public string AvalinId { get; set; } + [DisplayName("تاریخ انقضا")] + [DataType(DataType.Date)] public DateTime ExpireDate { get; set; } + [DisplayName("تاریخ انقضا")] + [DataType(DataType.Date)] + public string JalaliExpireDate + { + get + { + return DateAssist.ToShamsi(this.ExpireDate); + } + set + { + ExpireDate = DateAssist.ValidateAndSetToMiladi(value) ?? DateTime.MinValue; + } + } + + [DisplayName("سایر مشخصات")] public string Description { get; set; } + + [DisplayName("نوع رزومه")] public byte ResumeType { get; set; } + + [DisplayName("نام رابط/نماینده شرکت")] public string ContactPersonName { get; set; } + + [DisplayName("تلفن رابط/نماینده شرکت")] public string ContactPersonPhone { get; set; } + [EmailValidation] + [DisplayName("ایمیل رابط/نماینده شرکت")] public string ContactPersonEMail { get; set; } + [DisplayName("نمایش نام شرکت")] public bool ShowCompanyName { get; set; } + + [DisplayName("نمایش لوگوی شرکت")] public bool ShowCompanyLogo { get; set; } + + [DisplayName("کار تمام وقت")] public bool IsFullTime { get; set; } public IList Parameters; @@ -36,7 +67,7 @@ namespace Sevomin.Models { this.Id = job.Id; this.AvalinId = job.AvalinId; - this.ExpireDate = job.ExpireDate; + this.ExpireDate = job.ExpireDate == DateTime.MinValue ? DateTime.Now : job.ExpireDate; this.Description = job.Description; this.ResumeType = job.ResumeType; this.ContactPersonEMail = job.ContactPersonEMail; @@ -46,6 +77,9 @@ namespace Sevomin.Models this.ShowCompanyName = job.ShowCompanyName; this.IsFullTime = job.IsFullTime; + if (job.JobParameters == null) + return; + Parameters = new List(); foreach (var jp in job.JobParameters) { diff --git a/Sevomin.Models/Sevomin.Models.csproj b/Sevomin.Models/Sevomin.Models.csproj index 6e08045..7c2a4f3 100644 --- a/Sevomin.Models/Sevomin.Models.csproj +++ b/Sevomin.Models/Sevomin.Models.csproj @@ -63,6 +63,7 @@ + diff --git a/Sevomin.WebFrontend/Views/Job/JobEditor.cshtml b/Sevomin.WebFrontend/Views/Job/JobEditor.cshtml index f87188c..7c82a86 100644 --- a/Sevomin.WebFrontend/Views/Job/JobEditor.cshtml +++ b/Sevomin.WebFrontend/Views/Job/JobEditor.cshtml @@ -1,4 +1,4 @@ -@model Sevomin.Models.JobParameterViewModel +@model Sevomin.Models.JobViewModel @using (Html.BeginForm("", "", FormMethod.Post, new { role = "form" })) { @@ -8,26 +8,45 @@
- - +
+ @* + *@ + +
- - +
+ +
+
+
+
+ +
- - + @Html.LabelFor(model => model.JalaliExpireDate) + @Html.TextBoxFor(model => model.JalaliExpireDate, new { @class = "form-control datepickerify" }) +
+
+ @Html.LabelFor(model => model.ContactPersonName) + @Html.TextBoxFor(model => model.ContactPersonName, new { @class = "form-control" })
- - + @Html.LabelFor(model => model.ContactPersonPhone) + @Html.TextBoxFor(model => model.ContactPersonPhone, new { @class = "form-control" })
- - + @Html.LabelFor(model => model.ContactPersonEMail) + @Html.TextBoxFor(model => model.ContactPersonEMail, new { @class = "form-control" })