Пример #1
0
        public BaseResponse SaveSOSData(SOSFileter sos)
        {
            var          watchFlag = Enum.GetName(typeof(DeviceType), DeviceType.Watch);
            var          sosdata   = JsonConvert.DeserializeObject <SOSDataModel>(sos.data);
            BaseResponse res       = new BaseResponse();
            var          m         = from r in unitOfWork.GetRepository <DC_Resident>().dbSet
                                     join p in unitOfWork.GetRepository <DC_Person>().dbSet on r.PersonID equals p.PersonID
                                     join q in unitOfWork.GetRepository <DC_Device>().dbSet.Where(a => a.DeviceType == watchFlag) on p.PersonID equals q.PersonID
                                     where q.DeviceNo == sosdata.IMEI
                                     select r;

            if (!m.Any())
            {
                return(res);
            }
            try
            {
                var sosRepository = unitOfWork.GetRepository <DC_SOSData>();
                var saveModel     = sosRepository.dbSet.Where(it => it.IMEI == sosdata.IMEI).FirstOrDefault();
                if (saveModel == null)
                {
                    saveModel = Mapper.DynamicMap <DC_SOSData>(sosdata);
                    sosRepository.Insert(saveModel);
                }
                else
                {
                    saveModel.EmgDate = sosdata.EmgDate;
                    saveModel.Address = sosdata.Address;
                    saveModel.Lng     = sosdata.Lng;
                    saveModel.Lat     = sosdata.Lat;
                    saveModel.Hpe     = sosdata.Hpe;
                    saveModel.Method  = sosdata.Method;
                    sosRepository.Update(saveModel);
                }

                unitOfWork.Save();
            }catch (Exception ex) {
                res.IsSuccess     = false;
                res.ResultMessage = "已接收,但是未保存成功。";
            }

            return(res);
        }
        public IHttpActionResult SaveSOSData([FromBody] SOSFileter data)
        {
            var response = service.SaveSOSData(data);

            return(Ok(response));
        }