Пример #1
0
        public IActionResult DeleteDevice(int id)
        {
            try
            {
                if (!_bl.DeviceExists(id))
                {
                    _log.LogWarning("Not Found: Device '{0}' not found", id);
                    return(NotFound());
                }

                var d = _bl.GetSingleDevice(id);
                _bl.DeleteDevice(d);
                _bl.SaveChanges();
                _log.LogInformation("Device '{0}({1})' deleted by '{2}'", d.InvNum, d.Name, User.Identity.Name);

                return(Ok(d));
            }
            catch (SecurityException)
            {
                _log.LogWarning("Security: '{0}' tried to delete Device '{1}'", _bl.GetCurrentUid(), id);
                return(Unauthorized());
            }

            catch (Exception ex)
            {
                _log.LogError("Exception: {0}", ex);
                return(StatusCode(500));
            }
        }
Пример #2
0
        public void bl_should_delete_device()
        {
            var invNum = Guid.NewGuid().ToString();
            var obj    = _bl.CreateDevice();

            obj.InvNum   = invNum;
            obj.IsActive = true;
            var getObj = _bl.GetSingleDevice(invNum);

            Assert.NotNull(getObj);
            _bl.DeleteDevice(getObj);
            getObj.IsActive = false;
            var getDel = _bl.GetSingleDevice(invNum);

            Assert.False(getDel.IsActive);
        }