private static void DeleteAndReseed(string tableName) { using (var context = new TimesheetsContext()) { context.Database.ExecuteSqlCommand(string.Format("DELETE FROM dbo.[{0}] DBCC CHECKIDENT ('{0}', RESEED, 0)", tableName)); } }
public void GivenTheFollowingDataInTheTimeCodesTable(Table table) { using (var context = new TimesheetsContext()) { foreach (var row in table.Rows) { var timeCode = new TimeCode(); timeCode.Id = int.Parse(row[0]); timeCode.Name = row[1]; timeCode.Description = row[2]; context.TimeCodes.Add(timeCode); } context.SaveChanges(); } }
public void GivenTheFollowingDataInTheDepartmentsTable(Table table) { using (var context = new TimesheetsContext()) { foreach (var department in table.Rows) { var dbDepartment = new Department(); dbDepartment.Id = int.Parse(department[0]); dbDepartment.Code = department[1]; dbDepartment.Name = department[2]; context.Departments.Add(dbDepartment); } context.SaveChanges(); } }
public ActionResult Index() { using (var context = new TimesheetsContext()) { var users = context.Users.ToList().Select(x => new UserModel { Id = x.Id, Firstname = x.Firstname, Surname = x.Surname, Email = x.Email, IsCurrentUser = x.Email == User.Identity.Name }); return(View(users.AsEnumerable())); } }
public List <WeeklyPayslip> RetrievePayslip() { var _payservice = new PayService(); var payslips_all = new List <WeeklyPayslip>(); using (var context = new TimesheetsContext()) { LambdaLogger.Log("Context Retrieval"); var payAgreements = context.PayAgreements; var timesheets = context.Timesheets .Where(x => x.Date >= MinDate(false) && x.Date < MaxDate(false)); foreach (var payAgr in payAgreements) { var empTimesheet = timesheets .Where(x => x.EmployeeId == payAgr.EmployeeId && x.CompanyAbn == payAgr.CompanyAbn).ToList(); var employee = context.AspNetUsers .Include(x => x.Payslips) .SingleOrDefault(x => x.Id == payAgr.EmployeeId); var company = context.Companies .SingleOrDefault(x => x.Abn == payAgr.CompanyAbn); if (empTimesheet.Count > 0) { try { var payslip_print = _payservice.GetEmpoyeeTimesheet(employee, company, empTimesheet, payAgr); payslips_all.Add(payslip_print); var payslip_database = new Payslips() { WeekBegininning = MinDate(false), GrossPay = Convert.ToDouble(payslip_print.Pay), PayYtd = Convert.ToDouble(payslip_print.PayYTD), Tax = Convert.ToDouble(payslip_print.Tax), BaseHours = Convert.ToDouble(payslip_print.BaseHours), SatHours = Convert.ToDouble(payslip_print.SatHours), SunHours = Convert.ToDouble(payslip_print.SunHours), CompanyAbn = Convert.ToInt64(payslip_print.CompanyABN), EmployeeId = payslip_print.EmpId }; context.Payslips.Add(payslip_database); } catch (Exception e) { LambdaLogger.Log(e.Message); } } } LambdaLogger.Log("Save Changes to Context"); context.SaveChanges(); }; return(payslips_all); }