Example #1
0
        public List <ts.Employee> GetList()
        {
            ts.TimesheetDBContext db = DBContext;
            var lst = db.Employee.OrderBy(x => x.Name).ToList();

            return(lst);
        }
Example #2
0
        public void ImportTimesheetBulk(HttpPostedFileBase fb)
        {
            DataTable dt = GetDataTableFromSpreadsheet(fb.InputStream, false);

            ts.TimesheetDBContext db = DBContext;
            foreach (DataRow dr in dt.Rows)
            {
                int   EmployeeNumber = int.Parse(dr[0].ToString());
                int   Month          = int.Parse(dr[1].ToString());
                float WorkingHours   = float.Parse(dr[2].ToString());
                if (db.Employee.Any(x => x.EmployeeNumber == EmployeeNumber))
                {
                    var sheet = db.Timesheet.Where(x => x.EmployeeNumber == EmployeeNumber && x.Month == Month).FirstOrDefault();
                    if (sheet != null && sheet.EmployeeNumber > 0)
                    {
                        sheet.WorkingHours = WorkingHours;
                    }
                    else
                    {
                        db.Timesheet.Add(new ts.Timesheet()
                        {
                            EmployeeNumber = EmployeeNumber, Month = Month, WorkingHours = WorkingHours
                        });
                    }
                }
            }
            db.SaveChanges();
        }
Example #3
0
 public void AddTempTimesheet()
 {
     ts.TimesheetDBContext db = DBContext;
     if (!db.Timesheet.Any(x => x.EmployeeNumber == 1 && x.Month == 1))
     {
         db.Timesheet.Add(new ts.Timesheet()
         {
             EmployeeNumber = 1, Month = 1, WorkingHours = 7
         });
     }
     if (!db.Timesheet.Any(x => x.EmployeeNumber == 2 && x.Month == 1))
     {
         db.Timesheet.Add(new ts.Timesheet()
         {
             EmployeeNumber = 2, Month = 1, WorkingHours = 8
         });
     }
     if (!db.Timesheet.Any(x => x.EmployeeNumber == 3 && x.Month == 1))
     {
         db.Timesheet.Add(new ts.Timesheet()
         {
             EmployeeNumber = 3, Month = 1, WorkingHours = 9
         });
     }
     db.SaveChanges();
 }
Example #4
0
 public void AddTempEmployees()
 {
     ts.TimesheetDBContext db = DBContext;
     if (!db.Employee.Any(x => x.EmployeeNumber == 1))
     {
         db.Employee.Add(new ts.Employee()
         {
             EmployeeNumber = 1, Name = "Ahmed Mohamed"
         });
     }
     if (!db.Employee.Any(x => x.EmployeeNumber == 2))
     {
         db.Employee.Add(new ts.Employee()
         {
             EmployeeNumber = 2, Name = "Mostafa Salah"
         });
     }
     if (!db.Employee.Any(x => x.EmployeeNumber == 3))
     {
         db.Employee.Add(new ts.Employee()
         {
             EmployeeNumber = 3, Name = "Samy Reda"
         });
     }
     if (!db.Employee.Any(x => x.EmployeeNumber == 4))
     {
         db.Employee.Add(new ts.Employee()
         {
             EmployeeNumber = 4, Name = "Said Fahmy"
         });
     }
     if (!db.Employee.Any(x => x.EmployeeNumber == 5))
     {
         db.Employee.Add(new ts.Employee()
         {
             EmployeeNumber = 5, Name = "Ramy Nagy"
         });
     }
     if (!db.Employee.Any(x => x.EmployeeNumber == 6))
     {
         db.Employee.Add(new ts.Employee()
         {
             EmployeeNumber = 6, Name = "Hady Shawky"
         });
     }
     db.SaveChanges();
 }
Example #5
0
        public List <ts.TimesheetListItem> GetList()
        {
            ts.TimesheetDBContext       db   = DBContext;
            List <ts.TimesheetListItem> data = new List <ts.TimesheetListItem>();
            var lst = from t in db.Timesheet join e in db.Employee on t.EmployeeNumber equals e.EmployeeNumber
                      select new { t.EmployeeNumber, t.Month, t.WorkingHours, e.Name };

            foreach (var item in lst)
            {
                data.Add(new ts.TimesheetListItem()
                {
                    EmployeeNumber = item.EmployeeNumber,
                    Name           = item.Name,
                    Month          = item.Month,
                    WorkingHours   = item.WorkingHours
                });
            }
            return(data);
        }
Example #6
0
 public void AddUpdate(AddTimesheetViewModel vm)
 {
     if (vm != null && vm.EmployeeNumber > 0 && vm.SelectedMonth > 0 && vm.WorkingHours > 0)
     {
         ts.TimesheetDBContext db = DBContext;
         var ts = db.Timesheet.Where(x => x.EmployeeNumber == vm.EmployeeNumber && x.Month == vm.SelectedMonth).FirstOrDefault();
         if (ts != null && ts.EmployeeNumber > 0)
         {
             ts.WorkingHours = vm.WorkingHours;
         }
         else
         {
             db.Timesheet.Add(new Data.Entities.Timesheet()
             {
                 EmployeeNumber = vm.EmployeeNumber, Month = vm.SelectedMonth, WorkingHours = vm.WorkingHours
             });
         }
         db.SaveChanges();
     }
 }