示例#1
0
 public ActionResult EditEmployee(Employee employee)
 {
     var contain = (dsc.Employees.Any(d => d.Mail == employee.Mail && d.Id != employee.Id));
     if (contain)
         ModelState.AddModelError("Mail", "Such e-mail is already registered");
     var j = (new DateTime(1950, 1, 1) <= employee.Birthday && new DateTime(2000, 12, 12) >= employee.Birthday);
     if (!j)
         ModelState.AddModelError("Birthday", "Date of birth must be between the dates of 01.01.1950 and 12.12.2000");
     if (!ModelState.IsValid)
         return View(employee);
     dsc.Entry(employee).State = EntityState.Modified;
     dsc.SaveChanges();
     return View("Complete", employee);
 }
示例#2
0
        public ActionResult AddEmployee(Employee employee, int idDepart)
        {
            var contain = (dsc.Employees.Any(d => d.Mail == employee.Mail));
            if (contain)
                ModelState.AddModelError("Mail", "Such e-mail is already registered");
            var j = (new DateTime(1950, 1, 1) <= employee.Birthday && new DateTime(2000, 12, 12) >= employee.Birthday);
            if (!j)
                ModelState.AddModelError("Birthday", "Date of birth must be between the dates of 01.01.1950 and 12.12.2000");
            if (!ModelState.IsValid)
            {
                var depart = dsc.Departments.Find(idDepart);
                ViewBag.IdDepart = depart.Id;
                ViewBag.nameDepart = depart.Name;
                return View(employee);
            }

            employee.Department = dsc.Departments.Find(idDepart);
            dsc.Employees.Add(employee);
            dsc.SaveChanges();
            return View("Complete", employee);
        }