Esempio n. 1
0
        public IActionResult Create(CreateModel Emp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (Emp == null || Emp.Employee == null || string.IsNullOrEmpty(Emp.Employee.LastName))
            {
                return(NotFound());
            }
            int checkExist = (from e in companyDB.Employees
                              where e.LastName == Emp.Employee.LastName && e.FirstName == Emp.Employee.FirstName
                              select e).Count();

            if (0 < checkExist)
            {
                return(BadRequest());
            }
            if (Emp.DepartmentName != null)
            {
                Emp.Employee.DepartmentId = companyDB.GetDepartmentIdByName(Emp.DepartmentName);
            }
            companyDB.Employees.Add(Emp.Employee);
            companyDB.SaveChanges();
            return(RedirectToAction("Index"));
        }