/// <summary> /// Send CRUD notifications for an Entity or Entities /// Note! : /// If the service does not implement serverEvents this will throw an error. /// This will send a notification to all subscribed clients (including the client the request originated from) where the chanel name is the name of the entity type. /// This will only process SelectorTypes.store and SelectorTypes.delete notifications. /// The notification sent to subscribers will be a ServerEventMessage (serviceStack) where the data(json) is set as ServerEventMessageData (Jars) object. /// </summary> /// <param name="crud">The notification request indicating a store or delete event that will be sent to other subscribers.</param> public virtual void Any(JarsDefaultAppointmentNotification crud) { //ExecuteFaultHandledMethod(() => //{ //check that the sender has subscribed to the service //SubscriptionInfo subscriber = ServerEvents.GetSubscriptionInfo(crud.From); List <SubscriptionInfo> subscriber = ServerEvents.GetSubscriptionInfosByUserId(crud.FromUserName); if (subscriber == null) { throw HttpError.NotFound($"Subscriber {crud.FromUserName} does not exist."); } //do some job updates here using the info from the the crud IGenericEntityRepositoryBase <JarsDefaultAppointment, IDataContextNhJars> _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <JarsDefaultAppointment, IDataContextNhJars> >(); if (crud.Selector == SelectorTypes.store) { List <JarsDefaultAppointmentDto> storeList = _repository.Where(a => crud.Ids.Contains(a.Id)).ConvertAllTo <JarsDefaultAppointmentDto>().ToList(); TrySendStoreNotificationToChannel(typeof(JarsDefaultAppointment).Name, storeList.ToJson()); } if (crud.Selector == SelectorTypes.delete) { TrySendDeleteNotificationToChannel(typeof(JarsDefaultAppointment).Name, crud.Ids.ConvertTo <List <string> >().ToArray());//, true); } //}); }
public void query_information_using_queryover_method_generic_repositories() { IGenericEntityRepositoryBase <JarsJob, IDataContextNhJars> jarsRepo = _repFactory.GetDataRepository <IGenericEntityRepositoryBase <JarsJob, IDataContextNhJars> >(); IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> extRepo = _repFactory.GetDataRepository <IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> >(); //var jQry = QueryOver.Of<JarsJob>().Where(j => j.Id > 0).And(j => j.CreatedBy.IsLike("MEF",MatchMode.Anywhere)).OrderBy(j => j.CreatedDate).Asc; //IList<JarsJob> jList = jarsRepo.QueryOverOf(jQry); IList <JarsJob> jList = jarsRepo.Where(j => j.Id > 0 && j.CreatedBy.IsLike("MEF", MatchMode.Anywhere)).OrderBy(j => j.CreatedBy).ToList(); Assert.IsTrue(jList.Count > 0); jList = jarsRepo.Where(j => j.Id > 1 && j.Id < 3); Assert.IsTrue(jList.Count == 1); //var xQry = QueryOver.Of<ExternalJobHeader>().Where(j => j.Id > 0).And(j => j.ExtRefID == "123").OrderBy(j => j.Priority).Desc; IList <BOSEntity> xList = extRepo.Where(j => j.Id > 0 && j.ExtRefId == "123").OrderByDescending(j => j.Priority).ToList(); Assert.IsTrue(xList.Count > 0); }
/// <summary> /// Send CRUD notifications for a BOSRecord Entity or Entities /// Note! : /// This Method is a special method used by the service when ServerEvents are being used.(serviceStack). /// If the service does not implement serverEvents this will throw an error. /// This will send a notification to all subscribed clients (including the client the request originated from) where the chanel name is the name of the entity type. /// This will only process SelectorTypes.store and SelectorTypes.delete notifications. /// The notification sent to subscribers will also be a JarsSyncEventStore or JarsSyncEventStore Dto object. /// </summary> /// <param name="crud">The notification request indicating a store or delete event that will be sent to other subscribers.</param> public virtual void Any(BOSEntitiesNotification crud) { //do some BOSRecord updates here using the info from the the crud IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> >(); if (crud.Selector == SelectorTypes.store) { List <BOSEntityDto> notifyList = _repository.Where(d => crud.Ids.Contains(d.Id)).ConvertAllTo <BOSEntityDto>().ToList(); TrySendStoreNotificationToChannel(typeof(BOSEntity).Name, notifyList.ToJson()); } if (crud.Selector == SelectorTypes.delete) { TrySendDeleteNotificationToChannel(typeof(BOSEntity).Name, crud.Ids.ConvertTo <List <string> >().ToArray());//, true); } }
/// <summary> /// Find a list of appointments depending on the criteria given in the Find request. /// If the request does not contain any values for filtering all the records will be returned. /// </summary> /// <param name="request">The request containing the search criteria.</param> /// <returns>a list of StandardAppointmentDefault entities.</returns> public JarsDefaultAppointmentsResponse Any(FindJarsDefaultAppointments request) { IGenericEntityRepositoryBase <JarsDefaultAppointment, IDataContextNhJars> repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <JarsDefaultAppointment, IDataContextNhJars> >(); JarsDefaultAppointmentsResponse response = new JarsDefaultAppointmentsResponse(); if (request.DescriptionLike != null) { response.Appointments = repository.Where(d => d.Description.IsLike(request.DescriptionLike)).ToList().ConvertAll(s => s.ConvertTo <JarsDefaultAppointmentDto>()); } else { response.Appointments = repository.GetAll().ToList().ConvertAll(s => s.ConvertTo <JarsDefaultAppointmentDto>()); } return(response); }
/// <summary> /// Find a BOSRecord 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 JarsBOSRecordBase items, otherwise a list of fully loaded JarsBOSRecords</returns> public virtual BOSEntitiesResponse Any(FindBOSEntities request) { BOSEntitiesResponse response = new BOSEntitiesResponse(); if (request != null) { Expression <Func <BOSEntity, bool> > query = LinqExpressionBuilder.True <BOSEntity>(); //Id if (request.ResourceId != null) { query = query.And(a => a.ResourceId == int.Parse(request.ResourceId)); } //StartDateTime if (request.StartDate.HasValue && request.StartDate != DateTime.MinValue) { query = query.And(a => a.StartDate.Date >= request.StartDate.Value.Date); } //EndDateTime (unlike the mobile version we dont set the end date = start date if the end date is empty) if (request.EndDate.HasValue && request.EndDate != DateTime.MinValue) { query = query.And(a => a.EndDate.Date <= request.EndDate.Value.Date); } //statuses if (!request.Statuses.IsNullOrEmpty()) { //if the status value contains a , then split it, otherwise just use as is if (request.Statuses.Contains(',')) { string[] arrStatus = request.Statuses.Split(new[] { ',' }); query = query.And(a => arrStatus.Contains(a.ProgressStatus)); } else { query = query.And(a => a.ProgressStatus == request.Statuses); } } IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> >(); response.BOSEntities = _repository.Where(query, true).ConvertAllTo <BOSEntityDto>().ToList(); } return(response); }
/// <summary> /// Update or create a single BOSRecord or a list of BOSRecords, depending on whether the BOSRecord or BOSRecords property has got a value set. /// If the BOSRecord property is set the BOSRecord will be created or updated and the BOSRecords property will be ignored. /// To create or update more than one BOSRecord, assign a list to the BOSRecords property and make sure BOSRecord is set to nothing/null. /// </summary> /// <param name="request">The request containing the BOSRecord or BOSRecords that needs to be created or updated</param> /// <returns>depending on the values supplied, the updated BOSRecord or BOSRecords will be returned.</returns> public virtual object Any(StoreMobileBOSEntities request) { MobileBOSEntitiesResponse response = new MobileBOSEntitiesResponse(); if (request.BOSEntities.Any()) { IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> >(); List <int> ids = request.BOSEntities.Select(e => e.Id).ToList(); IList <BOSEntity> oldies = _repository.Where(e => ids.Contains(e.Id)).ToList(); foreach (var reqEntity in request.BOSEntities) { BOSEntity old = oldies.SingleOrDefault(o => o.Id == reqEntity.Id); if (old != null) { old.PopulateWith(reqEntity); } } List <BOSEntity> updtList = _repository.CreateUpdateList(oldies, CurrentSessionUsername).ToList(); response.BOSEntities = updtList.ConvertAllTo <MobileBOSEntityDto>().ToList(); TrySendStoreNotificationToChannel(typeof(BOSEntity).Name, updtList.ToJson()); //response.BOSEntities = _repository.MergeList(request.BOSEntities.ConvertAllTo<BOSEntity>().ToList(), CurrentSessionUsername).ConvertAllTo<MobileBOSEntityDto>().ToList(); } return(new HttpResult(response) { ResultScope = () => JsConfig.With(new Config { DateHandler = DateHandler.ISO8601 }) }); //using (JsConfig.With(new Config { DateHandler = DateHandler.ISO8601 })) //{ // return response; //} }
/// <summary> /// Find a BOSRecord 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 JarsBOSRecordBase items, otherwise a list of fully loaded JarsBOSRecords</returns> public virtual object Any(FindMobileBOSEntities request) { //https://github.com/ServiceStack/ServiceStack.Text#global-default-json-configuration MobileBOSEntitiesResponse response = new MobileBOSEntitiesResponse(); if (request != null) { Expression <Func <BOSEntity, bool> > query = LinqExpressionBuilder.True <BOSEntity>(); //Id if (request.ResourceId != null) { query = query.And(a => a.ResourceId == int.Parse(request.ResourceId)); } //StartDateTime if (request.StartDate.HasValue && request.StartDate != DateTime.MinValue) { query = query.And(a => a.StartDate.Date >= request.StartDate.Value.Date); } //EndDateTime if (request.EndDate.HasValue && request.EndDate != DateTime.MinValue) { query = query.And(a => a.EndDate.Date <= request.EndDate.Value.Date); } else { //set end date to start date so that we only get one day by default if (request.StartDate.HasValue && request.StartDate != DateTime.MinValue) { query = query.And(a => a.EndDate.Date <= request.StartDate.Value.Date); } } //statuses if (!request.Statuses.IsNullOrEmpty()) { //if the status value contains a , then split it, otherwise just use as is if (request.Statuses.Contains(',')) { string[] arrStatus = request.Statuses.Split(new[] { ',' }); query = query.And(a => arrStatus.Contains(a.ProgressStatus)); } else { query = query.And(a => a.ProgressStatus == request.Statuses); } } IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> >(); response.BOSEntities = _repository.Where(query, true).ConvertAllTo <MobileBOSEntityDto>().ToList(); } return(new HttpResult(response) { ResultScope = () => JsConfig.With(new Config { AssumeUtc = true, DateHandler = DateHandler.ISO8601DateTime }) }); //using (JsConfig.With(new Config { DateHandler = DateHandler.ISO8601 })) //{ // return response; //} }