public void Setup() { var connString = new ConnectionString(); _productRepo = new ProductRepository(connString); _sut = new AssetRepository(connString, _productRepo); var product = InsertProduct(); _asset = new AssetDto { CreatedBy = "user2", Tag = "CRD-X-012345", Serial = "xx0123456789", Product = product, Description = "Asset Description", InvoiceDate = DateTime.Now.AddDays(-7), InvoiceNumber = "ii0123456789", Price = 50M, PaidBy = "user3", Owner = "user4", Remark = "Not yet installed", TeamAsset = false }; _asset.Id = _sut.Insert(_asset); }
public void ThenTheAssetIsInserted() { _expected.Id = _sut.Insert(_expected); var actual = _sut.GetById(_expected.Id.Value); Assert.IsNotNull(actual); Assert.AreEqual(_expected, actual); }
public void Setup() { var connString = new ConnectionString(); _productRepo = new ProductRepository(connString); _assetRepo = new AssetRepository(connString, _productRepo); _sut = new AssetHistoryRepository(connString); _expectedHistory = new List <AssetDto>(); var product = InsertProduct(); _assets = new List <AssetDto> { new AssetDto { CreatedBy = "user1", Tag = "CRD-X-00001", Product = product, PaidBy = "user1", Owner = "user1", TeamAsset = true }, new AssetDto { CreatedBy = "user2", Tag = "CRD-X-00002", Serial = "xx0123456789", Product = product, Description = "Asset Description", InvoiceDate = DateTime.Now.AddDays(-7), InvoiceNumber = "ii0123456789", Price = 50.01M, PaidBy = "user2", Owner = "user1", InstallDate = DateTime.Now.AddDays(2), InstalledBy = "user2", Remark = "To be installed within 2 days", TeamAsset = false }, new AssetDto { CreatedBy = "user3", Tag = "CRD-X-00003", Product = product, PaidBy = "user3", Owner = "user1", TeamAsset = true }, }; _assets.ToList().ForEach(x => x.Id = _assetRepo.Insert(x)); AddToHistory(_assets); UpdateAssets(_assets); }
public static IPostResponse Insert(IAsset asset) { if (asset.Id != 0) { throw new ArgumentException("Asset Id must be 0."); } using (AssetRepository repo = new AssetRepository()) { return(repo.Insert(asset)); } }
public Asset Save([FromBody] Asset model) { if (model.Id == 0) { model.BranchId = _branchContext.Branch.Id; model.CreateDate = DateTime.Now; model.UserId = _sessionContext.UserId; } ModelState.Clear(); TryValidateModel(model); ModelState.Validate(); if (model.Id > 0) { _repository.Update(model); } else { _repository.Insert(model); } return(model); }