public async Task <IActionResult> PutLegalCase(long id, LegalCase legalCase) { if (id != legalCase.Id) { return(BadRequest()); } _context.Entry(legalCase).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LegalCaseExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <LegalCase> > PostLegalCase(LegalCase legalCase) { _context.Cases.Add(legalCase); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLegalCase", new { id = legalCase.Id }, legalCase)); }
public async void DeleteLegalCaseAsync_Returns_NotFound_404_When_Delete_With_non_existent_LegalCase(int id) { //get expected LegalCase LegalCase legalCase = null; //configure Repo return of getting the LegalCase to be deleted _mockRepository.Setup(repo => repo.GetOneByAsync(lc => lc.Id == id)).ReturnsAsync(legalCase); //configure Repo return of Adding the LegalCase _mockRepository.Setup(repo => repo.DeleteTAsync(legalCase)).ReturnsAsync(0); //call the controller method var actionResult = await _controller.DeleteLegalCaseAsync(id); //Get the LegalCase from the ActionResult returned var notFoundResult = Assert.IsType <NotFoundObjectResult>(actionResult.Result); string responseMessage = (string)notFoundResult.Value; int? statusCode = notFoundResult.StatusCode; //Assertions Assert.IsType <int>(statusCode); Assert.Equal(404, statusCode); Assert.IsType <string>(responseMessage); Assert.Equal("No Legal Case was found", responseMessage); }
public async void UpdateLegalCaseAsync_Updates_Existing_LegalCase_And_Returns_Updated_LegalCase() { //get expected LegalCase LegalCase legalCase = new LegalCase() { Id = 1, Client_Id = 2, Title = "Title for Case Updated", Description = "Description for Case Updated", TrustFund = 9999.99m }; LegalCaseDTO expectedLegalCaseDTO = _mapper.Map <LegalCaseDTO>(legalCase); //configure Repo return of getting the LegalCase to be updated _mockRepository.Setup(repo => repo.GetOneByAsync(lc => lc.Id == legalCase.Id)).ReturnsAsync(legalCase); //configure Repo return of the Update action _mockRepository.Setup(repo => repo.UpdateTAsync(legalCase)).ReturnsAsync(1); //call the controller method var actionResult = await _controller.UpdateLegalCaseAsync(legalCase.Id, legalCase); //Get the LegalCase from the ActionResult returned var okObjectResult = Assert.IsType <OkObjectResult>(actionResult.Result); LegalCaseDTO actualLegalCaseDTO = okObjectResult.Value as LegalCaseDTO; int? statusCode = okObjectResult.StatusCode; //Assertions Assert.Equal(200, statusCode); Assert.IsType <LegalCaseDTO>(actualLegalCaseDTO); //use FluentAssertions to compare Reference types actualLegalCaseDTO.Should().BeEquivalentTo(expectedLegalCaseDTO, options => options.ComparingByMembers <LegalCaseDTO>()); }
public async Task <ActionResult <LegalCaseDTO> > UpdateLegalCaseAsync([FromRoute] int id, [FromBody] LegalCase legalCase) { LegalCase legalCaseResult = await _genericRepository.GetOneByAsync(lc => lc.Id == legalCase.Id); if (legalCaseResult is null) { var logData = new { Id = id, LegalCase = legalCase, Action = ControllerContext.ActionDescriptor.DisplayName, Verb = HttpContext.Request.Method, EndpointPath = HttpContext.Request.Path.Value, User = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value }; _logger.LogInformation("No LegalCase was updated for Id {id} and Legalcase {@legalCase}. Data: {@logData}", id, legalCase, logData); return(NotFound("No Legal Case was updated")); } int updated = await _genericRepository.UpdateTAsync(legalCase); LegalCaseDTO legalCaseDTO = _mapper.Map <LegalCaseDTO>(legalCase); return(Ok(legalCaseDTO)); }
public async void AddLegalCaseAsync_Creates_And_Returns_New_LegalCase() { //get expected LegalCase LegalCase legalCase = _legalCases.FirstOrDefault(); LegalCaseDTO expectedLegalCaseDTO = _mapper.Map <LegalCaseDTO>(legalCase); //configure Repo return of Adding the LegalCase _mockRepository.Setup(repo => repo.AddTAsync(legalCase)).ReturnsAsync(1); //configure Repo return of getting the newly created LegalCase _mockRepository.Setup(repo => repo.GetOneByAsync(lc => lc.Client_Id == legalCase.Client_Id && lc.Title == legalCase.Title)) .ReturnsAsync(legalCase); //call the controller method var actionResult = await _controller.AddLegalCaseAsync(legalCase); //Get the LegalCase from the ActionResult returned var createdResult = Assert.IsType <CreatedResult>(actionResult.Result); LegalCaseDTO actualLegalCaseDTO = createdResult.Value as LegalCaseDTO; int? statusCode = createdResult.StatusCode; //Assertions Assert.Equal(201, statusCode); Assert.IsType <LegalCaseDTO>(actualLegalCaseDTO); //use FluentAssertions to compare Reference types actualLegalCaseDTO.Should().BeEquivalentTo(expectedLegalCaseDTO, options => options.ComparingByMembers <LegalCaseDTO>()); }
public async void GetLegalCaseByIdWithDetailsAsync_Returns_LegalCaseWithDetails(int id) { //get expected LegalCase LegalCase expectedLegalCase = _legalCases.Where(lc => lc.Id == id).First(); LegalCaseWithBillableActivitiesDTO expectedCaseDTO = _mapper.Map <LegalCaseWithBillableActivitiesDTO>(expectedLegalCase); //configure the Repo return _mockRepository.Setup(repo => repo.GetOneByWithRelatedDataAsync(lc => lc.Id == id, lc => lc.BillableActivities)).ReturnsAsync(expectedLegalCase); //call the controller method var actionResult = await _controller.GetLegalCaseByIdWithDetailsAsync(id); //Get the LegalCase from the ActionResult returned var okObjectResult = Assert.IsType <OkObjectResult>(actionResult.Result); LegalCaseWithBillableActivitiesDTO actualLegalCaseDTO = okObjectResult.Value as LegalCaseWithBillableActivitiesDTO; int?statusCode = okObjectResult.StatusCode; //Assertions Assert.Equal(200, statusCode); Assert.IsType <LegalCaseWithBillableActivitiesDTO>(actualLegalCaseDTO); //use FluentAssertions to compare Reference types actualLegalCaseDTO.Should().BeEquivalentTo(expectedCaseDTO, options => options.ComparingByMembers <LegalCaseWithBillableActivitiesDTO>()); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { bool isValid = false; if (value is string) { var id = (value as string) ?? ""; isValid = LegalCase.IsValidCaseId(id); } else if (value is List <string> ) { var caseList = value as List <string>; // empty lists are considered valid isValid = true; caseList.ForEach(c => isValid = isValid && LegalCase.IsValidCaseId(c)); } if (!isValid) { return(new ValidationResult("Invalid CaseId detected.")); } return(ValidationResult.Success); }
public ICollection <object> ParseData(MySqlDataReader dataReader) { var entities = new List <object>(); while (dataReader.Read()) { var entity = new LegalCase { ID = (int)dataReader["ID"], TrademarkNumber = dataReader["TrademarkNumber"] as string, DateAssigned = dataReader["DateAssigned"] as string }; if (int.TryParse((dataReader["TrademarkID"] as int?)?.ToString(), out int trademarkID)) { entity.Trademark = new Trademark { ID = trademarkID, Name = dataReader["TrademarkName"] as string }; } entities.Add(entity); } return(entities); }
public async Task <ActionResult <LegalCaseDTO> > AddLegalCaseAsync([FromBody] LegalCase legalCase) { int created = await _genericRepository.AddTAsync(legalCase); if (created == 0) { var logData = new { LegalCase = legalCase, Action = ControllerContext.ActionDescriptor.DisplayName, Verb = HttpContext.Request.Method, EndpointPath = HttpContext.Request.Path.Value, User = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value }; _logger.LogInformation("No LegalCase was created for Legalcase {@legalCase}. Data: {@logData}", legalCase, logData); return(NotFound("No Legal Case was created")); } var newLegalCase = await _genericRepository.GetOneByAsync(lc => lc.Client_Id == legalCase.Client_Id && lc.Title == legalCase.Title); LegalCaseDTO legalCaseDTO = _mapper.Map <LegalCaseDTO>(newLegalCase); return(Created("", legalCaseDTO)); }
private void Update(LegalCase legalCase) { legalCase.RegisteredAt = RegisteredAt; legalCase.GregDate = GregDate; legalCase.Defendant = Defendant; legalCase.Description = Description; legalCase.StatusId = CaseStatus.Id; }
public void UpdateLegalCase(LegalCase lcase) { if (lcase == null) { throw new ArgumentNullException(nameof(lcase)); } _context.LegalCases.Update(lcase); }
private void FillFromExisted(LegalCase legalCase) { CaseNo = legalCase.CaseNo; RegisteredAt = legalCase.RegisteredAt; Defendant = legalCase.Defendant; Description = legalCase.Description; StatusId = legalCase.StatusId; CaseStatus = legalCase.CaseStatus; }
internal static LegalCaseDTO MapToDTO(this LegalCase legalCase, IUrlHelper helper) { var dto = new LegalCaseDTO { CaseId = legalCase.CaseId.ToString(), CaseUrl = helper.ActionLink("DeleteLegalCase", "Cases", new { folderId = legalCase.FolderId, caseId = legalCase.CaseId }) }; return(dto); }
public async Task <IActionResult> PutLegalCase(long folderId, string caseId) { if (!LegalCase.IsValidCaseId(caseId) || !FolderExists(folderId)) { return(NotFound()); } var legalCase = new LegalCase { FolderId = folderId, CaseId = Int64.Parse(caseId) }; _context.Cases.Add(legalCase); await _context.SaveChangesAsync(); return(NoContent()); }
static void Main(string[] args) { try { var data = new LegalCase(); var LegalCaseStates = new LegalCaseStates().Items; var Events = new Events(false).Items; } catch (ValidationException validationException) { } catch (Exception e) { } }
private void AddNew(LegalCase legalCase, IUnitOfWork db) { if (legalCase == null) { throw new ArgumentNullException("legalCase"); } if (db == null) { throw new ArgumentNullException("db"); } legalCase.CaseNo = CaseNo; legalCase.RegisteredAt = RegisteredAt; legalCase.GregDate = GregDate; legalCase.Defendant = Defendant; legalCase.Description = Description; legalCase.StatusId = CaseStatus.Id; db.LegalCases.Add(legalCase); }
public async Task <IActionResult> DeleteLegalCase(long folderId, string caseId) { if (!LegalCase.IsValidCaseId(caseId)) { return(NotFound()); } var legalCase = await _context.Cases.FirstOrDefaultAsync(c => c.FolderId == folderId && c.CaseId == Int64.Parse(caseId)); if (legalCase == null) { return(NotFound()); } _context.Cases.Remove(legalCase); await _context.SaveChangesAsync(); return(NoContent()); }
public async void GetLegalCaseByIdWithDetailsAsync_Returns_NotFound_For_Wrong_Id(int id) { //get expected LegalCase LegalCase expectedLegalCase = null; //configure the Repo return _mockRepository.Setup(repo => repo.GetOneByWithRelatedDataAsync(lc => lc.Id == id, lc => lc.BillableActivities)).ReturnsAsync(expectedLegalCase); //call the controller method var actionResult = await _controller.GetLegalCaseByIdWithDetailsAsync(id); //Get the Message from the ActionResult returned var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(actionResult.Result); string responseMessage = notFoundObjectResult.Value.ToString(); int? statusCode = notFoundObjectResult.StatusCode; //Assertions Assert.Equal(404, statusCode); responseMessage.Should().Be("No data was found"); }
public void LoadCaseAppointments(LegalCase legalCase) { if (legalCase == null) { throw new ArgumentNullException("legalCase"); } try { _selectedCase = legalCase; using (IUnitOfWork unit = new UnitOfWork()) { var appints = ((CaseAppointmentRepository)unit.CaseAppointments).GetCaseAppointments(legalCase.CaseNo); CaseAppointments = new ObservableCollection <CaseAppointment>(appints); CreateNewAppointment(); ControlState(ControllerStates.Blank); } } catch (Exception ex) { Helper.LogShowError(ex); } }
public ICollection <object> ParseDataMin(MySqlDataReader dataReader) { var entities = new List <object>(); while (dataReader.Read()) { var entity = new LegalCase { ID = (int)dataReader["ID"], LegalProceedingName = dataReader["LegalProceedingName"] as string, TypeOfCase = dataReader["TypeOfCase"] as string, DateAssigned = dataReader["DateAssigned"] as string, Keywords = dataReader["Keywords"] as string }; if (int.TryParse((dataReader["TrademarkID"] as int?)?.ToString(), out int trademarkID)) { entity.Trademark = new Trademark { ID = trademarkID, Name = dataReader["TrademarkName"] as string }; if (int.TryParse((dataReader["OfficeID"] as int?)?.ToString(), out int officeID)) { entity.Trademark.Office = new Office { ID = officeID, DisplayName = dataReader["OfficeName"] as string }; } } entities.Add(entity); } return(entities); }
public async Task <ActionResult <int> > DeleteLegalCaseAsync([FromRoute] int id) { LegalCase legalCaseResult = await _genericRepository.GetOneByAsync(lc => lc.Id == id); if (legalCaseResult is null) { var logData = new { Id = id, Action = ControllerContext.ActionDescriptor.DisplayName, Verb = HttpContext.Request.Method, EndpointPath = HttpContext.Request.Path.Value, User = HttpContext.User.Claims.First(usr => usr.Type == "preferred_username").Value }; _logger.LogInformation("No LegalCase was found for Id {id}. Data: {@logData}", id, logData); return(NotFound("No Legal Case was found")); } int deletedLegalCases = await _genericRepository.DeleteTAsync(legalCaseResult); return(Ok(deletedLegalCases)); }
public async void UpdateLegalCaseAsync_Returns_NotFound_404_When_Update_With_null_LegalCase() { //get expected LegalCase LegalCase legalCase = null; //configure Repo return of Adding the LegalCase _mockRepository.Setup(repo => repo.UpdateTAsync(legalCase)).ReturnsAsync(0); //call the controller method var actionResult = await _controller.UpdateLegalCaseAsync(1, legalCase); //Get the LegalCase from the ActionResult returned var notFoundResult = Assert.IsType <NotFoundObjectResult>(actionResult.Result); string responseMessage = (string)notFoundResult.Value; int? statusCode = notFoundResult.StatusCode; //Assertions Assert.IsType <int>(statusCode); Assert.Equal(404, statusCode); Assert.IsType <string>(responseMessage); Assert.Equal("No Legal Case was updated", responseMessage); }
public async void DeleteLegalCaseAsync_Deletes_A_LegalCase_And_Returns_Number_Of_Deletions(int id) { //get expected LegalCase //LegalCase legalCase = _legalCases.FirstOrDefault(); LegalCase legalCase = new LegalCase() { Id = 1, Client_Id = 1, Title = "Title for Case Delete", Description = "Description for Case Delete", TrustFund = 7777.33m }; //configure Repo return of getting the LegalCase to be deleted _mockRepository.Setup(repo => repo.GetOneByAsync(lc => lc.Id == id)).ReturnsAsync(legalCase); //configure Repo return of the Delete action _mockRepository.Setup(repo => repo.DeleteTAsync(legalCase)).ReturnsAsync(1); //call the controller method //var actionResult = await _controller.DeleteLegalCaseAsync(legalCase.Id); var actionResult = await _controller.DeleteLegalCaseAsync(legalCase.Id); //Get the number of deleted LegalCases from the ActionResult returned var okObjectResult = Assert.IsType <OkObjectResult>(actionResult.Result); int actualLegalCasesDeletedNumber = (int)okObjectResult.Value; int?statusCode = okObjectResult.StatusCode; //Assertions Assert.Equal(200, statusCode); Assert.IsType <int>(actualLegalCasesDeletedNumber); //use FluentAssertions to compare Reference types Assert.Equal(1, actualLegalCasesDeletedNumber); }
/// <summary> /// Performs a JSON-to-Object conversion. /// </summary> /// <param name="reader"> /// A JsonReader object. /// </param> /// <param name="objectType"> /// The type of the object. /// </param> /// <param name="existingValue"> /// The existing value. /// </param> /// <param name="serializer"> /// A JsonSerializer object. /// </param> /// <returns> /// A converted object. /// </returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { const string ITEM_TYPE_KEY = "ItemType"; const string ARGUMENT_EXCEPTON = "Invalid Or Missing ItemType"; ContentItem contentItem = null; ItemType itemType = ItemType.Unknown; JObject jObject = JObject.Load(reader); JToken jToken = null; if (jObject.TryGetValue(ITEM_TYPE_KEY, StringComparison.CurrentCultureIgnoreCase, out jToken) && jToken != null && Enum.TryParse(jToken.Value <string>(), true, out itemType)) { switch (itemType) { case ItemType.Unknown: throw new ArgumentException(ARGUMENT_EXCEPTON); case ItemType.Book: contentItem = new Book(); break; case ItemType.Chapter: contentItem = new Chapter(); break; case ItemType.Journal: contentItem = new Journal(); break; case ItemType.Magazine: contentItem = new Magazine(); break; case ItemType.Newspaper: contentItem = new Newspaper(); break; case ItemType.Webpage: contentItem = new Webpage(); break; case ItemType.Encyclopedia: contentItem = new Encyclopedia(); break; case ItemType.Graphic: contentItem = new Graphic(); break; case ItemType.AudioRecording: contentItem = new AudioRecording(); break; case ItemType.VideoRecording: contentItem = new VideoRecording(); break; case ItemType.Broadcast: contentItem = new Broadcast(); break; case ItemType.PersonalCommunication: contentItem = new PersonalCommunication(); break; case ItemType.Interview: contentItem = new Interview(); break; case ItemType.Presentation: contentItem = new Presentation(); break; case ItemType.Map: contentItem = new Map(); break; case ItemType.Bill: contentItem = new Bill(); break; case ItemType.Legislation: contentItem = new Legislation(); break; case ItemType.LegalCase: contentItem = new LegalCase(); break; case ItemType.Report: contentItem = new Report(); break; case ItemType.ConferencePaper: contentItem = new ConferencePaper(); break; default: throw new NotImplementedException(); } } else { throw new ArgumentException(ARGUMENT_EXCEPTON); } if (serializer != null) { serializer.Populate(jObject.CreateReader(), contentItem); } return(contentItem); }
public void CreateLegalCase(LegalCase lcase) { throw new NotImplementedException(); }
public void OnActionExecuting(ActionExecutingContext context) { //get the LegalCase object from the context body LegalCase _legalCase = context.ActionArguments["legalcase"] as LegalCase; //validate that LegalCase is not null if (_legalCase == null) { _logger.LogInformation($"LegalCaseValidationFilter: LegalCase is mandatory. Value Received: {_legalCase}"); context.Result = new BadRequestObjectResult("LegalCase is mandatory"); return; } //Validate Id exists if Request Method is not "POST" var httpPostMethod = context.HttpContext.Request.Method; if (_legalCase.Id == 0 && httpPostMethod != "POST") { _logger.LogInformation($"LegalCaseValidationFilter: Id is mandatory. Value Received: {_legalCase.Id}"); context.Result = new BadRequestObjectResult("Id is mandatory"); return; } //Validate Title if (String.IsNullOrEmpty(_legalCase.Title)) { _logger.LogInformation($"LegalCaseValidationFilter: Title is mandatory. Value Received: {_legalCase.Title}"); context.Result = new BadRequestObjectResult("Title is mandatory"); return; } //Validate Description if (String.IsNullOrEmpty(_legalCase.Description)) { _logger.LogInformation($"LegalCaseValidationFilter: Description is mandatory. Value Received: {_legalCase.Description}"); context.Result = new BadRequestObjectResult("Description is mandatory"); return; } //validate Client_id if (_legalCase.Client_Id == 0) { _logger.LogInformation($"LegalCaseValidationFilter: Client_id is mandatory. Value Received: {_legalCase.Client_Id}"); context.Result = new BadRequestObjectResult("Client_Id is mandatory"); return; } if (_legalCase.Client_Id.GetTypeCode() != TypeCode.Int32) { _logger.LogInformation($"LegalCaseValidationFilter: Client_Id must be a valid number. Value Received: {_legalCase.Client_Id}"); context.Result = new BadRequestObjectResult("Client_Id must be a valid number"); return; } //Validate TrustFund if (_legalCase.TrustFund == 0.0M) { _logger.LogInformation($"LegalCaseValidationFilter: TrustFund is mandatory. Value Received: {_legalCase.TrustFund}"); context.Result = new BadRequestObjectResult("TrustFund is mandatory"); return; } //validate TrustFund Range if (_legalCase.TrustFund < 0.1M) { _logger.LogInformation($"LegalCaseValidationFilter: TrustFund must be more than zero. Value Received: {_legalCase.TrustFund}"); context.Result = new BadRequestObjectResult("TrustFund must be more than zero"); return; } //validate the ModelState if (!context.ModelState.IsValid) { _logger.LogInformation($"LegalCaseValidationFilter: Modelstate is invalid."); context.Result = new BadRequestObjectResult(context.ModelState); return; } }
public LegalCase ProcessAndValidate(LegalCase instance, out List <Exception> exceptions, out bool shouldSuppressProcessing) { ProcessAndValidateCommon(instance, out exceptions, out shouldSuppressProcessing); return(instance); }
public ICollection <object> ParseData(MySqlDataReader dataReader) { var entities = new List <object>(); while (dataReader.Read()) { var entity = new LegalCase { ID = (int)dataReader["ID"], LegalProceedingName = dataReader["LegalProceedingName"] as string, TypeOfCase = dataReader["TypeOfCase"] as string, TypeOfCaseExternalClients = dataReader["TypeOfCaseExternalClients"] as string, TrademarkNumber = dataReader["TrademarkNumber"] as string, Keywords = dataReader["Keywords"] as string, DateAssigned = dataReader["DateAssigned"] as string, CourtURL = dataReader["CourtURL"] as string, DeletionRequest = (dataReader["DeletionRequest"] as sbyte? ?? 0) == 1, DeletionRequestReason = dataReader["DeletionRequestReason"] as string }; if (int.TryParse((dataReader["TrademarkID"] as int?)?.ToString(), out int trademarkID)) { entity.Trademark = new Trademark { ID = trademarkID, Name = dataReader["TrademarkName"] as string }; if (int.TryParse((dataReader["OfficeID"] as int?)?.ToString(), out int officeID)) { entity.Trademark.Office = new Office { ID = officeID, OfficeName = dataReader["OfficeName"] as string }; } } if (int.TryParse((dataReader["PlainTiffID"] as int?)?.ToString(), out int plainTiffID)) { entity.Plaintiff = new Company { ID = plainTiffID, DisplayName = dataReader["PlaintiffName"] as string }; } if (int.TryParse((dataReader["DefendantID"] as int?)?.ToString(), out int defendantID)) { entity.Defendant = new Company { ID = defendantID, DisplayName = dataReader["DefendantName"] as string }; } if (int.TryParse((dataReader["PlaintiffRepresentativeID"] as int?)?.ToString(), out int plaintiffRepresentativeID)) { entity.PlaintiffRepresentative = new Company { ID = plaintiffRepresentativeID, DisplayName = dataReader["PlaintiffRepresentativeName"] as string }; } if (int.TryParse((dataReader["DefendantRepresentativeID"] as int?)?.ToString(), out int defendantRepresentativeID)) { entity.DefendantRepresentative = new Company { ID = defendantRepresentativeID, DisplayName = dataReader["DefendantRepresentativeName"] as string }; } entities.Add(entity); } return(entities); }
public static bool IsValid(LegalCase legalCase, out Dictionary <string, string> validationResult) { validationResult = new Dictionary <string, string>(); return(!validationResult.Any()); }