コード例 #1
0
        public IHttpActionResult PostHardwareType(HardwareTypeDto hardwareTypeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var hardwareType = Mapper.Map <HardwareTypeDto, HardwareType>(hardwareTypeDto);

            hardwareType = _repository.Create(hardwareType);

            return(CreatedAtRoute("HardwareApi", new { id = hardwareType.Id }, hardwareTypeDto));
        }
コード例 #2
0
        /// <summary>
        /// 获取设备SN 并返回是否可以添加以及设备硬件类型 CheckDeviceBySN
        /// </summary>
        /// <param name="SerialNumber">SN码</param>
        /// <param name="isExist">1已存在 0不存在</param>
        /// <param name="online">设备是否在线</param>
        /// <param name="hardwareType">硬件类型</param>
        /// <returns></returns>
        public ResponseBaseDto CheckDeviceBySN(string serialNumber, ref int isEnable, ref int isOnline, ref int hardwareType)
        {
            ResponseBaseDto dto = new ResponseBaseDto();

            try
            {
                IList <Device> deviceFlag =
                    deviceServer.SelectDeviceSerialNumber(new Device()
                {
                    SerialNumber = serialNumber
                });
                if (deviceFlag != null && deviceFlag.Count != 0)
                {
                    isEnable     = 0;//设备已存在,不可用
                    hardwareType = deviceFlag[0].HardwareType;
                    dto.Code     = (int)CodeEnum.Success;
                    dto.Message  = "SN已验证完毕!";
                    return(dto);
                }
                else
                {
                    //向BP4Server请求SN码
                    Bsr.ServiceProxy.Utils.ServiceFactory serviceFactory = new ServiceProxy.Utils.ServiceFactory();
                    string          seviceAddr = bllHelper.GetServerModelStr();
                    HardwareTypeDto htDto      = new HardwareTypeDto();
                    htDto.IsOnline = 0;
                    htDto.Type     = HardwareType.Unknown;
                    serviceFactory.GetProxy <IDevice>(new Uri(seviceAddr)).Use(
                        p =>
                    {
                        htDto = p.GetHardwareTypeBySerialNumber(serialNumber);
                    }
                        );
                    if (htDto.IsOnline != 0)
                    {
                        isEnable     = 1;
                        isOnline     = htDto.IsOnline;
                        hardwareType = (int)htDto.Type;
                    }
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.ErrorFormat("GetDeviceBySN方法异常,设备serialNumber:{0}", ex, serialNumber);
            }
            return(dto);
        }
コード例 #3
0
        public IHttpActionResult PutHardwareType(int id, HardwareTypeDto hardwareTypeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var hardwareType = _repository.Get(id);

            if (hardwareType == null)
            {
                return(NotFound());
            }

            if (id != hardwareType.Id)
            {
                return(BadRequest());
            }

            Mapper.Map(hardwareTypeDto, hardwareType);
            hardwareType = _repository.Update(hardwareType);

            return(StatusCode(HttpStatusCode.NoContent));
        }