public ActionResult CreateRegulationTime(RegulationTimeEntity entity)
 {
     ViewData["Position"]   = _IplPosition.ListAll();
     ViewData["Department"] = _IplDepartment.ListAllByTreeView();
     try
     {
         ViewBag.Err = TempData["Err"].ToString();
     }
     catch (Exception)
     {
     }
     return(View(entity));
 }
 public ActionResult Save(FormCollection colection)
 {
     ViewData["Position"]   = _IplPosition.ListAll();
     ViewData["Department"] = _IplDepartment.ListAllByTreeView();
     if (!string.IsNullOrEmpty(colection["Id"]) && int.Parse(colection["Id"]) == 0)
     {
         var entity = new RegulationTimeEntity();
         try
         {
             entity.IdDepartment = int.Parse(colection["DepartmentId"]);
             entity.IdPosition   = int.Parse(colection["PositionId"]);
             entity.AllowedLate  = int.Parse(colection["AllowedLate"]);
             entity.AllowedEarly = int.Parse(colection["AllowedEarly"]);
             entity.TimesLate    = int.Parse(colection["TimesLate"]);
             if (entity.IdDepartment < 0 || entity.IdPosition < 0 || entity.AllowedLate < 0 || entity.AllowedEarly < 0 || entity.TimesLate < 0)
             {
                 TempData["Err"] = "Chỉ được nhập số lớn hơn hoặc bằng 0";
                 return(RedirectToAction("CreateRegulationTime"));
             }
             var listAll = _IplRegulationTime.ListAll();
             if (listAll != null && listAll.Count() > 0)
             {
                 foreach (var item in listAll)
                 {
                     if (item.IdDepartment == entity.IdDepartment && item.IdPosition == entity.IdPosition)
                     {
                         TempData["Err"] = "Đã quy định ra vào công ty cho chức vụ " + _IplPosition.ViewDetail(item.IdPosition).Name + " phòng " + _IplDepartment.ViewDetail(item.IdDepartment).Name;
                         return(RedirectToAction("CreateRegulationTime"));
                     }
                 }
             }
         }
         catch (Exception)
         {
             TempData["Err"] = "Chỉ được nhập số";
             return(RedirectToAction("CreateRegulationTime"));
         }
         if (_IplRegulationTime.Insert(entity))
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             return(RedirectToAction("CreateRegulationTime"));
         }
     }
     else
     {
         return(RedirectToAction("CreateRegulationTime"));
     }
 }