public JsonResult Update([DataSourceRequest] DataSourceRequest request, EmployeeDirectoryModel employee)
        {
            if (ModelState.IsValid)
            {
                employeeDirectory.Update(employee, ModelState);
            }

            return Json(new[] { employee }.ToTreeDataSourceResult(request, ModelState));
        }
 public virtual void Update(EmployeeDirectoryModel employee, ModelStateDictionary modelState)
 {
     if (ValidateModel(employee, modelState))
     {
         var entity = employee.ToEntity();
         db.EmployeeDirectories.Attach(entity);
         db.Entry(entity).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
        private bool ValidateModel(EmployeeDirectoryModel employee, ModelStateDictionary modelState)
        {
            if (employee.HireDate < employee.BirthDate)
            {
                modelState.AddModelError("errors", "Employee cannot be hired before birth.");
                return(false);
            }

            return(true);
        }
        public virtual void Delete(EmployeeDirectoryModel employee, ModelStateDictionary modelState)
        {
            var entity = employee.ToEntity();

            db.EmployeeDirectories.Attach(entity);

            Delete(entity);

            db.SaveChanges();
        }
        public virtual void Insert(EmployeeDirectoryModel employee, ModelStateDictionary modelState)
        {
            if (ValidateModel(employee, modelState))
            {
                var entity = employee.ToEntity();

                db.EmployeeDirectories.Add(entity);
                db.SaveChanges();

                employee.EmployeeId = entity.EmployeeID;
            }
        }