コード例 #1
0
        public ActionResult ShowEmployee(int EmployeeID)
        {
            MVCTutorialEntities      db      = new MVCTutorialEntities();
            List <EmployeeViewModel> listemp = db.Employees.Where(x => x.Isbool == false && x.EmployeeID == EmployeeID).Select(x => new EmployeeViewModel {
                Name = x.Name, Address = x.Address, EmployeeID = x.EmployeeID, DepartmentName = x.Department.DepartmentName
            }).ToList();

            ViewBag.EmployeeList = listemp;
            return(PartialView("Partial1"));
        }
コード例 #2
0
        public ActionResult Index()
        {
            MVCTutorialEntities db   = new MVCTutorialEntities();
            List <Department>   list = db.Departments.ToList();

            ViewBag.DepartmentList = new SelectList(list, "DepartmentID", "DepartmentName");
            List <EmployeeViewModel> listEmp = db.Employees.Where(x => x.Isbool == false).Select(x => new EmployeeViewModel {
                Name = x.Name, Address = x.Address, EmployeeID = x.EmployeeID, DepartmentName = x.Department.DepartmentName
            }).ToList();

            ViewBag.EmpVMList = listEmp;
            return(View());
        }
コード例 #3
0
        public ActionResult RegisterUser(RegistrationViewModel model)
        {
            MVCTutorialEntities db       = new MVCTutorialEntities();
            SiteUser            siteUser = new SiteUser();

            siteUser.UserName = model.UserName;
            siteUser.EmailId  = model.EmailId;
            siteUser.Password = model.Password;
            siteUser.Address  = model.Address;
            siteUser.RoleId   = 3;
            db.SiteUsers.Add(siteUser);
            db.SaveChanges();

            return(View());
        }
コード例 #4
0
        public JsonResult DeleteEmp(int EmployeeID)
        {
            bool result             = false;
            MVCTutorialEntities db  = new MVCTutorialEntities();
            Employee            emp = db.Employees.SingleOrDefault(x => x.Isbool == false && x.EmployeeID == EmployeeID);

            if (emp != null)
            {
                emp.Isbool = true;
                db.SaveChanges();
                result = true;
            }


            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        // GET: Test
        public ActionResult Index()
        {
            MVCTutorialEntities db           = new MVCTutorialEntities();
            List <Employee>     employeelist = db.Employees.ToList();

            EmployeeViewModel employeeVM = new EmployeeViewModel();

            List <EmployeeViewModel> employeeVMlist = employeelist.Select(x => new EmployeeViewModel
            {
                Name           = x.Name,
                Address        = x.Address,
                DepartmentId   = x.DepartmentId,
                EmployeeId     = x.EmployeeId,
                DepartmentName = x.Department.DepartmentName
            }).ToList();

            return(View(employeeVMlist));
        }
コード例 #6
0
        public ActionResult AddEditEmployee(int EmployeeID)
        {
            MVCTutorialEntities db    = new MVCTutorialEntities();
            EmployeeViewModel   model = new EmployeeViewModel();
            List <Department>   list  = db.Departments.ToList();

            ViewBag.DepartmentList = new SelectList(list, "DepartmentID", "DepartmentName");

            if (EmployeeID > 0)
            {
                Employee emp = db.Employees.SingleOrDefault(x => x.EmployeeID == EmployeeID && x.Isbool == false);
                model.EmployeeID   = emp.EmployeeID;
                model.DepartmentID = emp.DepartmentID;
                model.Address      = emp.Address;
                model.Name         = emp.Name;
            }
            return(PartialView("Partial2", model));
        }
コード例 #7
0
        public ActionResult Index(EmployeeViewModel model)
        {
            try
            {
                MVCTutorialEntities db = new MVCTutorialEntities();



                // db.SaveChanges();

                if (model.EmployeeID > 0)
                {
                    //update
                    Employee emp = db.Employees.SingleOrDefault(x => x.EmployeeID == model.EmployeeID && x.Isbool == false);
                    emp.DepartmentID = model.DepartmentID;
                    emp.Name         = model.Name;
                    emp.Address      = model.Address;
                    db.SaveChanges();
                }
                else
                {
                    //insert
                    Employee emp = new Employee();

                    emp.Name         = model.Name;
                    emp.Address      = model.Address;
                    emp.DepartmentID = model.DepartmentID;
                    emp.Isbool       = false;
                    db.Employees.Add(emp);
                    db.SaveChanges();
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //return RedirectToAction("Index");
        }