Пример #1
0
        // GET: Employees/Delete/5
        public ActionResult Delete(int id)
        {
            EmployeeModel model = null;

            try
            {
                using (EmployeeDirectoryDB db = new EmployeeDirectoryDB(ConnectionString))
                {
                    Employee dbEmp = db.ReadEmployee(id);
                    if (dbEmp == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, string.Format("Student with id = {0}, unknown.", id)));

                        model = new EmployeeModel()
                        {
                            Id         = dbEmp.Id.ToString(),
                            FirstName  = dbEmp.FirstName,
                            LastName   = dbEmp.LastName,
                            EmployeeID = dbEmp.EmployeeID,
                            BirthDate  = dbEmp.BirthDate,
                            Department = dbEmp.Department.ToString(),
                            Gender     = dbEmp.Gender.ToString(),
                            Race       = dbEmp.Race.ToString()
                        };
                    }
                }
            }
            catch (Exception)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Internal Server Error"));
            }
            return(View(model));
        }
Пример #2
0
        // GET: Employees/Edit/5
        public ActionResult Edit(int id)
        {
            EmployeeModel model = null;

            try
            {
                using (EmployeeDirectoryDB db = new EmployeeDirectoryDB(ConnectionString))
                {
                    Employee dbEmp = db.ReadEmployee(id);
                    if (dbEmp == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound, string.Format("Employee with ID {0} unknown", id)));
                    }

                    model = new EmployeeModel()
                    {
                        Id          = dbEmp.Id.ToString(),
                        FirstName   = dbEmp.FirstName,
                        LastName    = dbEmp.LastName,
                        EmployeeID  = dbEmp.EmployeeID,
                        Gender      = dbEmp.Gender.ToString(),
                        Race        = dbEmp.Race,
                        Department  = dbEmp.Department,
                        BirthDate   = dbEmp.BirthDate,
                        RaceOptions = GetRaceOptions()
                    };
                    foreach (SelectListItem item in model.RaceOptions)
                    {
                        if (item.Value == model.Race)
                        {
                            item.Selected = true;
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Internal server error."));
            }
            return(View(model));
        }