public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiBusinessEntityContactRequestModel model) { this.ContactTypeIDRules(); this.ModifiedDateRules(); this.PersonIDRules(); this.RowguidRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiBusinessEntityContactResponseModel> CreateRecord(ApiClient client) { var model = new ApiBusinessEntityContactRequestModel(); model.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); CreateResponse <ApiBusinessEntityContactResponseModel> result = await client.BusinessEntityContactCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiBusinessEntityContactRequestModel model) { CreateResponse <ApiBusinessEntityContactResponseModel> result = await this.BusinessEntityContactService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/BusinessEntityContacts/{result.Record.BusinessEntityID}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapResponseToRequest() { var mapper = new ApiBusinessEntityContactModelMapper(); var model = new ApiBusinessEntityContactResponseModel(); model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); ApiBusinessEntityContactRequestModel response = mapper.MapResponseToRequest(model); response.ContactTypeID.Should().Be(1); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PersonID.Should().Be(1); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
private async Task <ApiBusinessEntityContactRequestModel> PatchModel(int id, JsonPatchDocument <ApiBusinessEntityContactRequestModel> patch) { var record = await this.BusinessEntityContactService.Get(id); if (record == null) { return(null); } else { ApiBusinessEntityContactRequestModel request = this.BusinessEntityContactModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual BOBusinessEntityContact MapModelToBO( int businessEntityID, ApiBusinessEntityContactRequestModel model ) { BOBusinessEntityContact boBusinessEntityContact = new BOBusinessEntityContact(); boBusinessEntityContact.SetProperties( businessEntityID, model.ContactTypeID, model.ModifiedDate, model.PersonID, model.Rowguid); return(boBusinessEntityContact); }
public virtual async Task <CreateResponse <ApiBusinessEntityContactResponseModel> > Create( ApiBusinessEntityContactRequestModel model) { CreateResponse <ApiBusinessEntityContactResponseModel> response = new CreateResponse <ApiBusinessEntityContactResponseModel>(await this.BusinessEntityContactModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolBusinessEntityContactMapper.MapModelToBO(default(int), model); var record = await this.BusinessEntityContactRepository.Create(this.DalBusinessEntityContactMapper.MapBOToEF(bo)); response.SetRecord(this.BolBusinessEntityContactMapper.MapBOToModel(this.DalBusinessEntityContactMapper.MapEFToBO(record))); } return(response); }
public void CreatePatch() { var mapper = new ApiBusinessEntityContactModelMapper(); var model = new ApiBusinessEntityContactRequestModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); JsonPatchDocument <ApiBusinessEntityContactRequestModel> patch = mapper.CreatePatch(model); var response = new ApiBusinessEntityContactRequestModel(); patch.ApplyTo(response); response.ContactTypeID.Should().Be(1); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PersonID.Should().Be(1); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public async void Create() { var mock = new ServiceMockFacade <IBusinessEntityContactRepository>(); var model = new ApiBusinessEntityContactRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <BusinessEntityContact>())).Returns(Task.FromResult(new BusinessEntityContact())); var service = new BusinessEntityContactService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BusinessEntityContactModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBusinessEntityContactMapperMock, mock.DALMapperMockFactory.DALBusinessEntityContactMapperMock); CreateResponse <ApiBusinessEntityContactResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.BusinessEntityContactModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBusinessEntityContactRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <BusinessEntityContact>())); }
public async void Delete() { var mock = new ServiceMockFacade <IBusinessEntityContactRepository>(); var model = new ApiBusinessEntityContactRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new BusinessEntityContactService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BusinessEntityContactModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBusinessEntityContactMapperMock, mock.DALMapperMockFactory.DALBusinessEntityContactMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.BusinessEntityContactModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiBusinessEntityContactResponseModel> > Update( int businessEntityID, ApiBusinessEntityContactRequestModel model) { var validationResult = await this.BusinessEntityContactModelValidator.ValidateUpdateAsync(businessEntityID, model); if (validationResult.IsValid) { var bo = this.BolBusinessEntityContactMapper.MapModelToBO(businessEntityID, model); await this.BusinessEntityContactRepository.Update(this.DalBusinessEntityContactMapper.MapBOToEF(bo)); var record = await this.BusinessEntityContactRepository.Get(businessEntityID); return(new UpdateResponse <ApiBusinessEntityContactResponseModel>(this.BolBusinessEntityContactMapper.MapBOToModel(this.DalBusinessEntityContactMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiBusinessEntityContactResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiBusinessEntityContactRequestModel model) { ApiBusinessEntityContactRequestModel request = await this.PatchModel(id, this.BusinessEntityContactModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiBusinessEntityContactResponseModel> result = await this.BusinessEntityContactService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiBusinessEntityContactRequestModel> patch) { ApiBusinessEntityContactResponseModel record = await this.BusinessEntityContactService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiBusinessEntityContactRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiBusinessEntityContactResponseModel> result = await this.BusinessEntityContactService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }