Пример #1
0
        public ActionResult Save(Employee emp)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (MidasEMSEmployeeDataEntities dc = new MidasEMSEmployeeDataEntities())
                {
                    if (emp.EmployeeID > 0)
                    {
                        // Edit
                        var v = dc.Employees.Where(a => a.EmployeeID == emp.EmployeeID).FirstOrDefault();
                        if (v != null)
                        {
                            v.FirstName = emp.FirstName;
                            v.LastName  = emp.LastName;
                            v.EmailID   = emp.EmailID;
                            v.City      = emp.City;
                            v.Country   = emp.Country;
                        }
                    }
                    else
                    {
                        //Save
                        dc.Employees.Add(emp);
                    }
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Пример #2
0
        public ActionResult ConfirmDelete(int id)
        {
            bool status = false;

            using (MidasEMSEmployeeDataEntities dc = new MidasEMSEmployeeDataEntities())
            {
                var v = dc.Employees.Where(a => a.EmployeeID == id).FirstOrDefault();
                if (v != null)
                {
                    dc.Employees.Remove(v);
                    dc.SaveChanges();
                    status = true;
                }
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }