Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateCounterType([FromBody] UpdateCounterType value, int counterTypeId)
        {
            await _ctService.UpdateCounterType(counterTypeId, value);

            return(Ok());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CreatecounterType([FromBody] UpdateCounterType value)
        {
            await _ctService.CreateNewCounterType(value);

            return(Ok());
        }