示例#1
0
        public async Task <IActionResult> Update(int id, [FromBody] UpdateDeviceRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                await _devicesRepository.Update(id, request);

                return(NoContent());
            }
            catch (InvalidDeviceException)
            {
                return(NotFound());
            }
            catch (InvalidOfficeException)
            {
                string errorText = String.Format("Office with ID: {0} doesn't exist", request.OfficeId);
                return(StatusCode(StatusCodes.Status409Conflict, new { Message = errorText }));
            }
            catch (InvalidBrandException)
            {
                string errorText = String.Format("Brand with ID: {0} doesn't exist", request.BrandId);
                return(StatusCode(StatusCodes.Status409Conflict, new { Message = errorText }));
            }
            catch (InvalidModelException)
            {
                string errorText = String.Format("Model with ID: {0} doesn't exist", request.ModelId);
                return(StatusCode(StatusCodes.Status409Conflict, new { Message = errorText }));
            }
            catch (DuplicateDeviceSerialNumberException)
            {
                string errorText = String.Format("Device with Serial number: {0} already exist", request.SerialNum);
                return(StatusCode(StatusCodes.Status409Conflict, new { Message = errorText }));
            }
            catch (DuplicateModelException)
            {
                string errorText = String.Format("Model with name: {0} already exist", request.ModelName);
                return(StatusCode(StatusCodes.Status409Conflict, new { Message = errorText }));
            }
            catch (DuplicateDeviceIdentificationNumberException)
            {
                string errorText = String.Format("Device with identification number: {0} already exist", request.IdentificationNum);
                return(StatusCode(StatusCodes.Status409Conflict, new { Message = errorText }));
            }
        }
        public async Task <IActionResult> Put([FromBody] Device device)
        {
            var response = await devicesRepository.Update(device);

            // Notify clients in the group
            await this.hubContext.Clients.Group(device.UserEmail).DeviceIsOnChange(response);

            // Notify every client
            await this.hubContext.Clients.All.DeviceStatusChange(response.Id, response.UserEmail, response.IsOn);

            return(Ok(new
            {
                correct = true,
                title = "Mensaje del sistema",
                message = "Dispositivo actualizado correctamente",
                deviceData = response,
                fullStackTrace = "",
            }));
        }
示例#3
0
        public JsonResult Put(Devices devices)
        {
            if (!ModelState.IsValid)
            {
                return(JsonResponse(ResponseType.error, ValidationErrors()));
            }

            try
            {
                devicesRepository.Update(devices);
                devicesRepository.SaveChanges();
                return(JsonResponse(ResponseType.success, ResponseMessage.ChangesSaved));
            }
            catch (DuplicateItemException die)
            {
                return(JsonResponse(ResponseType.error, die.Message));
            }
            catch (Exception ex)
            {
                return(InternalException(ex));
            }
        }
示例#4
0
 public async Task <EntityState> Update(Device device)
 {
     return(await _devicesRepository.Update(device));
 }