/// <summary> /// Create a new MetaFeature object. /// </summary> /// <param name="metaFeatureID">Initial value of the MetaFeatureID property.</param> /// <param name="featureName">Initial value of the FeatureName property.</param> public static MetaFeature CreateMetaFeature(global::System.Int32 metaFeatureID, global::System.String featureName) { MetaFeature metaFeature = new MetaFeature(); metaFeature.MetaFeatureID = metaFeatureID; metaFeature.FeatureName = featureName; return metaFeature; }
/// <summary> /// Deprecated Method for adding a new object to the MetaFeatures EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToMetaFeatures(MetaFeature metaFeature) { base.AddObject("MetaFeatures", metaFeature); }
protected void btnAdd_Click(object sender, EventArgs e) { using (eCommerceDBEntities context = new eCommerceDBEntities()) { if (rdoChooseFeature.SelectedValue == "1") { Feature fr = new Feature() { MetaFeatureID = Convert.ToInt16(ddlFeatureName.SelectedValue), ProductID = Convert.ToInt16(txtProductID.Text), FeatureDescription = txtBoxFeatureValue.Text }; context.Features.AddObject(fr); } else if (rdoChooseFeature.SelectedValue == "2") { //Show error on empty textbox if (string.IsNullOrEmpty(txtFeatureName.Text)) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = "Please add a feature name."; } else { //Check if the feature already exists MetaFeature mr = context.MetaFeatures.Where(i => i.FeatureName == txtFeatureName.Text).FirstOrDefault(); int id; //If not found, create new row if (mr == null) { MetaFeature mfr = new MetaFeature() { FeatureName = txtFeatureName.Text }; context.MetaFeatures.AddObject(mfr); context.SaveChanges(); //get the ID which is just created id = mfr.MetaFeatureID; Feature fr = new Feature() { MetaFeatureID = id, ProductID = Convert.ToInt16(txtProductID.Text), FeatureDescription = txtBoxFeatureValue.Text }; context.Features.AddObject(fr); } //if found, update row. else { id = mr.MetaFeatureID; Feature fUpdate = context.Features.Where(i => i.MetaFeatureID == id).FirstOrDefault(); fUpdate.FeatureDescription = txtBoxFeatureValue.Text; } } } context.SaveChanges(); lblStatus.ForeColor = System.Drawing.Color.Green; lblStatus.Text = "Feature added successfully. You can add more!"; } }