public ActionResult Index(IList <EmployeeService.Employee> employees) { ViewBag.Connection = GetServerName(); if (employees == null) { return(RedirectToAction("Index")); } EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient(); if (ModelState.IsValid) { client.DeleteEmployee(0); foreach (var employee in employees) { if (employee.Id == 0) { continue; //If employee with Id=0 has been entered in the view, ignore he/she, will not be stored in db and will disapear in next page load } if (client.GetEmployee(employee.Id) == null) { client.SaveEmployee(employee); //employee doesn't exist in Db, Create new } else { client.UpdateEmployee(employee); //employee do exist in Db, Update } } } return(RedirectToAction("Index")); }
protected void btnSave_Click(object sender, EventArgs e) { EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient(); EmployeeService.Employee employee = null; string message = string.Empty; if (((EmployeeService.EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue)) == EmployeeService.EmployeeType.FullTimeEmployee) { employee = new EmployeeService.FullTimeEmployee { ID = Convert.ToInt32(txtID.Text), Name = txtName.Text, Gender = txtGender.Text, DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text), Type = EmployeeService.EmployeeType.FullTimeEmployee, AnnualSalary = Convert.ToInt32(txtAnnualSalary.Text), }; client.SaveEmployee(employee); lblMessage.Text = "Employee saved"; } else if (((EmployeeService.EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue)) == EmployeeService.EmployeeType.PartTimeEmployee) { employee = new EmployeeService.PartTimeEmployee { ID = Convert.ToInt32(txtID.Text), Name = txtName.Text, Gender = txtGender.Text, DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text), Type = EmployeeService.EmployeeType.PartTimeEmployee, HourlyPay = Convert.ToInt32(txtHourlyPay.Text), HoursWorked = Convert.ToInt32(txtHoursWorked.Text), }; client.SaveEmployee(employee); lblMessage.Text = "Employee saved"; } else { lblMessage.Text = "Please select Employee Type"; } }
protected void btnSave_Click(object sender, EventArgs e) { EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient(); //EmployeeService.Employee employee = new EmployeeService.Employee(); EmployeeService.Employee employee = null; if ((EmployeeService.EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue) == EmployeeService.EmployeeType.FullTimeEmployee) { employee = new EmployeeService.FullTimeEmployee { Id = Convert.ToInt32(txtID.Text), Name = txtName.Text, Gender = txtGender.Text, DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text), Type = EmployeeService.EmployeeType.FullTimeEmployee, AnnualSalary = Convert.ToInt32(txtAnnualSalary.Text) }; client.SaveEmployee(employee); lblMessage.Text = "Employee saved"; } else if ((EmployeeService.EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue) == EmployeeService.EmployeeType.PartTimeEmployee) { employee = new EmployeeService.PartTimeEmployee { Id = Convert.ToInt32(txtID.Text), Name = txtName.Text, Gender = txtGender.Text, DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text), Type = EmployeeService.EmployeeType.PartTimeEmployee, Hourlypay = Convert.ToInt32(txtHourlyPay.Text), HoursWorked = Convert.ToInt32(txtHoursWorked.Text) }; client.SaveEmployee(employee); lblMessage.Text = "Employee saved"; } else { lblMessage.Text = "Please select Employee Type"; } }
protected void SaveEmployee() { Response4 = string.Empty; //清空前台显示 using var channel = GrpcChannel.ForAddress(ServerAdderss); var client = new EmployeeService.EmployeeServiceClient(channel); var newEmp = GetNewEmployee(Request4); var response = client.SaveEmployee(new EmployeeRequest { Employee = newEmp }); Response4 += $"New Employee “{response.Employee.Name}” is Saved"; }
protected void Button2_Click(object sender, EventArgs e) { EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient(); EmployeeService.Employee employee = new EmployeeService.Employee(); employee.Id = Convert.ToInt32(TextBox1.Text); employee.Name = TextBox5.Text; employee.Gender = TextBox3.Text; employee.DateOfBirth = Convert.ToDateTime(TextBox4.Text); client.SaveEmployee(employee); Label1.Text = "Employee saved!"; }