コード例 #1
0
        public ActionResult Create(Employee employee)
        {
            try
            {
                SqlRepository repository = new SqlRepository(_LocalFileConnectionString);

                string sql = String.Format($@"INSERT INTO Employee(PositionId, DepartmentId, FirstName, LastName, Email, Phone, Extension, HireDate, StartTime, ActiveEmployee, TerminationDate) 
                Values(
                1,
                1,
                '{employee.FirstName}',
                '{employee.LastName}',
                '{employee.EMail}',
                '{employee.Phone}',
                '{employee.Extension}',
                '{employee.HireDate.ToString()}',
                '{employee.StartTime}',
                ");

                if (employee.ActiveEmployee)
                {
                    sql += $"1";
                }
                else
                {
                    sql += $"0";
                }

                if (employee.TerminationDate.HasValue)
                {
                    sql += $", '{employee.TerminationDate.Value.ToString()}'";
                }
                else
                {
                    sql += $", null";
                }

                sql += $")";

                repository.CreateEmployee(sql);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorText = ex.ToString();
                return(View("Error"));
            }
        }
コード例 #2
0
        public ActionResult Create(Employee employee)
        {
            // Hint: This method will be similar to the update method.
            // Hint: for now set the Position and Department to Id 1

            // TODO: Create employee from form submission, redirect to list
            SqlRepository repository = new SqlRepository(_LocalFileConnectionString);



            string sql = String.Format($@"INSERT INTO Employee (PositionId, DepartmentId, FirstName, LastName, Email, Phone, Extension, 
HireDate, StartTime, ActiveEmployee) VALUES(
                    1,
                    1,
                    '{employee.FirstName}',
                    '{employee.LastName}',
                    '{employee.EMail}',
                    '{employee.Phone}',
                    '{employee.Extension}',
                    '{employee.HireDate.ToString()}',
                    '{employee.StartTime}',
            ");

            if (employee.ActiveEmployee)
            {
                sql += "1";
            }
            else
            {
                sql += "0";
            }

            sql += ")";


            repository.CreateEmployee(sql);

            return(RedirectToAction("Index"));
        }