private int GetOrSetEmployeeRecord(Wave_X1_MainEntities dbContext, string employeeName, string address) { var names = employeeName.Split(new char[] { ' ' }); string firstName = names[0]; string lastName = names[1]; var emp = dbContext.Employees.Where(x => x.FirstName == firstName && x.LastName == lastName).FirstOrDefault(); if (emp == null) { DataAccess.Employee newEmployee = new DataAccess.Employee { FirstName = firstName, LastName = lastName, Address = address, CreatedDate = DateTime.Now }; dbContext.Employees.Add(newEmployee); dbContext.SaveChanges(); return(newEmployee.EmployeeId); } else { return(emp.EmployeeId); } }
public Employee MapToModel(DataAccess.Employee employee) { return(new Employee { EmployeeId = new Field(employee.EmployeeId.ToString()), EmployeeCode = new Field(employee.EmployeeCode), EmployeeName = new Field(employee.EmployeeName), PostCode = new Field(employee.PostCode), Address = new Field(employee.Address), Salary = new Field(employee.Salary.ToString(CultureInfo.InvariantCulture)), }); }
void btnSave_Click(object sender, EventArgs e) { try { DataAccess.Employee employee = new DataAccess.Employee(); employee.EmployeeNumber = txtEmployeeNumber.Text.ToInteger(); employee.Title = txtTitle.Text; employee.FirstName = txtFname.Text; employee.MiddleName = txtMname.Text; employee.LastName = txtLname.Text; employee.Age = txtAge.Text.ToInteger(); employee.Birthdate = txtBirthDate.Text.ToDate(); employee.Sex = char.Parse(ddlSex.SelectedValue); employee.CivilStatus = ddlCivilStatus.SelectedValue; employee.HomePhone = txtHomePhone.Text; employee.MobilePhone = txtMobile.Text; employee.Email = txtEmail.Text; employee.PresentHomeAddressId = Guid.NewGuid(); employee.DepartmentCode = ddlDepartment.SelectedValue; employee.PositionCode = ddlPosition.SelectedValue; employee.TaxStatusCode = ddlTaxStatus.SelectedValue; employee.HireDate = txtHiredDate.Text.ToDate(); employee.EmployementTypeCode = ddlEmployeeType.SelectedValue; employee.SSSNumber = txtSSSNumber.Text.ToInteger(); employee.TINNumber = txtTIN.Text.ToInteger(); employee.PagIbigNumber = txtPagIbig.Text.ToNullableInteger(); employee.PhilHealthNumber = txtPhilHealth.Text.ToNullableInteger(); employee.SalaryRate = txtSalaryRate.Text; employee.CurrentSalary = txtCurrentSalary.Text.ToDecimal(); employee.BankNameCode = ddlBankName.SelectedValue; employee.AccountNumber = txtAccountNumber.Text.ToNullableInteger(); employee.EmployeeStatus = ddlEmpStatus.SelectedValue; DataAccess.EmployeeAddress address = new DataAccess.EmployeeAddress(); address.AddressTypeCode = "Permanent"; address.Address = txtAddress.Text; address.CityMun = TxtCityMun.Text; address.ProvState = string.IsNullOrEmpty(txtProvState.Text) ? null: txtProvState.Text; address.CountryCode = string.IsNullOrEmpty(ddlCountry.SelectedValue)? null: ddlCountry.SelectedValue; address.ZipCode = txtZipCode.Text; DAEmployee empService = new DAEmployee(); var exist = empService.FindByEmployeeNumber(employee.EmployeeNumber); if (exist == null) { //save employee and return the id var id = empService.Create(employee); //save address address.EmployeeId = id; empService.CreateAddress(address); SetMessage(MessageType.Succes, "Saving successfull"); } else SetMessage(MessageType.Error, "Employee number already exist"); } catch (Exception ex) { SetMessage(MessageType.Error , string.Format( "Saving failed: {0}",ex.Message)); } }
protected void BtnLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtName.Value) || string.IsNullOrEmpty(txtPassword.Value) || string.IsNullOrEmpty(txtusername.Value) || string.IsNullOrEmpty(txtpassword2.Value) || string.IsNullOrEmpty(txtmobile.Value) || string.IsNullOrEmpty(txtadress.Value) || string.IsNullOrEmpty(txtFamily.Value)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('اطلاعات را کامل وارد کنید ! ');", true); txtImage.Value = ""; FillImageText(); return; } if ( (txtusername.Value.Length > 50) || (txtName.Value.Length > 50) || (txtFamily.Value.Length > 50) || (txtEmail.Value.Length > 150) || (txtPassword.Value.Length > 50) || (txtzip.Value.Length > 10) || (txtmobile.Value.Length > 11) || (txtadress.Value.Length > 150) || (txtpassword2.Value.Length > 50) || (txtImage.Value.Length > 5) ) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('اطلاعات ورودی بیش از حد مجاز');", true); txtImage.Value = ""; FillImageText(); return; } if (txtmobile.Value.Length < 11) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('شماره موبایل 11 رقمی خود را وارد کنید');", true); txtImage.Value = ""; FillImageText(); return; } if (txtzip.Value != "") { if (txtzip.Value.Length < 10) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('کد پستی 10 رقمی خود را وارد کنبد');", true); txtImage.Value = ""; FillImageText(); return; } } EmployeesRepository em = new EmployeesRepository(); UsersRepository urr = new UsersRepository(); if (rdiEmployees.Checked && em.isThereUsername(txtusername.Value)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('این نام کاربری از قبل وجود دارد');", true); txtImage.Value = ""; FillImageText(); txtusername.Value = ""; return; } if (em.isThereEmail(txtEmail.Value)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('این ایمیل از قبل وجود دارد');", true); txtImage.Value = ""; FillImageText(); txtEmail.Value = ""; return; } if (rdiUsers.Checked && urr.isThereUsername(txtusername.Value)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('این نام کاربری از قبل وجود دارد');", true); txtImage.Value = ""; FillImageText(); txtusername.Value = ""; return; } if (txtPassword.Value != txtpassword2.Value) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('رمز های عبور مطابقت ندارند');", true); txtImage.Value = ""; FillImageText(); return; } if (Session["ImgValue"].ToString() != null) { if (Session["ImgValue"].ToString() == txtImage.Value.ToUpper()) { //lblWarning.Text = "کد وارد شده صحیح می باشد"; //FillImageText(); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('کد تصویر وارد شده صحیح نمی باشد');", true); txtImage.Value = ""; FillImageText(); return; } } /////////////////////////////////////////////////////////////////////////////////// bool Employee = false; bool User = false; bool isComplete = true; try { using (TransactionScope ts = new TransactionScope()) { if (rdiUsers.Checked) { DataAccess.User u = new DataAccess.User(); u.Address = txtadress.Value; u.FirstName = txtName.Value; u.LastName = txtFamily.Value; u.Mobile = txtmobile.Value; u.PostalCode = txtzip.Value; u.Password = txtPassword.Value; u.UserName = txtusername.Value; u.City = ddlCity.SelectedValue.ToInt(); u.State = ddlState.SelectedValue.ToInt(); u.Email = txtEmail.Value; u.RegSeen = false; UsersRepository ur = new UsersRepository(); ur.SaveUsers(u); int id = ur.getLastUserID(); Session.Add("userid", id); Session.Timeout = 20; User = true; } else { DataAccess.Employee u = new DataAccess.Employee(); u.Address = txtadress.Value; u.FirstName = txtName.Value; u.LastName = txtFamily.Value; u.Mobile = txtmobile.Value; u.PostalCode = txtzip.Value; u.Password = txtPassword.Value; u.Score = 0; u.empImage = "/img/user128px.png"; u.UserName = txtusername.Value; u.City = ddlCity.SelectedValue.ToInt(); u.State = ddlState.SelectedValue.ToInt(); u.Email = txtEmail.Value; u.RegSeen = false; EmployeesRepository ur = new EmployeesRepository(); ur.SaveEmployees(u); int id = ur.getLastEmployeeID(); Session.Add("employeeid", id); Session.Timeout = 20; Employee = true; } ts.Complete(); } } catch (Exception m) { string txt = m.Message; isComplete = false; } if (isComplete) { if (Employee) { Response.Redirect("/Employee/Profile"); } else { Response.Redirect("/User/Profile"); } } }