How to insert data in to two tables based on parameters

I have two Entities

public class ProductOption

{

    [Key]     [DatabaseGenerated(DatabaseGeneratedOption.Identity)]     public int OptionId { get; set; }      [Required]     [MaxLength(40)]     public String OptionName { get; set; } 

}

public class ProductOptionValue

{

    [Key]     [DatabaseGenerated(DatabaseGeneratedOption.Identity)]     public int ValueId { get; set; }     public int OptionId { get; set; }      [Required]     [MaxLength(32)]     public String ValueName { get; set; } 

}

ABOVE Entities 1. Optionid –Primary key(ProductOption table) 2. Optionid –foreignkey (ProductOptionValue table)

I have 2 model classes

public class ProductOptionRequest

{

 public string Name { set; get; }  public List<ProductValuesRequest> productValues { get; set; } 

}

public class ProductValuesRequest

{

 public int OptionId { get; set; }  public string ValueName { get; set;} 

}

now I want insert data into those tables

public async Task SaveProductOption(ProductOptionRequest request)

{

        ReturnString returnString = new ReturnString();         ProductOption details = new ProductOption();         details.OptionName = request.Name;         object result = await productOptionRepository.InsertAsync(details, true);         foreach (ProductValuesRequest valueRequest in request.productValues)          {              ProductOptionValue res = new ProductOptionValue();             res.OptionId = valueRequest.OptionId;             res.ValueName = valueRequest.ValueName;             object response = await productOptionValueRepository.InsertAsync(res, true);         }         returnString.StringValue = result != null ? $  "{request.Name} saved successfully" : "";         return returnString;                          

}

I wrote the above pattern. but I don’t want to pass OptionId. So kindly let me know how to write a single insert query without passing OptionId parameter. Because its foreign key of ProductOption tabl

An infinite chessboard problem based on number theory

The squares of an infinite chessboard are numbered as follows: in the zeroth row and column we put 0, and then in every other square we put the smallest non-negative integer that does not appear anywhere below it in the same column nor anywhere to the left of it in the same row. 6 6 01234 5 10325 4 7 23016 7 3210 7 456 7 5 4 7 7 … … … … … … … … … What number will appear in the 2019th row and 1826th column? Can you generalize?

Sharepoint foundation 2013 FBA (Claim based authentication issue)

I’m trying to configure FBA on sharepoint 2013 foundation. Followed each steps described in technet. Still getting error “

An exception occurred when trying to issue security token: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs..

May be in past i have seen some comments regarding this from your side but now not able to get it. Kindly help.

Magento 2 : toggle whole group in system.xml based on field in another group

I have created two groups in system.xml. I need to show/hide group 2 depending on the “Module Enable” field in group 1. But when I use the following code it hides both the sections and does not save anything to configuration table. Please help.

<section id="fancypopup" translate="label" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">         <label>Fancy Popup</label>         <tab>asoft</tab>         <resource>Asoft_Fancypop::config</resource>         <group id="general" translate="label" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">             <label>General Settings</label>             <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">                 <label>Module Enable</label>                 <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>             </field>         </group>         <group id="popup" translate="label" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">             <label>Popup Settings</label>              <field id="show_on" translate="label comment" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Show on</label>                 <source_model>Asoft\Fancypop\Model\Config\Settings\Popup\ShowOn</source_model>             </field>              <field id="active_from" translate="label comment" type="date" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Active from</label>                 <frontend_model>Asoft\Fancypop\Block\Adminhtml\System\Config\Date</frontend_model>             </field>              <field id="active_to" translate="label comment" type="date" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Active to</label>                 <frontend_model>Asoft\Fancypop\Block\Adminhtml\System\Config\Date</frontend_model>             </field>              <field id="delay" translate="label comment" type="text" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Delay(miliseconds)</label>             </field>              <field id="bg_color" translate="label comment" type="text" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Popup Backgroud Color</label>             </field>             <field id="bg_image" translate="label" type="image" sortOrder="170" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Popup Background Image</label>                 <comment>Allowed file types:PNG, GIF, JPG, JPEG.</comment>                 <backend_model>Asoft\Fancypop\Model\Config\Backend\Image\Popupbg</backend_model>                 <base_url type="media" scope_info="1">asoft/fancypop/background</base_url>             </field>             <field id="custom_style" translate="label comment" type="textarea" sortOrder="180" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Custom Style</label>             </field>               <field id="link_to_page" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Link to page</label>             </field>             <field id="width" translate="label comment" type="text" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Popup Width</label>                 <validate>required-entry validate-number</validate>             </field>             <field id="height" translate="label comment" type="text" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Popup Height</label>                 <validate>required-entry validate-number</validate>             </field>             <depends>                 <field id="fancypopup/general/enable">1</field>             </depends>         </group>     </section> 

Use calculation to provide the next Friday based on submission date

I will have our users input “today’s” date on a form, and I want the next field to auto-populate to the next Friday:

So if the submission date is 9/25/2017, the calculated field would be 9/29/2017.
Or if the submission date is 9/29/2017, the calculated field would be 9/29/2017.

Is there a way to use the default date in a date field, or a calculation field to make this happen?

Form validation or model based verification on client side

I’m actually wondering what are the pros and cons of these two ways to handle client side validations / verifications.

Let’s imagine an application where there is a contact form that needs these information:

  • An email address (with a specific format)
  • A postal address (with a specific postal code format)

I have in mind two ways to handle these format verifications:

At the form level

The “usual” way to handle this: we put some verifications based on user inputs and validate / invalidate the information.

Concretely, on the change (or submit, anyway) event of the input we verify the field value with some regexp and modify the current component state to display an error accordingly.

The “backend DDD” way

The idea is to rely on the following statement:

When creating an object, it should always be in a good and consistent shape so that you don’t have to tweak for specific computations everywhere in the app

The idea is to enforce the verifications using schemas and to always rely on consistent objects that we don’t have to tweak in multiple places like modifying one of its internal attributes by hand (implying multiple sanity verifications etc…).

In a concrete world, I would simply rely on a Email.create(rawInputValue) that may throw an error concerning a bad format exception or something like this. Email would be a class definition that owns information on how to build a valid email address.


After this bit of context, I’m wondering what are the pros / cons of these system? Which one do you use and why?

Calculate initial velocity based on displacement, time and constant acceleration.

“A car has a constant speed along a road. It goes down a hill at a constant acceleration. 50s after it goes down the hill the speed is doubled and 50s later it reaches the end of the 200m hill and is back at a constant speed. Find out the initial velocity and acceleration.”

At first I made relevant graphs to see if I could find some useful information from that but no luck. Then I tried to use the “suvat” equations but we haven’t learned them in class so I’m not allowed to use them, which is why I’m stuck as to how to solve this basic problem.

View filter based in text not in number

I have a field in an entity that is an Entity Reference with widget Select list.

I have created a view and I want to be able to filter by that field in text format, but when I try to configure the filter I get the options to do it as if it were a number (is less than, is equal to…) and not as a text (contains, start with…).

Any idea of what I am doing wrong? Thanks!