예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,First,Last,Month,Year,EmployeeTypeID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                //
                if (employee.EmployeeTypeID == 2)
                {
                    Manager manager = new Manager
                    {
                        Id             = employee.Id,
                        First          = employee.First,
                        Last           = employee.Last,
                        Month          = employee.Month,
                        Year           = employee.Year,
                        EmployeeTypeID = employee.EmployeeTypeID,
                        EmployeeType   = employee.EmployeeType
                    };
                    _context.Add(manager);
                }
                else
                {
                    _context.Add(employee);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeTypeID"] = new SelectList(_context.EmployeeType, "EmployeeTypeID", "EmployeeDiscription", employee.EmployeeTypeID);
            return(View(employee));
        }
        public async Task <IActionResult> Create([Bind("Name,Surname,Address,Qualification,ContactNumber, DeptId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                using (var _context = new EmployeeManagementContext())
                {
                    _context.Add(employee);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            using (var _context = new EmployeeManagementContext())
            {
                var departments = await _context.Departments.Select(a => new SelectListItem
                {
                    Value = a.DeptId.ToString(),
                    Text  = $"{a.DeptName}"
                }).ToListAsync();

                ViewBag.Departments = departments;
                //ViewData["DeptId"] = new SelectList(_context.Departments, "DeptId", "DeptId", employee.DeptId);
            }
            return(View(employee));
        }
예제 #3
0
        public ActionResult <string> CreateEmployee()
        {
            string   employeeJson = new StreamReader(Request.Body).ReadToEnd();
            Employee employee     = JsonConvert.DeserializeObject <Employee>(employeeJson);

            _context.Add(employee);
            _context.SaveChanges();
            return("success");
        }
예제 #4
0
 public async Task <IActionResult> Create([Bind("DeptName")] Department department)
 {
     using (var context = new EmployeeManagementContext())
     {
         if (ModelState.IsValid)
         {
             context.Add(department);
             await context.SaveChangesAsync();
         }
         return(RedirectToAction("Index"));
     }
 }
예제 #5
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Gender,Birth,Department,Address,Phone,Email")] Employee employee)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(employee);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(employee));
        }