public Entity.DeviceType Get(Guid id) { try { Entity.DeviceType response = _deviceTypeRepository.FindBy(r => r.Guid == id).Select(p => Mapper.Configuration.Mapper.Map <Entity.DeviceType>(p)).FirstOrDefault(); return(response); } catch (Exception ex) { _logger.Error(Constants.ACTION_EXCEPTION, "DeviceTypeService.Get " + ex); return(null); } }
public Entity.ActionStatus Delete(Guid id) { Entity.ActionStatus actionStatus = new Entity.ActionStatus(true); try { var dbEntity = _entityRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault(); if (dbEntity == null) { throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Location"); } var dbChildEntity = _entityRepository.FindBy(x => x.ParentEntityGuid.Equals(id) && !x.IsDeleted).FirstOrDefault(); var dbDevice = _deviceRepository.FindBy(x => x.EntityGuid.Equals(id) && !x.IsDeleted || (dbChildEntity != null && x.EntityGuid.Equals(dbChildEntity.Guid))).FirstOrDefault(); var dbDeviceType = _deviceTypeRepository.FindBy(x => x.EntityGuid.Equals(id) && !x.IsDeleted).FirstOrDefault(); if (dbDevice == null && dbChildEntity == null && dbDeviceType == null) { var device = _iotConnectClient.Device.AllDevice(new IoTConnect.Model.AllDeviceModel { entityGuid = id.ToString() }).Result; if (device != null && device.Data != null && device.Data.Any()) { _logger.Error($"Asset is associated with Location so it can not be deleted., Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Location is associated with Asset in IoTConnect so it can not be deleted."; } else { var deleteEntityResult = _iotConnectClient.Entity.Delete(id.ToString()).Result; if (deleteEntityResult != null && deleteEntityResult.status) { dbEntity.IsDeleted = true; dbEntity.UpdatedDate = DateTime.Now; dbEntity.UpdatedBy = SolutionConfiguration.CurrentUserId; return(_entityRepository.Update(dbEntity)); } else { _logger.Error($"Location is not deleted from iotconnect, Error: {deleteEntityResult.message}"); actionStatus.Success = false; actionStatus.Message = new UtilityHelper().IOTResultMessage(deleteEntityResult.errorMessages); } } } else if (dbChildEntity != null) { _logger.Error($"Location is not deleted in solution database.Zone exists, Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Location is already associated with Zone so it can not be deleted."; } else if (dbDeviceType != null) { _logger.Error($"Location is not updated in solution database.Device Type exists, Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Location is associated with Device Type so it can not be deleted."; } else { _logger.Error($"Location is not deleted in solution database.Asset exists, Error: {actionStatus.Message}"); actionStatus.Success = false; actionStatus.Message = "Asset is associated with Location so it can not be deleted."; } } catch (Exception ex) { _logger.Error(Constants.ACTION_EXCEPTION, "Location.Delete " + ex); actionStatus.Success = false; actionStatus.Message = ex.Message; } return(actionStatus); }