public IOWVariable InsertOrUpdateVariable(IOWVariable input) { IOWVariable variable = null; // Check to see if a variable already exists. If so, update it in place. Otherwise, create a new one. if (input.Id > 0) variable = _iowVariableRepository.FirstOrDefault(input.Id); else if (!string.IsNullOrEmpty(input.Name)) variable = _iowVariableRepository.FirstOrDefault(p => p.Name == input.Name); // No variable? Then create one. if( variable == null ) { variable = new IOWVariable { Name = input.Name, IOWLimits = new List<IOWLimit>(), TenantId = input.TenantId }; } variable.Description = input.Description; // Validate the tag Tag tag = _tagManager.FirstOrDefaultTag(input.TagId); if( tag != null) variable.TagId = input.TagId; // Set the UOM to, in order: (1) input, (2) original variable, (3) tag. if (!string.IsNullOrEmpty(input.UOM)) variable.UOM = input.UOM; else if (string.IsNullOrEmpty(variable.UOM) && tag != null) variable.UOM = tag.UOM; variable.IOWLimits = input.IOWLimits; return _iowVariableRepository.InsertOrUpdate(variable); }
public List<LimitStatsByDay> GetLimitStatsByDay(IOWVariable variable, DateTime? startTimestamp, DateTime? endTimestamp) { List<LimitStatsByDay> stats = new List<LimitStatsByDay>(); if( variable != null && variable.IOWLimits != null ) { // Get all limits for the specified variable List<long> limitIds = new List<long>(); foreach (IOWLimit limit in variable.IOWLimits) limitIds.Add(limit.Id); stats = GetLimitStatsByDay(limitIds, startTimestamp, endTimestamp); } return stats; }
public VariableDto UpdateVariable(UpdateVariableInput input) { Logger.Info("Update a variable for input Id= " + (input.Id.HasValue ? (input.Id.Value).ToString() : "n/a") + " Name= " + input.Name); // Look for the variable IOWVariable variable = _iowManager.FirstOrDefaultVariable(input.Id, input.Name); if( variable == null && !string.IsNullOrEmpty(input.Name) ) { // No variable, so create one variable = new IOWVariable { Name = input.Name, TenantId = (AbpSession.TenantId != null) ? (int)AbpSession.TenantId : 1 }; } if( variable != null ) { variable.Description = input.Description; variable.UOM = input.UOM; // Check the tag Tag tag = _tagManager.FirstOrDefaultTag(input.TagId, input.Name); if( tag != null ) variable.TagId = tag.Id; variable = _iowManager.InsertOrUpdateVariable(variable); } return variable.MapTo<VariableDto>(); }