Esempio n. 1
0
        public ActionResult Save(Employee emp)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (MydataEntities dc = new MydataEntities())
                {
                    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 }
            });
        }
Esempio n. 2
0
        public ActionResult DeleteEmployee(int id)
        {
            bool status = false;

            using (MydataEntities dc = new MydataEntities())
            {
                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 }
            });
        }