Пример #1
0
 public static int AddEmployee(Employees emp)
 {
     using (VedantaEntities ve = new VedantaEntities())
     {
         Employees oldEmp = ve.Employees.FirstOrDefault(e => emp.EmployeeId.Equals(e.EmployeeId));
         if (oldEmp == null)
         {
             if (emp.BranchId != null)
             {
                 Utilities.BranchRegionZones brz = Utilities.GetRegionAndZoneByBranchId(emp.BranchId.Value);
                 if (brz != null && brz.ZoneId > 0 && brz.RegionId > 0)
                 {
                     emp.RegionId = brz.RegionId;
                     emp.ZoneId   = brz.ZoneId;
                 }
             }
             if (emp.RegionId != null)
             {
                 emp.ZoneId = Utilities.GetRegionZoneId(emp.RegionId.Value);
             }
             emp.IsActive    = true;
             emp.CreatedDate = DateTime.Now.Date;
             ve.AddToEmployees(emp);
             return(ve.SaveChanges());
         }
         else
         {
             return(-1);
         }
     }
 }