//Delete one item if StockAdjustment in Draft Status public string DeleteItemFromDraftOrPendingStockAdjustment(string stockadjustment_id, string itemcode) { //controller pass stockadjustmentid and itemcode to the method StockAdjustment s1 = stockAdjustmentRepository.FindById(stockadjustment_id); StockAdjustmentDetail s = stockAdjustmentDetailRepository.FindById(stockadjustment_id, itemcode); if (stockAdjustmentRepository.FindById(stockadjustment_id) == null) { throw new Exception("can't find StockAdjustment"); } else if (stockAdjustmentDetailRepository.FindById(stockadjustment_id, itemcode) == null) { throw new Exception("can't find stockAdjustmentDetail"); } if (s1.Status.StatusId == 3 || s1.Status.StatusId == 4) { //remove one StockAdjustmentDetail in List<StockAdjustmentDetail> s1.StockAdjustmentDetails.Remove(s); //delete one stockadjustmentdetail stockAdjustmentDetailRepository.Delete(s); stockAdjustmentRepository.Save(s1); } return(itemcode); }
public void Delete_CannotFind() { // Arrange stockAdjustmentRepository.Save(new StockAdjustment() { StockAdjustmentId = "SADREPOTEST", CreatedDateTime = DateTime.Now, }); var saveResult = stockAdjustmentDetailRepository.Save(new StockAdjustmentDetail() { StockAdjustmentId = "SADREPOTEST", ItemCode = "E030", }); // Act stockAdjustmentDetailRepository.Delete(saveResult); // Assert Assert.IsNull(stockAdjustmentDetailRepository.FindById("SADREPOTEST", "E030")); }