Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            using (var context = new EmployeeMgmtContext())
            {
                var model = await context.Department.Include(a => a.Employees).AsNoTracking().ToListAsync();

                return(View(model));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Name, Id")] Employees employee)
        {
            using (var context = new EmployeeMgmtContext())
            {
                context.Employees.Add(employee);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
        }
        public async Task <IActionResult> Create([Bind("Name, Location")] Department department)
        {
            using (var context = new EmployeeMgmtContext())
            {
                context.Add(department);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create()
        {
            using (var context = new EmployeeMgmtContext())
            {
                var department = await context.Department.Select(a => new SelectListItem {
                    Value = a.Id.ToString(),
                    Text  = $"{a.Name} {a.Location}"
                }).ToListAsync();

                ViewBag.Department = department;
            }
            return(View());
        }