The project i am working on requires me to put check boxes on a form for the user to possibly select more than one item. I could just put these as bool in individual columns but the check box values may change or need added to. So i created a table that holds the names of these check boxes and then list them out. My question is; how do i get those values into another table that coincides with the customer. How should this be handled properly?
The view has the company name and record id /AuditSchedule/details/208 I have read that it is not good practice to put more than one value in a column but what other choice do i have?
thanks much!
What i have for the table of customers is a field for ProductType. This is not linked to anything. There is another table with the Product types which i want to list out as check boxes. I do not have any relationship between these two tables. To me doesn't seem like there should be but please correct me and let me know if there is supposed to be. So when a check box is selected i want that value (ProductName) to be put in the customer table in the ProductType field separated with commas.
Here is Customer or Schedule table:
public class AuditSchedule
{
public virtual int AuditScheduleID { get; set; }
public virtual Nullable<DateTime> audit_completed_date { get; set; }
public virtual string gl_cmp_key { get; set; }
public virtual string audit_year { get; set; }
public virtual string ar_ship_key { get; set; }
public virtual string ar_ship_name { get; set; }
public virtual string im_adres_city { get; set; }
public virtual string im_adres_state { get; set; }
public virtual string audit_type { get; set; }
public virtual string audit_no { get; set; }
public virtual string audit_group { get; set; }
public virtual string Footage { get; set; }
public virtual string Rolling3MosFootage { get; set; }
public virtual string snp_SalesRep8 { get; set; }
public virtual string epg_sales_rep_accountable { get; set; }
public virtual string tech_service_rep { get; set; }
public virtual string audit_done_by { get; set; }
public virtual Nullable<DateTime> audit_recieved_date { get; set; }
public virtual string audit_notes { get; set; }
public virtual string audit_pdf { get; set; }
public virtual string updated { get; set; }
public virtual string hidden { get; set; }
public virtual string en_stats_key { get; set; }
public virtual string Control_ID { get; set; }
public virtual Nullable<DateTime> audit_date { get; set; }
public virtual string contacts_present { get; set; }
public virtual string audit_furnished_to { get; set; }
public virtual string spacer_type { get; set; }
}
Here is the Product Table:
public class SpacerProduct
{
public int SpacerProductID { get; set; }
public string SpacerBrand { get; set; }
public string SpacerName { get; set; }
}
Hope this helps
The view is a form type edit for AuditSchedules with only a few places that get filled in. That part works. Adding the check boxes to the view is where i am lost. I created a partial view that populates a ToList of the checkboxes and then added that to the form. Not sure how to get the results in the table.
Questions for Tohid: I have question about a few things. Firstly the ViewModel I am assuming that this is just a namespace you have for your Models directory where mine is just Models. _db.getAuditScheduleById is not in my Entities which you explained that i might have to do another way. For me it would be _db.AuditSchedules it appears in the dropdown but does not like it so i changed it to be Updated 07/02/2012 viewModel.AuditScheduleInstance = _db.AuditSchedules.Single(r => r.AuditScheduleID == id);
I am still having an issue on the
_db.GetAvailableSpacerProducts()
i do not have anything in my entities that reflects that and i am not sure how to change it. Possibly something like what i changed in the other one but not sure.
Updated 07/05/2012
Here is the QQAEntities:
namespace QQAForm.Models
{
public class QQAEntities : DbContext
{
public DbSet<AuditSchedule> AuditSchedules { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<SubCategory> SubCategories { get; set; }
public DbSet<MainQuestion> MainQuestions { get; set; }
public DbSet<Suggestion> Suggestions { get; set; }
public DbSet<DocumentLink> DocumentLinks { get; set; }
public DbSet<Audit> Audits { get; set; }
public DbSet<AuditData> AuditDatas { get; set; }
public DbSet<SpacerProduct> SpacerProducts { get; set; }
public DbSet<ScoreCard> ScoreCards { get; set; }
}
}
I also have another project in my solution called QQAForm.Data this only controls the roles and security for everything that is involved with memberships. Hope this helps. thank you for your time and patience.
Updated 07/06/2012
Final Working Edit:
[HttpPost]
public ActionResult Edit(AuditScheduleEdit viewModel)
{
if (ModelState.IsValid)
{
viewModel.PopulateCheckBoxsToSpacerType();
_db.Entry(viewModel.AuditScheduleInstance).State = System.Data.EntityState.Modified;
_db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return View(viewModel);
}
}
Updated 08/02/2012
I have decided that i can use this in other areas of this project. I have multiple places where i use checkboxes.
I tried to implement this on another view and it is not working. The reason it does not work is because in order to populate the checkboxes it lookes at an ID in the current table so it can update it. This is the snippet:
//get
public ActionResult _Forms(int id)
{
AuditFormEdit viewModel = new AuditFormEdit();
viewModel.ScoreInstance = _db.MainAnswers.Single(r => r.MainAnswerID == id);
viewModel.InitializeScoreCheckBoxHelperList(_db.Scores.ToList());
return View(viewModel);
}
//post
[HttpPost]
public ActionResult _Forms(int id, AuditFormEdit viewModel)
{
if (ModelState.IsValid)
{
viewModel.PopulateCheckBoxsToScores();
_db.Entry(viewModel.ScoreInstance).State = System.Data.EntityState.Modified;
_db.SaveChanges();
return RedirectToAction("/");
}
else
{
return View(viewModel);
}
}
The (r => r.MainAnswerID == id) is the issue. MainAnswer is the table that needs updated. The record should also insert AuditScheduleID, MainQuestionID, and text populated from the checkbox for Score. If I comment this out i get nothing to show up. What i really need is a way to take this and insert a new record with the data. Not sure how to change the code to do this.