コード例 #1
0
 public IActionResult UpdateConnectedDeviceType(string deviceTypeId, [FromBody] ConnectedDeviceType updateConnectedDeviceType)
 {
     if (updateConnectedDeviceType == null)
     {
         return(BadRequest(ModelState));
     }
     if (deviceTypeId != updateConnectedDeviceType.Id)
     {
         return(BadRequest(ModelState));
     }
     if (!connectedDeviceTypeRepository.ConnectedDeviceTypeExists(deviceTypeId))
     {
         return(NotFound());
     }
     if (connectedDeviceTypeRepository.IsDuplicatedConnectedDeviceTypeName(deviceTypeId, updateConnectedDeviceType.Name))
     {
         ModelState.AddModelError("", $"Device Type {updateConnectedDeviceType.Name} already exists");
         return(StatusCode(422, ModelState));
     }
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     connectedDeviceTypeRepository.UpdateConnectedDeviceType(deviceTypeId, updateConnectedDeviceType);
     return(Ok("Update Success"));
 }
コード例 #2
0
        public IActionResult CreateConnectedDeviceType([FromBody] ConnectedDeviceType connectedDeviceType)
        {
            if (connectedDeviceType == null)
            {
                return(BadRequest(ModelState));
            }
            if (connectedDeviceTypeRepository.ConnectedDeviceTypeExists(connectedDeviceType.Id) == true)
            {
                ModelState.AddModelError("", $"Device Type Id {connectedDeviceType.Id} already exists");
                return(StatusCode(422, ModelState));
            }
            bool isDuplicated = connectedDeviceTypeRepository.IsDuplicatedConnectedDeviceTypeName(connectedDeviceType.Id, connectedDeviceType.Name);

            if (isDuplicated == true)
            {
                ModelState.AddModelError("", $"Device Type Name {connectedDeviceType.Name} already exists");
                return(StatusCode(422, ModelState));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            connectedDeviceTypeRepository.CreateConnectedDeviceType(connectedDeviceType);
            return(Ok("Create Success"));
        }
コード例 #3
0
        public bool IsDuplicatedConnectedDeviceTypeName(string connectedDeviceTypeId, string connectedDeviceTypeName)
        {
            ConnectedDeviceType connectedDeviceType = connectedDeviceTypes.AsQueryable().Where(connectedDeviceType => connectedDeviceType.Id != connectedDeviceTypeId &&
                                                                                               connectedDeviceType.Name.ToLower() == connectedDeviceTypeName.ToLower()).FirstOrDefault();

            return(connectedDeviceType == null ? false : true);
        }
コード例 #4
0
        public IActionResult GetConnectedDeviceType(string deviceTypeId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!connectedDeviceTypeRepository.ConnectedDeviceTypeExists(deviceTypeId))
            {
                return(NotFound());
            }
            ConnectedDeviceType connectedDeviceType = connectedDeviceTypeRepository.GetConnectedDeviceType(deviceTypeId);

            return(Ok(connectedDeviceType));
        }
コード例 #5
0
 public void UpdateConnectedDeviceType(string connectedDeviceTypeId, ConnectedDeviceType updateConnectedDeviceType)
 {
     connectedDeviceTypes.ReplaceOne(connectedDeviceType => connectedDeviceType.Id == connectedDeviceTypeId, updateConnectedDeviceType);
 }
コード例 #6
0
 public void CreateConnectedDeviceType(ConnectedDeviceType connectedDeviceType)
 {
     connectedDeviceTypes.InsertOne(connectedDeviceType);
 }