public async Task <bool> Delete <TEntity>(TEntity item, bool AutoSave = SAVE) where TEntity : class
        {
            var result = repository.Delete(item);

            if (AutoSave)
            {
                await SaveChangesAsync().ConfigureAwait(false);
            }
            ;
            return(result);
        }
Beispiel #2
0
 private void ConfigureData()
 {
     gateway = new Domain.Gateway()
     {
         Id           = 1,
         SerialNumber = "G1",
         IPV4Address  = "12.12.1.2",
         Name         = "G1"
     };
     gatewayDto = new GatewayDto()
     {
         Id           = 1,
         SerialNumber = "G1",
         IPV4Address  = "12.12.1.2",
         Name         = "G1"
     };
     gatewayDetailsDto = new GatewayDetailsDto()
     {
         Id           = 1,
         SerialNumber = "G1",
         IPV4Address  = "12.12.1.2",
         Name         = "G1",
         Devices      = new List <DeviceDto>()
     };
     mapper = new MapperConfiguration(c => c.AddProfile <AutoMapping>()).CreateMapper();
     gatewayRepositoryMock.Get(gateway.Id).Returns(Task <Domain.Gateway> .FromResult(gateway));
     gatewayRepositoryMock.Insert(gateway).Returns(Task <Domain.Gateway> .FromResult(gateway));
     gatewayRepositoryMock.Delete(gateway).Returns(Task <Domain.Gateway> .FromResult(gateway));
     service = new GatewayService(this.gatewayRepositoryMock, mapper);
 }
        public IHttpActionResult Delete(int networkId, int id)
        {
            _credentials.SetCredentials(Request.Headers.Authorization.Parameter);
            var userId = _userRep.Get(_credentials.Email, _credentials.Password).Id;

            if (!_networkRep.GetAll().Any(n => n.Id == networkId && n.User_Id == userId))
            {
                var errorMessage = _messages.GetMessage(Custom.NotFound, "Network", "Id");
                return(NotFound(errorMessage));
            }

            if (_gatewayRep.Exists(id))
            {
                _gatewayRep.Delete(id);
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }