Beispiel #1
0
        public Data.FootPrint GetRandomUnverifiedFootPrint()
        {
            var result = new Data.FootPrint();
            var source = _FootPrintRepository.Entities.AsNoTracking().Where(p => p.state == FootPrintState.None && p.isEnable);

            if (source.Any())
            {
                var pids   = source.Select(p => p.pid).ToArray();
                var Seed   = Guid.NewGuid().GetHashCode();
                var random = new Random(Seed);
                int index  = random.Next(0, pids.Length); //生成随机下标
                var pid    = pids[index];
                result = source.FirstOrDefault(p => p.pid == pid);
            }
            else
            {
                result = null;
            }
            return(result);
        }
Beispiel #2
0
        public IFootPrintService SaveFootPrint()
        {
            //Init();
            InitFootLocation();
            InitAreaNo();
            if (string.IsNullOrWhiteSpace(_AreaNo))
            {
                _AreaNo = "0001";
            }
            var now = DateTime.Now;
            IFootPrintService service = null;

            using (var scope = new TransactionScope())
            {
                Data.FootPrint entity = null;
                if (_Fid > 0)
                {
                    entity = _FootPrintRepository.Entities.FirstOrDefault(p => p.fid == _Fid);
                    ExceptionHelper.ThrowIfTrue(entity.uid != _Uid, "uid", "用户不允许修改他人的足迹");
                    ExceptionHelper.ThrowIfTrue(entity.state == FootPrintState.Pass, "", "已通过的足迹不能修改");
                }
                if (entity == null)
                {
                    entity = _FootPrintRepository.Add(new Data.FootPrint()
                    {
                        uid          = _Uid,
                        created      = now,
                        isEnable     = true,
                        state        = FootPrintState.None,
                        orderUpdated = now,
                    });
                }
                if (entity.pid != ProjectSource.pid)
                {
                    entity.pid = ProjectSource.pid;
                }
                if (!string.IsNullOrWhiteSpace(_Address) && _Address != entity.address)
                {
                    entity.address = _Address;
                }
                if (!string.IsNullOrWhiteSpace(_Content))
                {
                    entity.content = _Content;
                }
                if (_Latitude > 0 && _Longitude > 0 && (_Latitude != entity.latitude || _Longitude != entity.longitude))
                {
                    entity.latitude  = _Latitude;
                    entity.longitude = _Longitude;
                    if (!string.IsNullOrWhiteSpace(_AreaNo) && _AreaNo != "0001")
                    {
                        entity.areaNo = _AreaNo;
                    }
                }
                if (!string.IsNullOrWhiteSpace(_AreaNo) && string.IsNullOrWhiteSpace(entity.areaNo))
                {
                    entity.areaNo = _AreaNo;
                }
                entity.updated = now;
                _FootPrintRepository.SaveChanges();
                service = _FootPrintServiceFactory.GetService(entity.fid);
                service.UpdateImages(_Image);
                service.UpdateTags(_Tags);
                if (entity.state == FootPrintState.UnPass)
                {
                    entity.state = FootPrintState.None;
                }
                _FootPrintRepository.SaveChanges();


                scope.Complete();
            }
            return(service);
        }