示例#1
0
        public async Task <DeviceAddResultModel> AddAsync([NotNull] DeviceAddModel model, [NotNull] string appId,
                                                          [NotNull] string appKey)
        {
            var appInfo = new ElectOneSignalAppOption(appId, appKey);

            return(await AddAsync(model, appInfo));
        }
示例#2
0
        public async Task <DeviceAddResultModel> AddAsync([NotNull] DeviceAddModel model,
                                                          [NotNull] ElectOneSignalAppOption appInfo)
        {
            model.AppId = appInfo.AppId;

            try
            {
                var result =
                    await ElectOneSignalConstants.DefaultApiUrl
                    .ConfigureRequest(config =>
                {
                    config.JsonSerializer = ElectOneSignalConstants.NewtonsoftJsonSerializer;
                })
                    .AppendPathSegment("players")
                    .WithHeader("Authorization", $"Basic {appInfo.ApiKey}")
                    .PostJsonAsync(model)
                    .ReceiveJson <DeviceAddResultModel>()
                    .ConfigureAwait(true);

                return(result);
            }
            catch (FlurlHttpException e)
            {
                var response = await e.GetResponseStringAsync().ConfigureAwait(true);

                throw new HttpRequestException(response);
            }
        }
示例#3
0
        public IActionResult Add()
        {
            var model = new DeviceAddModel()
            {
            };

            return(View(model));
        }
示例#4
0
 public static DeviceAddDomainModel RequestToDomain(this DeviceAddModel @this)
 {
     return(new DeviceAddDomainModel
     {
         name = @this.name,
         serial_number = @this.serial_number,
         type = @this.type
     });
 }
示例#5
0
        public async Task <IActionResult> AddDevice(string user_id, [FromBody] DeviceAddModel model)
        {
            var response = await GetResultAsync <bool>(
                getItem : async() => await _deviceService.AddDeviceAsync(model.RequestToDomain()),
                modelState : ModelState
                );

            return(Result(response));
        }
示例#6
0
        public async Task <IActionResult> AddAsync([FromBody] DeviceAddModel mDevice)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelStateError()));
            }

            var deviceId = await _deviceRepository.AddAsync(mDevice);

            return(CreatedAtRoute("GetByDeviceIdAsync", new { controller = "Devices", deviceId = deviceId }, mDevice));
        }
示例#7
0
 //
 // GET: /Device/Add/<SiteId>
 public ActionResult Add(int SiteId)
 {
     try
     {
         var            provider = new SiteProvider(DomainSession.GetDataContextForUserContext(this.HttpContext));
         DeviceAddModel model    = new DeviceAddModel(provider.GetById(SiteId));
         return(View(model));
     }
     catch (Exception e)
     {
         return(View());
     }
 }
示例#8
0
 public async Task <ActionResult> Add(DeviceAddModel model)
 {
     try
     {
         var provider = new DeviceProvider(DomainSession.GetDataContextForUserContext(this.HttpContext));
         model.Result = StatusResponseGenerator.GetStatusResponseResultForReturnParam(provider.Add(model.Device, model.LocationId, model.TypeId, model.DeviceSiteId));
         return(View(model));
     }
     catch (Exception e)
     {
         return(View());
     }
 }
示例#9
0
        public int Add(DeviceAddModel mDevice)
        {
            var model = new Device
            {
                Voltage  = mDevice.Voltage,
                Diameter = mDevice.Diameter,
                Torque   = mDevice.Torque,
            };

            _context.Devices.Add(model);

            _context.SaveChanges();
            return(model.DeviceId);
        }
示例#10
0
        public async Task <int> AddAsync(DeviceAddModel mDevice)
        {
            var model = new Device
            {
                Voltage  = mDevice.Voltage,
                Diameter = mDevice.Diameter,
                Torque   = mDevice.Torque,
            };

            _context.Devices.Add(model);

            await _context.SaveChangesAsync();

            return(model.DeviceId);
        }
示例#11
0
        public IActionResult Add(DeviceAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { state = "error", data = "提交信息验证失败" }));
            }

            try
            {
                var dal = new DeviceDal();
                var p   = mapper.Map <DeviceDefinition>(model);
                dal.Add(p);
                return(Json(new { state = "ok", data = 1 }));
            }
            catch (Exception ex)
            {
                return(Json(new { state = "error", data = ex.Message }));
            }
        }
示例#12
0
        public async Task <DeviceAddResultModel> AddAsync([NotNull] DeviceAddModel model, [NotNull] string appId)
        {
            var appInfo = Options.Apps.Single(x => x.AppId == appId);

            return(await AddAsync(model, appInfo));
        }