public JsonResult Add_Post(User user) { TryUpdateModel(user, null, new[] { "Id", "FirstName", "LastName", "EmailPersonal", "DateofBirth", "DateofJoining", "Gender", "Status", "RoleId" }); var res = _bal.AddEmployee(user); if (!string.IsNullOrEmpty(res.Password) || !string.IsNullOrEmpty(res.UniqueEmpCode)) { user.Password = res.Password; user.UniqueEmpCode = res.UniqueEmpCode; _bal.SendEmail(user); Success("User " + user.FirstName + "created successfully Please check your mail", true); //return RedirectToAction("ViewList"); return(Json(user, JsonRequestBehavior.AllowGet)); } else { return(null); //return View(); } }
private void Submit_Click(object sender, RoutedEventArgs e) { string str; string mob1 = txtMobile1.Text.ToString(); string mob2 = txtMobile2.Text.ToString(); string emppw = txtEmpPW.Text.ToString(); string empemail = txtEmailId.Text.ToString(); DataTable dt = new DataTable(); dt = _objbal.chkempmo(mob1); int MOB1 = Convert.ToInt32(dt.Rows[0][0].ToString()); DataTable dt1 = new DataTable(); dt1 = _objbal.chkempmo2(mob2); int MOB2 = Convert.ToInt32(dt1.Rows[0][0].ToString()); DataTable dt2 = new DataTable(); dt2 = _objbal.chkempemail(empemail); int eml = Convert.ToInt32(dt2.Rows[0][0].ToString()); try { if (txtFirstName.Text == "" && txtLastName.Text == "") { MessageBox.Show("Please Enter the Details"); } else if (txtEmailId.Text.Length == 0) { MessageBox.Show("Enter an email."); txtEmailId.Focus(); } else if (txtMobile1.Text.Length == 0) { MessageBox.Show("Enter the Mobile Number."); txtMobile1.Focus(); } else if (txtMobile2.Text.Length == 0) { MessageBox.Show("Enter the Mobile Number."); txtMobile2.Focus(); } else if (txtFileName.Text == "") { MessageBox.Show("Enter an Image."); txtFileName.Focus(); } else if (!Regex.IsMatch(txtEmailId.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Enter a valid email."); txtEmailId.Select(0, txtEmailId.Text.Length); txtEmailId.Focus(); } else if (!Regex.IsMatch(txtMobile1.Text, @"^\d{10}$")) { MessageBox.Show("Enter a valid Mobile Number."); txtMobile1.Select(0, txtMobile1.Text.Length); txtMobile1.Focus(); } else if (!Regex.IsMatch(txtMobile2.Text, @"^\d{10}$")) { MessageBox.Show("Enter a valid Mobile Number."); txtMobile2.Select(0, txtMobile1.Text.Length); txtMobile2.Focus(); } else if (cmbrestcode.Text == "" || cmbrestcode.Text == null) { MessageBox.Show("Please select the Restaurant"); cmbrestcode.Focus(); } else if (cmbusercode.Text == "" || cmbusercode.Text == null) { MessageBox.Show("Please select the UserType"); cmbusercode.Focus(); } else if (cmbactive.Text == "" || cmbactive.Text == null) { MessageBox.Show("Please select the Availability"); cmbactive.Focus(); } else if (cmbusercode.SelectedIndex == 0) { MessageBox.Show("Please select the UserType"); cmbusercode.Focus(); } else if (cmbrestcode.SelectedIndex == 0) { MessageBox.Show("Please select the Restaurant"); cmbrestcode.Focus(); } else if (MOB1 >= 1) { MessageBox.Show("The Mobile Number is already Registered", "Mobile1", MessageBoxButton.OK, MessageBoxImage.Information); txtMobile1.Focus(); txtMobile1.SelectAll(); } else if (MOB2 >= 1) { MessageBox.Show("The Mobile Number is already Registered", "Mobile2", MessageBoxButton.OK, MessageBoxImage.Information); txtMobile2.Focus(); txtMobile2.SelectAll(); } else if (eml >= 1) { MessageBox.Show("The EmailId is already Registered", "Email", MessageBoxButton.OK, MessageBoxImage.Information); txtEmailId.Focus(); txtEmailId.SelectAll(); } else { FileStream fs = new FileStream(txtFileName.Text, FileMode.Open, FileAccess.Read); byte[] imgByteArr = new byte[fs.Length]; string[] files = fs.Name.Split(new char[] { '\\' }); string fileName = files[files.Length - 1]; Stream stream = new MemoryStream(imgByteArr); SqlCommand com = new SqlCommand(); ep.First_Name = txtFirstName.Text; ep.Last_Name = txtLastName.Text; ep.Address1 = txtAddress1.Text; ep.Address2 = txtAddress2.Text; ep.Mobile1 = txtMobile1.Text; ep.Mobile2 = txtMobile2.Text; ep.CustPhoneNumber = txtMobile1.Text; ep.CustomerFName = txtFirstName.Text; ep.CustomerLName = txtLastName.Text; ep.Billing_Address = txtAddress1.Text; ep.Delivery_Addresss = txtAddress2.Text; ep.CustomerTypeId = 5; str = cmbactive.SelectionBoxItem.ToString(); ep.Active = Boolean.Parse(str); ep.RestCode = cmbrestcode.SelectedValue.ToString().Trim().ToUpper(); ep.Remarks = txtRemarks.Text; ep.UserTypeId = int.Parse(cmbusercode.SelectedIndex.ToString()); ep.UserCode = cmbusercode.SelectedValue.ToString().Trim().ToUpper(); ep.EmailId = txtEmailId.Text; using (BinaryReader br = new BinaryReader(fs)) { byte[] bytes = br.ReadBytes((Int32)fs.Length); ep.Image = bytes; string Emp = _objbal.AddEmployee(ep); string customer = _objbal.AddEmpDtlstoCustomer(ep); MessageBox.Show("Employee Added Successfully", "Employee information", MessageBoxButton.OK, MessageBoxImage.Information); GetEmpdetails(); Clearcontrols(); Edit.IsEnabled = true; Changepw.IsEnabled = true; imgPhoto.Source = null; txtFileName.Text = ""; } } } catch (Exception ex) { throw ex; } }