You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

78 lines
2.9 KiB

using Sevomin.Models.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
namespace Sevomin.Models
{
public class JobMiniExternalViewModel
{
private int MaxNumberOfMiniParams = 6;
[Key]
public long Id { 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 bool IsFullTime { get; set; }
public string JobSummary { private set; get; }
private IList<Tuple<string, string>> Parameters;
public JobMiniExternalViewModel(Job job, int maxNumberOfMiniParams = 6)
{
this.MaxNumberOfMiniParams = maxNumberOfMiniParams;
this.Id = job.Id;
this.ExpireDate = job.ExpireDate == DateTime.MinValue ? DateTime.UtcNow.AddDays(14) : job.ExpireDate;
this.IsFullTime = job.IsFullTime;
if (job.JobParameters == null)
return;
Parameters = new List<Tuple<string,string>>();
var jpz = job.JobParameters.Where(x=>!string.IsNullOrWhiteSpace(x.StringValue)).OrderByDescending(x=>x.Moscow).Take(Math.Min(MaxNumberOfMiniParams * 3, job.JobParameters.Count()))
.OrderBy(x => x.Parameter.GroupName).ThenByDescending(x => x.Moscow).Take((int)(MaxNumberOfMiniParams*1.5)).ToList();
for (int i = 0; i < jpz.Count(); i++)
{
string format = jpz[i].Parameter.DisplayFormat;
format = format.Replace("$", jpz[i].Parameter.Name);
string value = jpz[i].StringValue;
if (jpz[i].Parameter.DisplayMethod == 4)
{
value = jpz[i].Parameter.ParameterValues.ToList().Where(x =>x.NumbericValue == jpz[i].NumericValue).Select(x => x.Value)
.FirstOrDefault();
}
Parameters.Add(new Tuple<string,string>(format, value));
}
StringBuilder sb = new StringBuilder("کارشناس برنامه ریزی و کنترل پروژه ");
foreach (var param in Parameters)
sb.Append(string.Format(param.Item1 + " ", param.Item2));
this.JobSummary = sb.ToString();
}
}
}