/// <summary>
        ///添加安装位置
        /// </summary>
        /// <param name="PositionRequest"></param>
        /// <returns></returns>
        public BasicResponse AddPosition(PositionAddRequest PositionRequest)
        {
            BasicResponse Result  = new BasicResponse();
            Jc_WzInfo     item    = PositionRequest.PositionInfo;
            Jc_WzInfo     olditem = null;

            PositionCacheGetByKeyRequest positionCacheRequest = new PositionCacheGetByKeyRequest();

            positionCacheRequest.PositionId = item.ID;
            var result = _PositionCacheService.GetPositionCacheByKey(positionCacheRequest);

            olditem = result.Data;

            //增加重复判断
            if (result.Data != null)
            { //缓存中存在此测点
                Result.Code    = 1;
                Result.Message = "当前添加的安装位置已存在!";
                return(Result);
            }
            //保存数据库
            var _jc_Wz      = ObjectConverter.Copy <Jc_WzInfo, Jc_WzModel>(PositionRequest.PositionInfo);
            var resultjc_Wz = _Repository.AddPosition(_jc_Wz);

            //保存缓存
            PositionCacheAddRequest AddPositionCacheRequest = new PositionCacheAddRequest();

            AddPositionCacheRequest.PositionInfo = item;
            _PositionCacheService.AddPositionCache(AddPositionCacheRequest);

            return(Result);
        }
Exemple #2
0
        public IActionResult Position([FromBody] PositionDTO position)
        {
            if (position == null)
            {
                throw new ArgumentNullException(nameof(position));
            }
            if (!positionRepository.AddPosition(position))
            {
                return(BadRequest("Position couldn't be saved"));
            }
            foreach (KeyValuePair <string, DateTime> pair in new Dictionary <string, DateTime>(CesiumHub.ClientsActive))
            {
                if (pair.Value != DateTime.MinValue && (DateTime.Now - pair.Value).TotalMinutes > 10)
                {
                    CesiumHub.ClientsActive[pair.Key] = DateTime.MinValue;
                    CesiumHub.ClientsConnections.Remove(pair.Key);
                    wsContext.Clients.All.SendAsync("InactiveUser", pair.Key);
                }
            }
            if (CesiumHub.ClientsActive.GetValueOrDefault(position.Name, DateTime.MinValue) == DateTime.MinValue)
            {
                CesiumHub.ClientsActive[position.Name] = position.Time;
                wsContext.Clients.All.SendAsync("NewActiveUser", position.Name);
            }

            var nearArtifacts = artifactRepository.GetWonArtifacts(position.Longitude, position.Latitude, position.Time);

            if (nearArtifacts.Count > 0)
            {
                foreach (var artifact in nearArtifacts)
                {
                    wsContext.Clients.All.SendAsync("ArtifactWon", artifact.Id.ToString());
                }
                artifactRepository.GivePoints(nearArtifacts.Count, position.Name);
            }


            wsContext.Clients.Group(position.Name).SendAsync("Position", position.Name, position.Latitude, position.Longitude);
            return(Ok());
        }
Exemple #3
0
 public void AddPosition(PositionCreateModel position)
 {
     position.Created   = _dateTime.Now;
     position.CreatedBy = _currentUserService.Username;
     _positionRepository.AddPosition(position);
 }