Exemplo n.º 1
0
        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"));
        }
 public ActionResult Delete(int EmployeeId)
 {
     if (client.DeleteEmployee(EmployeeId) > 0)
     {
         ViewBag.Result = "Employee data Deleted Successfully";
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Exemplo n.º 3
0
 public ActionResult Delete(int id)
 {
     try
     {
         EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
         client.DeleteEmployee(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }