private void btnSaveContact_Click(object sender, RoutedEventArgs e)
 {
     var viewModel = new ContactFormViewModel();
     viewModel.ContactName = txtName.Text;
     viewModel.Organization = txtOrganization.Text;
     viewModel.Designation = txtDesignation.Text;
     viewModel.DateOfBirth = DateTime.Parse(txtBirthDate.Text != "" ? txtBirthDate.Text : "12/07/1990");
     viewModel.IsSpecial = Convert.ToBoolean(chkIsSpecial.IsChecked);
     viewModel.IsIndian = Convert.ToBoolean(chkIsIndian.IsChecked);
     viewModel.IsOther = Convert.ToBoolean(chkIsOther.IsChecked);
     viewModel.PhoneNumber = txtPhoneNumber.Text; ;
     viewModel.Address = txtAddress.Text;
     viewModel.Email = txtEmail.Text;
     var chkValidation = new Validations();
     var result = chkValidation.PerformMandatoryContactValidations(viewModel);
     if (result.Result == "Success")
     {
         StudioRepository.InsertContact(viewModel);
         var msgbox = new BookerStudioMessageBox("Added contact successfully", "A new contact was added successfully!", GuestBookerMessageBoxButtons.Ok, IconType.Attention);
         msgbox.ShowDialog();
         MainWindow.MainStatusBarMessage.Text = "A new contact was added successfully.";
     }
     else if (result.Result == "Failure")
     {
         var msgBox = new BookerStudioMessageBox(result.TypeOfException, result.Message, GuestBookerMessageBoxButtons.Ok, IconType.Attention);
         msgBox.ShowDialog();
     }
 }
예제 #2
0
 public ValidationsStructure PerformMandatoryContactValidations(ContactFormViewModel viewModel)
 {
     var validationResult = new ValidationsStructure();
     if (viewModel.Organization != String.Empty && viewModel.ContactName!=String.Empty && viewModel.PhoneNumber != String.Empty)
     {
         validationResult.Result = "Success";
         validationResult.Message = "A new contact has been added successfully!";
         validationResult.TypeOfException = String.Empty;
         return validationResult;
     }
     else
     {
         validationResult.Result = "Failure";
         validationResult.Message = "Some fields are mandatory. Please provide values for all the fields and try again.";
         validationResult.TypeOfException = "MandatoryFieldsNotEnteredException";
         return validationResult;
     }
 }
        private void cmdSaveContact_Click(object sender, RoutedEventArgs e)
        {
            var viewModel = new ContactFormViewModel();
            viewModel.ContactName = txtName.Text;
            viewModel.Organization = txtOrganization.Text;
            viewModel.DateOfBirth = DateTime.Parse(txtBirthDate.Text);
            viewModel.Designation = txtDesignation.Text;
            viewModel.IsIndian = chkIndian.IsChecked.Value;
            viewModel.IsOther = chkOther.IsChecked.Value;
            viewModel.IsSpecial = chkIsSpecial.IsChecked.Value;
            viewModel.PhoneNumber = txtPhoneNumber.Text;
            viewModel.Address = txtAddress.Text;
            viewModel.Email = txtEmail.Text;
            StudioRepository.UpdateContact(viewModel);

            var msgbox = new BookerStudioMessageBox("Saved successfully", "The contact has been saved successfully!", GuestBookerMessageBoxButtons.Ok, IconType.Info);
            msgbox.ShowDialog();
            MainWindow.MainStatusBarMessage.Text = "The changes made were saved successfully.";
        }
 public static void UpdateContact(ContactFormViewModel viewModel)
 {
     var model = Repository.ECCContacts.Where(c => c.Organization == viewModel.Organization && c.Name == viewModel.ContactName).SingleOrDefault();
     model.Name = viewModel.ContactName;
     model.Organization = viewModel.Organization;
     model.Designation = viewModel.Designation;
     model.DateOfBirth = viewModel.DateOfBirth;
     model.IsOther = viewModel.IsOther;
     model.IsIndian = viewModel.IsIndian;
     model.IsSpecial = viewModel.IsSpecial;
     model.PhoneNumber = viewModel.PhoneNumber;
     model.Address = viewModel.Address;
     model.Email = viewModel.Email;
     Repository.SubmitChanges();
 }
 public static void InsertContact(ContactFormViewModel viewModel)
 {
     var model = new ECCContact();
     model.Name = viewModel.ContactName;
     model.Organization = viewModel.Organization;
     model.Designation = viewModel.Designation;
     model.DateOfBirth = viewModel.DateOfBirth;
     model.IsOther = viewModel.IsOther;
     model.IsIndian = viewModel.IsIndian;
     model.IsSpecial = viewModel.IsSpecial;
     model.PhoneNumber = viewModel.PhoneNumber;
     model.Address = viewModel.Address;
     model.Email = viewModel.Email;
     Repository.ECCContacts.InsertOnSubmit(model);
     Repository.SubmitChanges();
 }