private static HearingIsReadyForVideoIntegrationEvent CreateEvent() { var hearingDto = new HearingDto { HearingId = Guid.NewGuid(), CaseNumber = "Test1234", CaseType = "Generic", CaseName = "Automated Case vs Humans", ScheduledDuration = 60, ScheduledDateTime = DateTime.UtcNow, HearingVenueName = "MyVenue", RecordAudio = true }; var participants = Builder <ParticipantDto> .CreateListOfSize(4) .All().With(x => x.UserRole = UserRole.Individual.ToString()).Build().ToList(); var endpoints = Builder <EndpointDto> .CreateListOfSize(4).Build().ToList(); var message = new HearingIsReadyForVideoIntegrationEvent { Hearing = hearingDto, Participants = participants, Endpoints = endpoints }; return(message); }
public HearingDto UpdateHearing(int hearingId, HearingDto model) { var entity = _dbContext.Hearing.FirstOrDefault(x => x.HearingId == hearingId && x.IsDeleted == false); if (entity == null) { throw new NSIException("Hearing not found"); } //remove all users for this hearing from UserHearing table var atendees = _dbContext.UserHearing.Where(x => x.HearingId == hearingId).ToList(); if (atendees != null) { _dbContext.UserHearing.RemoveRange(atendees); } //remove all notes for this hearing from Note table var note = _dbContext.Note.FirstOrDefault(x => x.HearingId == hearingId && x.CreatedByUserId == model.Note.ElementAt(0).CreatedByUserId); if (note != null) { _dbContext.Note.Remove(note); } //update data entity.DateModified = DateTime.Now; if (model.HearingDate != null) { entity.HearingDate = model.HearingDate; } //update users foreach (var item in model.UserHearing) { entity.UserHearing.Add(new UserHearing() { UserId = item.UserId, HearingId = hearingId }); } //update notes foreach (var item in model.Note) { entity.Note.Add(new Note() { CreatedByUserId = item.CreatedByUserId, HearingId = hearingId, Text = item.Text }); } if (_dbContext.SaveChanges() > 0) { return(GetHearingById(entity.HearingId)); } throw new NSIException("Erro while updating hearing"); }
public HearingDto InsertHearing(HearingDto model) { var entity = Mappers.HearingsRepository.MapToDbEntity(model); _dbContext.Hearing.Add(entity); if (_dbContext.SaveChanges() > 0) { return(GetHearingById(entity.HearingId)); } throw new NSIException("Erro while inserting new hearing"); }
public void Delete_ReturnsOK() { // Arrange int id = 123; DateTime hearingDate = DateTime.Now; int createdByUserId = 1; int caseId = 3; var usersOnHearing = new List <UserHearingDto>() { new UserHearingDto() { UserId = 1 } }; var notes = new List <NoteDto>() { new NoteDto { Text = "test test", CreatedByUserId = 1, HearingId = 123 } }; var hearing = new HearingDto() { HearingId = id, HearingDate = hearingDate, CreatedByUserId = createdByUserId, CaseId = caseId, UserHearing = usersOnHearing, Note = notes }; var hearingRepo = new Mock <IHearingsRepository>(); hearingRepo.Setup(x => x.InsertHearing(hearing)); var hearingManipulation = new HearingsManipulation(hearingRepo.Object); var controller = new HearingsController(hearingManipulation); // Act var result = controller.DeleteHearing(3); // Assert Assert.IsType <OkObjectResult>(result); }
public static UpdateConferenceRequest MapToUpdateConferenceRequest(HearingDto hearing) { return(new UpdateConferenceRequest { HearingRefId = hearing.HearingId, CaseName = hearing.CaseName, CaseNumber = hearing.CaseNumber, CaseType = hearing.CaseType, ScheduledDateTime = hearing.ScheduledDateTime, ScheduledDuration = hearing.ScheduledDuration, HearingVenueName = hearing.HearingVenueName, AudioRecordingRequired = hearing.RecordAudio }); }
private static HearingDto CreateHearingDto() { var dto = new HearingDto { HearingId = Guid.NewGuid(), CaseNumber = "Test1234", CaseType = "Generic", CaseName = "Automated Case vs Humans", ScheduledDuration = 60, ScheduledDateTime = DateTime.UtcNow, HearingVenueName = "MyVenue", RecordAudio = true }; return(dto); }
public static Hearing MapToDbEntity(HearingDto model) { return(new Hearing() { HearingId = model.HearingId, HearingDate = model.HearingDate, CreatedByUserId = model.CreatedByUserId, CaseId = model.CaseId, UserHearing = model.UserHearing.Select(x => new UserHearing() { UserId = x.UserId }).ToList(), Note = model.Note.Select(x => new Note() { Text = x.Text, CreatedByUserId = x.CreatedByUserId, HearingId = model.HearingId }).ToList() }); }
public IActionResult Put(int id, [FromBody] HearingDto model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(new NSIResponse <HearingDto>() { Data = _hearingsManipulation.UpdateHearing(id, model), Message = "Hearing updated" })); } catch (Exception ex) { Logger.Logger.LogError(ex.Message); return(BadRequest(new NSIResponse <object> { Data = null, Message = ex.Message })); } }
public static BookNewConferenceRequest MapToBookNewConferenceRequest(HearingDto hearingDto, IEnumerable <ParticipantDto> participantDtos, IEnumerable <EndpointDto> endpointDtos) { var participants = participantDtos .Select(ParticipantToParticipantRequestMapper.MapToParticipantRequest) .ToList(); var request = new BookNewConferenceRequest { CaseNumber = hearingDto.CaseNumber, CaseName = hearingDto.CaseName, CaseType = hearingDto.CaseType, ScheduledDuration = hearingDto.ScheduledDuration, ScheduledDateTime = hearingDto.ScheduledDateTime, HearingRefId = hearingDto.HearingId, Participants = participants, HearingVenueName = hearingDto.HearingVenueName, AudioRecordingRequired = hearingDto.RecordAudio, Endpoints = endpointDtos.Select(EndpointToRequestMapper.MapToRequest).ToList() }; return(request); }
public void Update_ReturnsUpdatedHearing() { // Arrange int id = 123; DateTime hearingDate = DateTime.Now; int createdByUserId = 1; int caseId = 3; var usersOnHearing = new List <UserHearingDto>() { new UserHearingDto() { UserId = 1 } }; var notes = new List <NoteDto>() { new NoteDto { Text = "test test", CreatedByUserId = 1, HearingId = 123 } }; var newNotes = new List <NoteDto>() { new NoteDto { Text = "test test", CreatedByUserId = 1, HearingId = 123 }, new NoteDto { Text = "new note", CreatedByUserId = 2, HearingId = 123 }, new NoteDto { Text = "new note2", CreatedByUserId = 3, HearingId = 123 } }; var hearing = new HearingDto() { HearingId = id, HearingDate = hearingDate, CreatedByUserId = createdByUserId, CaseId = caseId, UserHearing = usersOnHearing, Note = notes }; var hearingRepo = new Mock <IHearingsRepository>(); hearingRepo.Setup(x => x.InsertHearing(hearing)); var hearingManipulation = new HearingsManipulation(hearingRepo.Object); var controller = new HearingsController(hearingManipulation); // Act var resultCreated = controller.Post(hearing); hearing.HearingDate = DateTime.Now.AddDays(15); hearing.Note = newNotes; var resultUpdated = controller.Put(id, hearing); // Assert Assert.IsType <OkObjectResult>(resultCreated); Assert.IsType <OkObjectResult>(resultUpdated); }
public HearingDto UpdateHearing(int hearingId, HearingDto model) { ValidationHelper.IntegerGreaterThanZero(hearingId, name: "Hearing id"); return(_hearingsRepository.UpdateHearing(hearingId, model)); }
public HearingDto CreateHearing(HearingDto model) { return(_hearingsRepository.InsertHearing(model)); }