Work with Chel
This commit is contained in:
		@@ -32,10 +32,10 @@ namespace Diplom_O.DataBase
 | 
			
		||||
	{
 | 
			
		||||
		[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
 | 
			
		||||
		public int Id { get; set; }
 | 
			
		||||
		[ForeignKey("Dogovor")]
 | 
			
		||||
		[ForeignKey("Chel")]
 | 
			
		||||
		public int ChelId { get; set; }
 | 
			
		||||
		public Chel Chel { get; set; }
 | 
			
		||||
		[ForeignKey("Dogovor")]
 | 
			
		||||
		[ForeignKey("Shtat")]
 | 
			
		||||
		public int ShtatId { get; set; }
 | 
			
		||||
		public Shtat Shtat { get; set; }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,7 @@ namespace Diplom_O.DataBase
 | 
			
		||||
							where a.Doljnost.ToLower().Contains(f) && a.Active
 | 
			
		||||
							select a).ToArray();
 | 
			
		||||
					var res = new List<(Shtat shtat, int ost)>();
 | 
			
		||||
					for(var i = 0; i < shtat.Length; i++)
 | 
			
		||||
					for (var i = 0; i < shtat.Length; i++)
 | 
			
		||||
						res.Add((shtat[i], shtat[i].Size - BusySizeShtat(shtat[i].Id)));
 | 
			
		||||
					return res.ToArray();
 | 
			
		||||
				}
 | 
			
		||||
@@ -129,5 +129,61 @@ namespace Diplom_O.DataBase
 | 
			
		||||
			}
 | 
			
		||||
			catch { throw; }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static Chel GetChel(int id)
 | 
			
		||||
		{
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				using (var db = new MainDB())
 | 
			
		||||
				{
 | 
			
		||||
					var res = from a in db.Chely
 | 
			
		||||
										where a.Id == id
 | 
			
		||||
										select a;
 | 
			
		||||
					try { return res.Single(); }
 | 
			
		||||
					catch { return null; }
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			catch { throw; }
 | 
			
		||||
		}
 | 
			
		||||
		public static Chel[] ListChel(string filter = null)
 | 
			
		||||
		{
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				using (var db = new MainDB())
 | 
			
		||||
				{
 | 
			
		||||
					var f = (string.IsNullOrEmpty(filter)) ? "" : filter.ToLower();
 | 
			
		||||
					return (string.IsNullOrEmpty(f)) ?
 | 
			
		||||
						(from a in db.Chely
 | 
			
		||||
						 select a).ToArray() :
 | 
			
		||||
						 (from a in db.Chely
 | 
			
		||||
							where
 | 
			
		||||
							  a.FName.ToLower().Contains(f) ||
 | 
			
		||||
								a.SName.ToLower().Contains(f) ||
 | 
			
		||||
								a.TName.ToLower().Contains(f) ||
 | 
			
		||||
								a.Birthday.ToString("yyyy.MM.dd").ToLower().Contains(f) ||
 | 
			
		||||
								a.Address.ToLower().Contains(f) ||
 | 
			
		||||
								a.INN.ToLower().Contains(f) ||
 | 
			
		||||
								a.SNILS.ToLower().Contains(f) ||
 | 
			
		||||
								a.Pasport.ToLower().Contains(f)
 | 
			
		||||
							select a).ToArray();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			catch { throw; }
 | 
			
		||||
		}
 | 
			
		||||
		public static bool HaveChelFromRabotniky(int id, bool all=false)
 | 
			
		||||
		{
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				using (var db = new MainDB())
 | 
			
		||||
				{
 | 
			
		||||
					var res = (from a in db.Rabotniky
 | 
			
		||||
										 where a.ChelId == id && (all || !a.End.HasValue)
 | 
			
		||||
										 select a).ToArray();
 | 
			
		||||
					return res.Length > 0;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			catch { throw; }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user