public string MasterRecord(AttendanceMaster master) { try { digitalContext = new DigitalEntities(); digitalContext.AttendanceMasters.Add(master); digitalContext.SaveChanges(); return "You signed"; } catch (Exception ex) { return "Register was not signed, Please try again" + ex.Message; } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { SignModel signModel = new SignModel(); if (!Regex.IsMatch(txtHours.Text, "^((?:[0-9]|1[0-9]|2[0-3])(?:\\.\\d{1,2})?|24(?:\\.00?)?)$")) { MessageBox.Show("Invalid input for Hours"); txtHours.Clear(); } else { AttendanceMaster master = new AttendanceMaster(); master.TrainedOn = txtTask.Text; master.AttendanceDate = (DateTime)datePicker.SelectedDate; MessageBox.Show(signModel.MasterRecord(master)); AttendanceDetail detail = new AttendanceDetail(); decimal hrs = decimal.Parse(txtHours.Text, CultureInfo.InvariantCulture); detail.HoursPerDay = hrs; detail.MasterID = master.MasterID; MessageBox.Show(signModel.SignRegister(detail)); txtHours.Clear(); txtTask.Clear(); LoadData(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }