public async Task UpdateCounterType(int counterTypeId, UpdateCounterType value) { try { using (var trans = await _context.Database.BeginTransactionAsync()) { var counterType = await _context.CounterTypes .FirstOrDefaultAsync(x => x.CounterTypeId == counterTypeId); if (counterType == null) { throw new Exception("The counter type is not found!"); } counterType.CounterShortName = value.ShortName; counterType.CounterName = value.CounterTypeName; counterType.IsEndpoint = value.IsEndpoint; _context.CounterTypes.Update(counterType); await _context.SaveChangesAsync(); trans.Commit(); } } catch (Exception e) { throw e; } }
public async Task CreateNewCounterType(UpdateCounterType value) { try { using (var trans = await _context.Database.BeginTransactionAsync()) { var newCounterType = new CounterType { CounterName = value.CounterTypeName, CounterShortName = value.ShortName, IsEndpoint = value.IsEndpoint }; await _context.CounterTypes.AddAsync(newCounterType); await _context.SaveChangesAsync(); trans.Commit(); } } catch (Exception e) { throw e; } }
public async Task <IActionResult> UpdateCounterType([FromBody] UpdateCounterType value, int counterTypeId) { await _ctService.UpdateCounterType(counterTypeId, value); return(Ok()); }
public async Task <IActionResult> CreatecounterType([FromBody] UpdateCounterType value) { await _ctService.CreateNewCounterType(value); return(Ok()); }