/// <summary> /// Find a StandardAppointment by specifying values for the properties available in the request. /// Date values: Start date will go from date forward, end date will be from end date back, and if both has values, /// it will be used as from (between) start to end /// </summary> /// <param name="request">The request used for building the find parameters</param> /// <returns>If LoadLazy was true, then a list of JarsStandardAppointmentBase items, otherwise a list of fully loaded JarsStandardAppointments</returns> public virtual StandardAppointmentsResponse Any(FindStandardAppointments request) { return(ExecuteFaultHandledMethod(() => { StandardAppointmentsResponse response = new StandardAppointmentsResponse(); if (request != null) { var query = BuildQuery <StandardAppointment>(request); //var _repository = _DataRepositoryFactory.GetDataRepository<IStandardAppointmentRepository>(); var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <StandardAppointment, IDataContextNhJars> >(); IList <StandardAppointment> list = _repository.Where(query, true); response.Appointments = list.ToStandardAppointmentDtoList().ToList(); } return response; })); }
/// <summary> /// A helper method used for building the query, depending on if the LoadLazy option was set. /// </summary> /// <typeparam name="T">A query over object required by the QueryOver Method on the repository</typeparam> /// <param name="request">The same request passed into the service</param> /// <param name="hasWhere">a bool value indicating if there is a where string</param> /// <returns></returns> private Expression <Func <T, bool> > BuildQuery <T>(FindStandardAppointments request) where T : StandardAppointment { Expression <Func <T, bool> > query = LinqExpressionBuilder.True <T>(); //the default value of loading recurring appointments will always be added. query = query.Or(a => a.RecurrenceInfo != null); //StartDateTime if (request.FromStartDate.HasValue && request.FromStartDate != DateTime.MinValue) { query = query.And(a => a.StartDate >= request.FromStartDate); } //EndDateTime if (request.ToEndDate.HasValue && request.ToEndDate != DateTime.MinValue) { query = query.And(a => a.EndDate <= request.ToEndDate); } //resourcelist if (!request.InCalendarForResources.IsNullOrEmpty()) { string[] resIds = request.InCalendarForResources.Split(','); query = query.And(a => resIds.Contains(a.ResourceId.ToString())); } //with description like if (request.WithAppointmentDescription != null && request.WithAppointmentDescription != string.Empty) { query = query.And(a => a.Subject.Contains(request.WithAppointmentDescription) || a.Description.Contains(request.WithAppointmentDescription)); } //Id if (request.Id != 0) { query = query.And(a => a.Id == request.Id); } return(query); }