How to make Automapper ignore records based on a value of a field - automapper-6

Hi I am trying to use Automapper 6 and want to ignore records based on specific value in a field. I wish there was a way to skip records like so:
CreateMap<CsfbFile, Common.Entities.FuturesExtract>()
.ForMember(dest => dest, opt => opt.Skip(source => source.Ccy == "BASE CURRENCY GRAND TOTAL"))
.ForMember(dest => dest.OptionValue, m => m.ResolveUsing(s => s.OptionsLmv + s.OptionsSmv));
Is there a way to do this ?
Thanks

Related

FluentValidation properties conditions

I have two properties that must be validated, but once at a time. If one is null then validate the other, so I was trying like this :
RuleFor(a => a.CNPJ).Must(a => CNPHelper.CheckCNPJ(a)).When(a => !string.IsNullOrEmpty(a.CPF));
RuleFor(a => a.CPF).Must(a => CNPHelper.CheckCPF(a)).When(a => !string.IsNullOrEmpty(a.CNPJ));
But the must is mandatory, how to change it ?
Can you please try DependentRules extension.
As from docs (https://fluentvalidation.net/start#conditions) reference, you can achieve it as
RuleFor(x => x.Surname).NotNull().DependentRules(() => {
RuleFor(x => x.Forename).NotNull();
});

Displaying choice based on foreign key / join

I have folowing schema:
Template
UserTemplate
template_id
Costs
template_id
amount
value
What I'm trying to do, is to create a sfWidgetFormDoctrineChoice that displays the shipping costs based on a UserTemplate id.
$this->widgetSchema['cost'] = new sfWidgetFormDoctrineChoice(array(
'model' => 'Costs',
'key_method' => 'getValue',
'method' => 'getAmount',
'add_empty' => 'Please Select Amount',
'expanded' => false,
'multiple' => false
));
This displays all of the Costs.
Ideally, I'd like it to limit it to the UserTemplate.
I have looked at creating a custom query and passing that into the widget, but I'm not sure if this would be the correct way of doing this
So If I have a bunch of costs assigned to the template id of 12 and the user template references 12, when I'm on example.com/user-template/12 - I'd expect to see the costs for this in my form widget.
Creating a custom query and passing it to the widget is exaclty what you're looking for. You will have to build the query depending on the template_id you use in the URL.

Use different color for different values in drop down for excel files created

I need to create an excel sheet with a field status. It is a drop down with values 'High', 'Medium', and 'Low'. I need to show different colors when they select different values. I have implemented the drop down using writeexcel gem. Here is my code:
worksheet.data_validation(count, 5,
{
:validate => 'list',
:source => ['High', 'Medium', 'Low'],
})
The drop down is working fine. But I want to specify a color for each selection. I can color the cell based on the selection of the dropdown, but what I need is different colors for different selections of the drop down. Any other gem having this implementation is also fine.
The write_xlsx gem is an updated version of writeexcel that supports the newer Excel 2007+ XLSX format. It is by the same author and has the same interface but has additional features.
One of these new features is Conditional Formating.
You can use it to apply conditional formats to the same cell as the drop-down validation like this:
worksheet.conditional_formatting(count, 5,
{
:type => 'cell',
:format => format1,
:criteria => '=',
:value => '"High"'
}
)
worksheet.conditional_formatting(count, 5,
{
:type => 'cell',
:format => format2,
:criteria => '=',
:value => '"Medium"'
}
)
...
You will need to define the formats using the standard interface.
Note, write_xlsx is a port of the Perl module Excel::Writer::XLSX. That module contains additional documentation on the use of conditional formats. You should be able to convert the examples to Ruby easily enough.
See also my answer to your previous question.

Rails 3 - Custom JSON with Conditions

I'm trying to DRY up my code and I have two methods that do almost the same thing but add an extra fields for one instance. It is formatting JSON in Rails and trying to see if there is a way where I can perform an if statement within the result.collect similar to below. Any help is much appreciated
results.collect{ |result| { :type => defined?(result.type) ? result.type : "Total",
:jan => result.jan, :feb => result.feb, :mar => result.mar, :apr => result.apr,
:may => result.may, :jun => result.jun, :jul => result.jul, :aug => result.aug,
:sep => result.sep, :oct => result.oct, :nov => result.nov, :dec => result.dec } }
in this statement
:type => defined?(result.type) ? result.type : "Total"
I want to be able perform a check if result.type exists in the query then list it else just put "Total"
Any ideas how to perform this? Thanks everyone
I ended up writing in the method to check if with_type or not. If true then I added the type select statement in and if false then added
Select 'Total' as Type
I was hoping to figure out how to modify the json as in the question but modifying the composed_scope worked too.

In Symfony how to set default values to sfWidgetFormDateRange from action

In Symfony how to set default values to sfWidgetFormDateRange from action
Basically you have to do the following:
$form->setDefault('field_name', array('from' => 'yesterday', 'to' => '+10 years'))
These yesterday and +10 years chants actually are anything suitable for strtotime function. Also, you could pass explicit dates without casting any magic:
$form->setDefault('field_name', array('from' => array('month' => 10, 'day' => 12, 'year' => 1984), 'to' => '+10 years'))

Resources