Ejemplo n.º 1
0
        public ActionResult Establishment(EstablishmentSearch search)
        {
            using (var session = NHibernateHelper.CreateSessionFactory())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var registrations = new List <Registration>(session.CreateCriteria(typeof(Registration)).List <Registration>());

                    if (!String.IsNullOrEmpty(search.EstablishmentName))
                    {
                        registrations = registrations.Where(s => s.EstablishmentName.ToLower().Contains(search.EstablishmentName.ToLower())).ToList();
                    }

                    if (!String.IsNullOrEmpty(search.PhermcRegistrationNumber))
                    {
                        registrations = registrations.Where(s => s.PhermcRegistrationNumber.ToLower().Contains(search.PhermcRegistrationNumber.ToLower())).ToList();
                    }

                    if (!String.IsNullOrEmpty(search.CacNumber))
                    {
                        registrations = registrations.Where(s => s.CacNumber.ToLower().Contains(search.CacNumber.ToLower())).ToList();
                    }

                    if (!String.IsNullOrEmpty(search.Location))
                    {
                        registrations = registrations.Where(s => s.CacNumber.ToLower().Contains(search.Location.ToLower())).ToList();
                    }

                    registrations = registrations.Where(s => s.RegistrationDate >= search.RegistrationDateFrom.DayMin()).ToList();

                    if (search.RegistrationDateTo.Equals(DateTime.MinValue))
                    {
                        registrations = registrations.Where(s => s.RegistrationDate <= DateTime.MaxValue).ToList();
                    }
                    else
                    {
                        registrations = registrations.Where(s => s.RegistrationDate <= search.RegistrationDateTo.DayMax()).ToList();
                    }

                    /*
                     *                  registrations = registrations.Where(s => s.LastRenewalDate >= search.LastRenewalDateFrom.DayMin()).ToList();
                     *
                     *                  if (search.LastRenewalDateTo.Equals(DateTime.MinValue))
                     *                  {
                     *                          registrations = registrations.Where(s => s.LastRenewalDate <= DateTime.MaxValue).ToList();
                     *                  }
                     *                  else
                     *                  {
                     *                          registrations = registrations.Where(s => s.LastRenewalDate <= search.LastRenewalDateTo.DayMax()).ToList();
                     *                  }*/

                    registrations.ForEach(x =>
                    {
                        //if (x.State != null) x.State.Locations = null;
                    });

                    return(Content(WebApiHelper.ObjectToJsonString(registrations), "application/json"));
                }
            }
        }
Ejemplo n.º 2
0
		public ActionResult Establishment(EstablishmentSearch search)
		{
			using (var session = NHibernateHelper.CreateSessionFactory())
			{
				using (var transaction = session.BeginTransaction())
				{
					var registrations = new List<Registration>(session.CreateCriteria(typeof(Registration)).List<Registration>());

					if (!String.IsNullOrEmpty(search.EstablishmentName))
					{
						registrations = registrations.Where(s => s.EstablishmentName.ToLower().Contains(search.EstablishmentName.ToLower())).ToList();
					}

					if (!String.IsNullOrEmpty(search.PhermcRegistrationNumber))
					{
						registrations = registrations.Where(s => s.PhermcRegistrationNumber.ToLower().Contains(search.PhermcRegistrationNumber.ToLower())).ToList();
					}

					if (!String.IsNullOrEmpty(search.CacNumber))
					{
						registrations = registrations.Where(s => s.CacNumber.ToLower().Contains(search.CacNumber.ToLower())).ToList();
					}

					if (!String.IsNullOrEmpty(search.Location))
					{
						registrations = registrations.Where(s => s.CacNumber.ToLower().Contains(search.Location.ToLower())).ToList();
					}

					registrations = registrations.Where(s => s.RegistrationDate >= search.RegistrationDateFrom.DayMin()).ToList();

					if (search.RegistrationDateTo.Equals(DateTime.MinValue))
					{
						registrations = registrations.Where(s => s.RegistrationDate <= DateTime.MaxValue).ToList();
					}
					else
					{
						registrations = registrations.Where(s => s.RegistrationDate <= search.RegistrationDateTo.DayMax()).ToList();
					}

                    /*
					registrations = registrations.Where(s => s.LastRenewalDate >= search.LastRenewalDateFrom.DayMin()).ToList();

					if (search.LastRenewalDateTo.Equals(DateTime.MinValue))
					{
						registrations = registrations.Where(s => s.LastRenewalDate <= DateTime.MaxValue).ToList();
					}
					else
					{
						registrations = registrations.Where(s => s.LastRenewalDate <= search.LastRenewalDateTo.DayMax()).ToList();
					}*/

					registrations.ForEach(x =>
						{
							//if (x.State != null) x.State.Locations = null;
						});

					return Content(WebApiHelper.ObjectToJsonString(registrations), "application/json");

				}
			}
		}