Click here to Skip to main content
15,917,632 members

Comments by Branden Coker (Top 31 by date)

Branden Coker 18-Dec-16 11:04am View    
Jon,
I think I can figure this out from here. Thank you for all your help. The button I'm trying to get the ID to is actually a save button on the AddNewWitness View. The view has the ID from the defendant It's a matter of converting the data from the fields to the model and persisting it is where my issue is. This is what I'm doing on that..

 private void btnSaveWitness_Click(object sender, RoutedEventArgs e)
        {
            using (DataController context = new DataController())
            {
                DefendantViewModel defendant = new DefendantViewModel();

                defendant.DefendantModel.FirstName = txtFName.Text;
                defendant.DefendantModel.MiddleName = txtMName.Text;
                defendant.DefendantModel.LastName = txtLName.Text;
                defendant.DefendantModel.NameSuffix = txtSuffix.Text;
                defendant.DefendantModel.Race = cboRace.SelectedValue.ToString();
                defendant.DefendantModel.Sex = cboSex.SelectedValue.ToString();

                context.CreateWitness(defendant);
            }
Branden Coker 17-Dec-16 10:10am View    
Jon, Thanks for your response. I forgot to mention that the ID comes from another view when someone selects a Defendant from a list. That part works, if I select the first person in the list I get the correct ID same with any other person. Both my DefendantModel and WitnessModels are below. Sorry I forgot to post them. I have the data access Logic (Linq) in a separate folder.

The Defendant Model:
   public class DefendantModel
    {
        public int ID { get; set; }
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        public string NameSuffix { get; set; }
        public string Alias { get; set; }
        public string SSN { get; set; }
        public string Race { get; set; }
        public string Sex { get; set; }
        public List<WitnessModel> WitnessModelList { get; set; }
        public WitnessModel WitnessModel { get; set; }
    }


The WitnessModel:
 public class WitnessModel
    {
        public int ID { get; set; }
        public int MasterID { get; set; }
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        public string NameSuffix { get; set; }
        public string Sex { get; set; }
        public string Race { get; set; }
    }


Let me know if I have left anything out. Thank you.
Branden Coker 24-Sep-14 15:27pm View    
Thank you for your help as well Afzaal.
Branden Coker 24-Sep-14 15:27pm View    
I was just "fine-tooth combing" my code and I did find that I missed typing in the Context. Thank you for your help. I'll know in the future where the error was made and sorry to waste your time.
Branden Coker 24-Sep-14 15:14pm View    
I created the Model class which houses three classes (Student, Enrollment, Course). After I constructed the class I tried the migration and that is when it failed. I did not however create a SchoolContext as it was not in the tutorial.

I believe this is the complete tutorial and I would imagine they wouldn't skip anything like that being Microsoft but maybe I should run through it again. Thank you for your suggestion. I'll check it out.