コード例 #1
0
        // GET: Employee/Edit/5
        public IActionResult Edit(int?id)
        {
            try
            {
                if (id == null)
                {
                    return(NotFound());
                }

                EmployeeViewModel employeeViewModel = _IEmployee.GetEmployeeViewModel((int)id);
                if (employeeViewModel == null)
                {
                    return(NotFound());
                }

                ViewBag.SubCompanies = UtilityService.CreateSubCompanyListItem(_IEmployee.GetSubCompanies());
                ViewBag.Positions    = UtilityService.CreatePositionListItemn(_IEmployee.GetPositions());

                return(View(employeeViewModel));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Message " + ex.Message);
                ViewBag.subCompany = new SelectList(_IEmployee.GetSubCompaniesQuery());
                ViewBag.position   = new SelectList(_IEmployee.GetPositionsQuery());
                return(View(nameof(Index)));
            }
        }
コード例 #2
0
        public IActionResult Create([Bind("EmployeeName,ProjectName,Salary,SubCompanyId,PositionId,Joined_Date,_Address,_PhoneNumber,Addresses,PhoneNumbers")] EmployeeViewModel employeeViewModel)
        {
            if (ModelState.IsValid)
            {
                if (_IEmployee.CreateEmployee(employeeViewModel))
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ViewBag.Message = "Unable To Create";
                }
            }

            ViewBag.SubCompanies = UtilityService.CreateSubCompanyListItem(_IEmployee.GetSubCompanies());
            ViewBag.Positions    = UtilityService.CreatePositionListItemn(_IEmployee.GetPositions());
            if (employeeViewModel.Addresses == null)
            {
                employeeViewModel.Addresses = new List <string>();
            }

            if (employeeViewModel.PhoneNumbers == null)
            {
                employeeViewModel.PhoneNumbers = new List <string>();
            }
            return(View(employeeViewModel));
        }
コード例 #3
0
        public IActionResult Edit(int id, [Bind("Id,EmployeeName,Salary,SubCompanyId,PositionId,Joined_Date,Addresses,_Address,_PhoneNumber,PhoneNumbers")] EmployeeViewModel employeeViewModel)
        {
            if (id != employeeViewModel.Id)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                if (_IEmployee.Update(employeeViewModel))
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ViewBag.Message = "Unable To Update.";
                }
            }


            ViewBag.SubCompanies = UtilityService.CreateSubCompanyListItem(_IEmployee.GetSubCompanies());
            ViewBag.Positions    = UtilityService.CreatePositionListItemn(_IEmployee.GetPositions());
            return(View(employeeViewModel));
        }
コード例 #4
0
        public IActionResult Create()
        {
            ViewBag.SubCompanies = UtilityService.CreateSubCompanyListItem(_IEmployee.GetSubCompanies());
            ViewBag.Positions    = UtilityService.CreatePositionListItemn(_IEmployee.GetPositions());
            EmployeeViewModel employeeViewModel = new EmployeeViewModel();

            employeeViewModel.Addresses    = new List <string>();
            employeeViewModel.PhoneNumbers = new List <string>();
            return(View(employeeViewModel));
        }