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")); }
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")); }
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); }
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)); }
public void UpdateConnectedDeviceType(string connectedDeviceTypeId, ConnectedDeviceType updateConnectedDeviceType) { connectedDeviceTypes.ReplaceOne(connectedDeviceType => connectedDeviceType.Id == connectedDeviceTypeId, updateConnectedDeviceType); }
public void CreateConnectedDeviceType(ConnectedDeviceType connectedDeviceType) { connectedDeviceTypes.InsertOne(connectedDeviceType); }