public JsonPatchDocument <ApiSaleServerRequestModel> CreatePatch(ApiSaleServerRequestModel model) { var patch = new JsonPatchDocument <ApiSaleServerRequestModel>(); patch.Replace(x => x.IpAddress, model.IpAddress); patch.Replace(x => x.Notes, model.Notes); patch.Replace(x => x.SaleDate, model.SaleDate); patch.Replace(x => x.TransactionId, model.TransactionId); return(patch); }
public virtual ApiSaleServerRequestModel MapServerResponseToRequest( ApiSaleServerResponseModel response) { var request = new ApiSaleServerRequestModel(); request.SetProperties( response.IpAddress, response.Notes, response.SaleDate, response.TransactionId); return(request); }
public virtual ApiSaleServerResponseModel MapServerRequestToResponse( int id, ApiSaleServerRequestModel request) { var response = new ApiSaleServerResponseModel(); response.SetProperties(id, request.IpAddress, request.Notes, request.SaleDate, request.TransactionId); return(response); }
public void MapModelToEntity() { var mapper = new DALSaleMapper(); ApiSaleServerRequestModel model = new ApiSaleServerRequestModel(); model.SetProperties("A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1); Sale response = mapper.MapModelToEntity(1, model); response.IpAddress.Should().Be("A"); response.Notes.Should().Be("A"); response.SaleDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.TransactionId.Should().Be(1); }
public virtual Sale MapModelToEntity( int id, ApiSaleServerRequestModel model ) { Sale item = new Sale(); item.SetProperties( id, model.IpAddress, model.Notes, model.SaleDate, model.TransactionId); return(item); }
public virtual async Task <CreateResponse <ApiSaleServerResponseModel> > Create( ApiSaleServerRequestModel model) { CreateResponse <ApiSaleServerResponseModel> response = ValidationResponseFactory <ApiSaleServerResponseModel> .CreateResponse(await this.SaleModelValidator.ValidateCreateAsync(model)); if (response.Success) { Sale record = this.DalSaleMapper.MapModelToEntity(default(int), model); record = await this.SaleRepository.Create(record); response.SetRecord(this.DalSaleMapper.MapEntityToModel(record)); await this.mediator.Publish(new SaleCreatedNotification(response.Record)); } return(response); }
public virtual async Task <UpdateResponse <ApiSaleServerResponseModel> > Update( int id, ApiSaleServerRequestModel model) { var validationResult = await this.SaleModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { Sale record = this.DalSaleMapper.MapModelToEntity(id, model); await this.SaleRepository.Update(record); record = await this.SaleRepository.Get(id); ApiSaleServerResponseModel apiModel = this.DalSaleMapper.MapEntityToModel(record); await this.mediator.Publish(new SaleUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiSaleServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiSaleServerResponseModel> .UpdateResponse(validationResult)); } }