Пример #1
0
        /// <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;
            //}
        }
Пример #2
0
        /// <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;
            //}
        }