public IActionResult Create([FromBody] InvestigationNote newmodel) { if (ModelState.IsValid) { _context.InvestigationNote.Add(newmodel); ReturnData ret; ret = _context.SaveData(); if (ret.Message == "Success") { return(CreatedAtRoute("GetInvestigationNote", new { id = newmodel.InvestigationNoteID }, newmodel)); } return(NotFound(ret)); } else { return(BadRequest()); } }
public IActionResult UpdateEntry([FromBody] InvestigationNote objupd) { var targetObject = _context.InvestigationNote.FirstOrDefault(t => t.InvestigationNoteID == objupd.InvestigationNoteID); if (targetObject == null) { return(NotFound()); } _context.Entry(targetObject).CurrentValues.SetValues(objupd); ReturnData ret; ret = _context.SaveData(); if (ret.Message == "Success") { return(Ok()); } return(NotFound(ret)); }
public void InvestigationNote() { using (var context = new AppDbContext(options, null)) { var controller = new InvestigationNoteController(context); // Get all var result = controller.Get(); // Assert var okResult = Assert.IsAssignableFrom <IEnumerable <InvestigationNote> >(result); var pgcount = okResult.ToList().Count; Assert.Equal(2, pgcount); // Get by ID var result1 = controller.Get(1); var okResult1 = Assert.IsAssignableFrom <InvestigationNote>(result1); //var thisresult1 = okResult1.FirstOrDefault(); Assert.Equal("InvestigationNote 1", result1.NoteText); // test update var pg1 = new InvestigationNote { InvestigationNoteID = 1, NoteText = "InvestigationNote 1 upd" }; controller.UpdateEntry(pg1); var result3 = controller.Get(1); //var thisresult3 = result3.FirstOrDefault(); Assert.NotEqual("InvestigationNote 1", result3.NoteText); Assert.Equal("InvestigationNote 1 upd", result3.NoteText); // test delete var result4 = controller.Get(2); Assert.Equal("InvestigationNote 2", result4.NoteText); IActionResult result5 = controller.Delete(2); var viewResult = Assert.IsType <Microsoft.AspNetCore.Mvc.OkResult>(result5); var result6 = controller.Get(2); Assert.Null(result6); } }
public void InvestigationNote() { IQueryable <InvestigationNote> InvestigationNoteInvestigationNote = Enumerable.Empty <InvestigationNote>().AsQueryable(); InvestigationNote ct = new InvestigationNote { InvestigationNoteID = 1, NoteText = "Test InvestigationNote" }; Mock <IInvestigationNoteRepository> InvestigationNoteService = new Mock <IInvestigationNoteRepository>(); object obj = new object(); try { InvestigationNoteService.Setup(x => x.GetAll()).Returns(InvestigationNoteInvestigationNote); InvestigationNoteService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct); InvestigationNoteService.Setup(x => x.Add(It.IsAny <InvestigationNote>())).Returns(ct); InvestigationNoteService.Setup(x => x.Delete(It.IsAny <InvestigationNote>())).Verifiable(); InvestigationNoteService.Setup(x => x.Update(It.IsAny <InvestigationNote>(), It.IsAny <object>())).Returns(ct); var InvestigationNoteObject = InvestigationNoteService.Object; var p1 = InvestigationNoteObject.GetAll(); var p2 = InvestigationNoteObject.Get(1); var p3 = InvestigationNoteObject.Update(ct, obj); var p4 = InvestigationNoteObject.Add(ct); InvestigationNoteObject.Delete(ct); Assert.IsAssignableFrom <IQueryable <InvestigationNote> >(p1); Assert.IsAssignableFrom <InvestigationNote>(p2); Assert.Equal("Test InvestigationNote", p2.NoteText); Assert.Equal("Test InvestigationNote", p3.NoteText); InvestigationNoteService.VerifyAll(); InvestigationNoteObject.Dispose(); } finally { InvestigationNoteService = null; } }
internal void PopulateData() { using (var context = new AppDbContext(options, null)) { if (context.ActivityType.Count() < 1) { var p1 = new ActivityType { ActivityTypeID = 1, ActivityTypeName = "activity type 1", }; var p2 = new ActivityType { ActivityTypeID = 2, ActivityTypeName = "activity type 2", }; context.ActivityType.Add(p1); context.ActivityType.Add(p2); context.SaveChanges(); } if (context.InvestigationNote.Count() < 1) { var p1 = new InvestigationNote { InvestigationNoteID = 1, NoteText = "InvestigationNote 1", }; var p2 = new InvestigationNote { InvestigationNoteID = 2, NoteText = "InvestigationNote 2", }; context.InvestigationNote.Add(p1); context.InvestigationNote.Add(p2); context.SaveChanges(); } if (context.InvestigationStatus.Count() < 1) { var p1 = new InvestigationStatus { InvestigationStatusID = 1, InvestigationStatusDescription = "InvestigationStatus 1", }; var p2 = new InvestigationStatus { InvestigationStatusID = 2, InvestigationStatusDescription = "InvestigationStatus 2", }; context.InvestigationStatus.Add(p1); context.InvestigationStatus.Add(p2); context.SaveChanges(); } if (context.InvestigationActivity.Count() < 1) { var p1 = new InvestigationActivity { InvestigationActivityID = 1, FromValue = "InvestigationActivity 1", }; var p2 = new InvestigationActivity { InvestigationActivityID = 2, FromValue = "InvestigationActivity 2", }; context.InvestigationActivity.Add(p1); context.InvestigationActivity.Add(p2); context.SaveChanges(); } } }
public IActionResult Update([FromBody] InvestigationNote editentry) { var result = _repository.Update(editentry, editentry.InvestigationNoteID); return(Helper.CheckResult(result)); }
public IActionResult Create([FromBody] InvestigationNote newentry) { var result = _repository.Add(newentry); return(Helper.CheckResult(result)); }