/// <summary> /// creates a user and saves it to the Users table in the database /// </summary> /// <param name="user"></param> public void createUser(User user) { using (var context = new PetoEntities()) { context.Users.AddObject(user); context.SaveChanges(); } }
/// <summary> /// saves Report Instance to the database under the Reports table /// </summary> /// <param name="d"></param> public void createReport(Report r) { using (var context = new PetoEntities()) { context.Reports.AddObject(r); context.SaveChanges(); } }
/// <summary> /// saves Document Instance to the database under the Documents table /// </summary> /// <param name="d"></param> public void createDocument(Document d) { using (var context = new PetoEntities()) { context.Documents.AddObject(d); context.SaveChanges(); } }
/// <summary> /// delete a Report /// </summary> /// <param name="id"></param> public void deleteReport(int ReportId) { using (var context = new PetoEntities()) { Report d = context.Reports.FirstOrDefault(x => x.ReportId == ReportId); if (d != null) { context.Reports.DeleteObject(d); context.SaveChanges(); } } }
/// <summary> /// copy chargeable record into a manager chargeable record /// </summary> /// <param name="j"></param> public void copyToManagerChargeable(ChargeableJob j) { using (var context = new PetoEntities()) { try { ManagerChargeable m = new ManagerChargeable(); m.BillingHours = j.EmpHours; m.PayRollHours = j.EmpHours; m.BillingAccomodation = j.Accomodations; m.PayRollAccomodation = j.Accomodations; m.BillingTravelDistance = j.TravelDistance; m.PayRollTravelDistance = j.TravelDistance; m.TruckDistance = j.TruckDistance; m.TimeSheetId = j.TimeSheetId; m.ProjectId = j.ProjectId.Value; m.Classification = j.Classification; m.Activity = j.Activity; m.Day = j.Day; m.Remarks = j.Remarks; context.ManagerChargeables.AddObject(m); context.SaveChanges(); } catch (Exception) { throw; } } }
/// <summary> /// delete a membership user /// </summary> /// <param name="user"></param> public void deleteUser(string UserName) { try { // delete the user from the API (asp_Users) table Membership.DeleteUser(UserName, true); using (var context = new PetoEntities()) { User user = context.Users.FirstOrDefault(x=> x.username == UserName); // if a user is returned with the specified username delete that record from the Users table if (user != null) { context.Users.DeleteObject(user); context.SaveChanges(); } } } catch (Exception ) { throw; } }
/// <summary> /// create manager chargeable job in db /// </summary> /// <param name="j"></param> public string createManagerChargeable(string bHours, string bAccom, string bDist, string truckDist, string bMisc, string day, string projectNo, string classification, string activity, int timesheetID, string remarks, ref decimal hoursLBL, ref int distLBL, ref int truckLBL, ref decimal expenseLBL) { using (var context = new PetoEntities()) { try { if (timesheetID > 0 && bHours != "0" && bHours != string.Empty || bAccom != "0" && bAccom != string.Empty || bDist != "0" && bDist != string.Empty || bMisc != "0" && bMisc != string.Empty || truckDist != "0" && truckDist != string.Empty) { ManagerChargeable c = new ManagerChargeable(); // Hours if (bHours != "0" && bHours != string.Empty) { c.BillingHours = Convert.ToDecimal(bHours); if (c.BillingHours.HasValue) { hoursLBL += c.BillingHours.Value; } } // Accomodation if (bAccom != "0" && bAccom != string.Empty) { c.BillingAccomodation = Convert.ToDecimal(bAccom); expenseLBL += Convert.ToDecimal(c.BillingAccomodation); } // Distance if (bDist != "0" && bDist != string.Empty) { c.BillingTravelDistance = Convert.ToInt32(bDist); distLBL += Convert.ToInt32(bDist); } // truck distance if (truckDist != "0" && truckDist != string.Empty) { c.TruckDistance = Convert.ToInt32(truckDist); truckLBL += Convert.ToInt32(truckDist); } // Misc if (bMisc != "0" && bMisc != string.Empty) { c.BillingMisc = Convert.ToDecimal(bMisc); expenseLBL += Convert.ToDecimal(c.BillingMisc); } if (remarks != string.Empty) { c.Remarks = remarks; } if (c.BillingHours > 0 || c.BillingTravelDistance > 0 || c.BillingAccomodation > 0 || c.BillingMisc > 0 || c.TruckDistance > 0) { c.Day = day; c.ProjectId = idForProjectNo(projectNo); if (classification != "Select") { c.Classification = classification; } c.Activity = activity; c.TimeSheetId = Convert.ToInt32(timesheetID); context.ManagerChargeables.AddObject(c); context.SaveChanges(); return "Data was successfully saved"; } else { return "Data was not Entered in input fields."; } } else { return "Input values are empty"; } } catch (Exception) { throw; } } }
/// <summary> /// update an existing timesheet /// </summary> /// <param name="id"></param> /// <param name="weekending"></param> /// <param name="status"></param> /// <param name="empComment"></param> /// <param name="mComment"></param> /// <param name="hours"></param> /// <param name="distance"></param> /// <param name="expenses"></param> public void updateTimeSheet(int id, decimal hours, int distance, int truckDist, decimal expenses, string status, string empComment, string mComment) { using (var context = new PetoEntities()) { try { TimeSheet t = context.TimeSheets.FirstOrDefault(x => x.TimeSheetId == id); // determine who is trying to update the timesheet string name = Membership.GetUser().UserName; User user = context.Users.FirstOrDefault(x => x.username == name); // ensure timesheet exists and has not already been approved or completed if (t != null) { if (status != string.Empty) { t.Status = status; } if (empComment != string.Empty) { t.EmployeeComments = empComment; } if (mComment != string.Empty) { t.ManagerComments = mComment; } t.ModifiedBy = user.username; t.DateModified = DateTime.Now; if (expenses > 0) { t.TotalExpenses = expenses; } else if (expenses == 0) { t.TotalExpenses = 0; } if (distance > 0) { t.TotalDistance = distance; } else if (distance == 0) { t.TotalDistance = 0; } // truck distance if (truckDist > 0) { t.TotalTruck = truckDist; } else if (distance == 0) { t.TotalTruck = 0; } if (hours > 0) { t.TotalHours = hours; } else if (hours == 0) { t.TotalHours = 0; } // if timesheet is rejected copy manager comments into employee comments if (t.Status == "Rejected") { t.EmployeeComments = t.EmployeeComments + "\n MANAGER COMMENT: \n " + mComment; } // only a manager can update an already approved timesheet if (Roles.GetRolesForUser().Contains("Manager") && t.Status == "Approved") { t.ApprovedBy = user.username; t.DateApproved = DateTime.Now; t.ManagerComments = mComment; context.SaveChanges(); } else if (t.Status != "Approved") { context.SaveChanges(); } } } catch (Exception) { throw; } } }
/// <summary> /// update a non-chargeable record /// </summary> /// <param name="hours"></param> /// <param name="accom"></param> /// <param name="distance"></param> /// <param name="misc"></param> /// <param name="day"></param> /// <param name="density"></param> /// <param name="expense"></param> /// <param name="hourType"></param> /// <param name="timesheetID"></param> /// <returns></returns> public bool updateNonChargeable(string hours, string accom, string distance, string misc, string day, string expense, string hourType, int timesheetID, string remarks, ref decimal totalHours, ref int totalDist, ref decimal totalExpense) { using (var context = new PetoEntities()) { try { NonChargeable nCh = context.NonChargeables.FirstOrDefault(x => x.Day == day && x.TimeSheetId == timesheetID && (x.TypeExpense == expense || x.TypeHours == hourType)); if (nCh != null) { if (hours != string.Empty) { totalHours -= nCh.Hours; nCh.Hours = Convert.ToDecimal(hours); totalHours += nCh.Hours; } if (misc != string.Empty) { if (nCh.Misc.HasValue) { totalExpense -= nCh.Misc.Value; } nCh.Misc = Convert.ToDecimal(misc.Trim()); totalExpense += nCh.Misc.Value; } if (remarks != string.Empty) { nCh.Remarks = remarks; } if (expense != "Select") { nCh.TypeExpense = expense; } if (hourType != "Select") { nCh.TypeHours = hourType; } if (distance != string.Empty) { if (nCh.Distance.HasValue) { totalDist -= nCh.Distance.Value; } // assign distance nCh.Distance = Convert.ToInt32(distance.Trim()); } if (accom != string.Empty) { if (nCh.Accomodation.HasValue) { totalExpense -= nCh.Accomodation.Value; } nCh.Accomodation = Convert.ToDecimal(accom.Trim()); totalExpense += nCh.Accomodation.Value; } // one drop down list value cannot be Select if (expense != "Select" || hourType != "Select") { context.SaveChanges(); } return true; } else { return false; } } catch (Exception) { throw; } } }
/// <summary> /// delete a Summary record of Employee entered chargeable and nonchargeable jobs /// </summary> /// <param name="NonChargeableId"></param> /// <param name="ChargeableId"></param> /// <param name="id"></param> public void deleteSummary(int NonChargeableId, int ChargeableId, int id, int labID, bool manager) { using (var context = new PetoEntities()) { TimeSheet t = context.TimeSheets.FirstOrDefault(x => x.TimeSheetId == id); // Lab test deletion if (labID > 0) { if (manager) { // subtract hours from total hours in timesheet ManagerTest m = context.ManagerTests.FirstOrDefault(x => x.TestId == labID); if (m != null) { if (m.LabTest.HasValue) { t.TotalHours -= m.LabTest.Value; } context.ManagerTests.DeleteObject(m); context.SaveChanges(); } } else { EmpTest e = context.EmpTests.FirstOrDefault(x => x.TestId == labID); if (e != null) { // subtract hours from total hours in timesheet if (e.LabTest.HasValue) { t.TotalHours -= e.LabTest.Value; } context.EmpTests.DeleteObject(e); context.SaveChanges(); } } } if (NonChargeableId > 0) { if (!manager) { NonChargeable m = context.NonChargeables.FirstOrDefault(x => x.NonChargeId == NonChargeableId); if (m != null) { // subtract the values from the times heet before deleting if (t != null) { if (m.Hours > 0) { t.TotalHours -= m.Hours; } if (m.Distance > 0) { t.TotalDistance -= m.Distance; } if (m.Accomodation > 0) { t.TotalExpenses -= m.Accomodation; } if (m.Misc > 0) { t.TotalExpenses -= m.Misc; } } // save changes to db context.NonChargeables.DeleteObject(m); context.SaveChanges(); } } else { ManagerNonChargeable m = context.ManagerNonChargeables.FirstOrDefault(x => x.ManagerNonChargeableId == NonChargeableId); if (m != null) { // subtract the values from the timesheet before deleting if (t != null) { if (m.Hours > 0) { t.TotalHours -= m.Hours; } if (m.Distance > 0) { t.TotalDistance -= m.Distance; } if (m.TruckDistance > 0) { t.TotalTruck -= m.TruckDistance; } if (m.Accomodations > 0 || m.Misc > 0) { t.TotalExpenses -= m.Accomodations - m.Misc; } } // save changes to db context.ManagerNonChargeables.DeleteObject(m); context.SaveChanges(); } } } if (ChargeableId > 0) { if (!manager) { ChargeableJob c = context.ChargeableJobs.FirstOrDefault(x => x.ChargeableId == ChargeableId); if (c != null) { if (t != null) { // hours if (c.EmpHours > 0) { t.TotalHours -= c.EmpHours; } // distance if (c.TravelDistance > 0) { t.TotalDistance -= c.TravelDistance; } // truck distance if (c.TruckDistance > 0) { t.TotalTruck -= c.TruckDistance; } // Expenses if (c.Accomodations > 0) { t.TotalExpenses -= c.Accomodations; } if (c.Misc > 0) { t.TotalExpenses -= c.Misc; } } // save changes to db context.ChargeableJobs.DeleteObject(c); context.SaveChanges(); } } else { ManagerChargeable c = context.ManagerChargeables.FirstOrDefault(x => x.ManagerChargeableId == ChargeableId); if (c != null) { if (t != null) { // hours if (c.BillingHours > 0) { t.TotalHours -= c.BillingHours; } // distance if (c.BillingTravelDistance > 0) { t.TotalDistance -= c.BillingTravelDistance; } // truck distance if (c.TruckDistance > 0) { t.TotalTruck -= c.TruckDistance; } // Expenses if (c.BillingAccomodation > 0 || c.BillingMisc > 0) { t.TotalExpenses -= c.BillingAccomodation - c.BillingMisc; } } // save changes to db context.ManagerChargeables.DeleteObject(c); context.SaveChanges(); } } } } }
/// <summary> /// delete lab test /// </summary> /// <param name="timesheet"></param> /// <param name="day"></param> /// <param name="manager"></param> public void deleteLabTest(int id, int time, bool manager) { using (var context = new PetoEntities()) { TimeSheet ts = context.TimeSheets.FirstOrDefault(t => t.TimeSheetId == time); if (manager) { // subtract hours from total hours in timesheet ManagerTest t = context.ManagerTests.FirstOrDefault(x => x.TestId == id); if (t != null) { if (t.LabTest > 0) { ts.TotalHours -= t.LabTest; } context.ManagerTests.DeleteObject(t); context.SaveChanges(); } } else { EmpTest t = context.EmpTests.FirstOrDefault(x => x.TestId == id); if (t != null) { // subtract hours from total hours in timesheet if (t.LabTest > 0) { ts.TotalHours -= t.LabTest; } context.EmpTests.DeleteObject(t); context.SaveChanges(); } } } }
/// <summary> /// create timesheet instance singleton for weekending. returns timesheetID /// </summary> /// <param name="t"></param> public int createTimesheet(TimeSheet t) { using (var context = new PetoEntities()) { try { if (context.TimeSheets.FirstOrDefault(x => x.TimeSheetId == t.TimeSheetId) == null) { context.TimeSheets.AddObject(t); context.SaveChanges(); return t.TimeSheetId; } else { return context.TimeSheets.FirstOrDefault(x => x.TimeSheetId == t.TimeSheetId).TimeSheetId; } } catch (Exception) { throw; } } }
/// <summary> /// copy EmpTests to ManagerTests /// </summary> /// <param name="emps"></param> public void copyToManagerTest(EmpTest item) { using (var context = new PetoEntities()) { try { ManagerTest m = new ManagerTest(); m.TimeSheetId = item.TimeSheetId; if (item.LabTest.HasValue) { m.LabTest = item.LabTest; } if (item.DensityTest.HasValue) { m.DensityTest = item.DensityTest; } m.Day = item.Day; context.ManagerTests.AddObject(m); context.SaveChanges(); } catch (Exception) { throw; } } }
/// <summary> /// delete a document /// </summary> /// <param name="id"></param> public void deleteDocument(int DocumentId) { using (var context = new PetoEntities()) { Document d = context.Documents.FirstOrDefault(x => x.DocumentId == DocumentId); if (d != null) { context.Documents.DeleteObject(d); context.SaveChanges(); } } }
/// <summary> /// create a NonChargeable Record /// </summary> /// <param name="n"></param> public string createNonChargeable(string hours, string accom, string distance, string misc, string day, string expense, string hourType, int timesheetID, string remarks, ref decimal hoursLBL, ref int distLBL, ref decimal expenseLBL) { using (var context = new PetoEntities()) { try { // to ensure only not null values are saved if (timesheetID > 0 && (hours != "0" && hours != string.Empty) || (accom != "0" && accom != string.Empty) || (distance != "0" && distance != string.Empty) || (misc != "0" && misc != string.Empty)) { NonChargeable nonCh = new NonChargeable(); if (hours != "0" && hours != string.Empty) { nonCh.Hours = Convert.ToDecimal(hours); // assign type of hour if (hourType != "Select") { nonCh.TypeHours = hourType; } hoursLBL += nonCh.Hours; } if (accom != "0" && accom != string.Empty) { nonCh.Accomodation = Convert.ToDecimal(accom); expenseLBL += Convert.ToDecimal(accom); } if (distance != "0" && distance != string.Empty) { nonCh.Distance = Convert.ToInt32(distance); distLBL += Convert.ToInt32(distance); } if (remarks != string.Empty) { nonCh.Remarks = remarks; } if (misc != "0" && misc != string.Empty) { nonCh.Misc = Convert.ToDecimal(misc); expenseLBL += Convert.ToDecimal(misc); } // assign expenses if ((misc != "0" && misc != string.Empty) || (distance != "0" && distance != string.Empty) || (accom != "0" && accom != string.Empty)) { if (expense != "Select") { nonCh.TypeExpense = expense; } } if (misc != "0" && misc != string.Empty || distance != "0" && distance != string.Empty || accom != "0" && accom != string.Empty || hours != "0" && hours != string.Empty) { nonCh.TimeSheetId = timesheetID; } nonCh.Day = day; // one of these must be selected in order to save if (expense != "Select" || hours != "Select") { context.NonChargeables.AddObject(nonCh); context.SaveChanges(); } } return "Data Saved Successfully"; } catch (Exception ex) { return "Data was not saved due to: " + ex.Message; } } }
/// <summary> /// create chargeable job in db /// </summary> /// <param name="j"></param> public string createChargeable(string hours, string accom, string distance, string truckDist, string misc, string day, string projectNo, string classification, string activity, int timesheetID, string remarks, ref decimal hoursLBL, ref int distLBL, ref int truckLBL, ref decimal expenseLBL) { using (var context = new PetoEntities()) { try { if (timesheetID > 0 && hours != "0" && hours != string.Empty || accom != "0" && accom != string.Empty || distance != "0" && distance != string.Empty || misc != "0" && misc != string.Empty || truckDist != "0" && truckDist != string.Empty) { ChargeableJob c = new ChargeableJob(); if (hours != "0" && hours != string.Empty) { c.EmpHours = Convert.ToDecimal(hours); hoursLBL += c.EmpHours; } if (accom != "0" && accom != string.Empty) { c.Accomodations = Convert.ToDecimal(accom); expenseLBL += Convert.ToDecimal(c.Accomodations); } if (distance != "0" && distance != string.Empty) { c.TravelDistance = Convert.ToInt32(distance); distLBL += Convert.ToInt32(distance); } if (truckDist != "0" && truckDist != string.Empty) { c.TruckDistance = Convert.ToInt32(truckDist); truckLBL += Convert.ToInt32(truckDist); } if (misc != "0" && misc != string.Empty) { c.Misc = Convert.ToDecimal(misc); expenseLBL += Convert.ToDecimal(misc); } if (remarks != string.Empty) { c.Remarks = remarks; } if (c.EmpHours > 0 || c.TravelDistance > 0 || c.Accomodations > 0 || c.Misc > 0 || c.TruckDistance > 0) { c.Day = day; c.ProjectId = idForProjectNo(projectNo); if (classification != "Select") { c.Classification = classification; } c.Activity = activity; c.TimeSheetId = Convert.ToInt32(timesheetID); context.ChargeableJobs.AddObject(c); context.SaveChanges(); return "Data was successfully saved"; } else { return "Data was not Entered in input fields."; } } else { return ""; } } catch (Exception) { throw; } } }
/// <summary> /// create a lab test /// </summary> /// <param name="day"></param> /// <param name="test"></param> /// <param name="timesheet"></param> /// <param name="manager"></param> public void createLabTest(string day, string density, string lab, int timesheet, bool manager, ref decimal totalLab) { using (var context = new PetoEntities()) { try { if (manager) { ManagerTest t = new ManagerTest(); t.Day = day; if (density != string.Empty) { t.DensityTest = Convert.ToInt32(density); } if (lab != string.Empty) { t.LabTest = Convert.ToDecimal(lab); totalLab += t.LabTest.Value; } t.TimeSheetId = timesheet; if (lab != string.Empty || density != string.Empty) { context.ManagerTests.AddObject(t); context.SaveChanges(); } } else { EmpTest t = new EmpTest(); t.Day = day; if (density != string.Empty) { t.DensityTest = Convert.ToInt32(density); } if (lab != string.Empty) { t.LabTest = Convert.ToDecimal(lab); totalLab += t.LabTest.Value; } t.TimeSheetId = timesheet; if (lab != string.Empty || density != string.Empty) { context.EmpTests.AddObject(t); context.SaveChanges(); } } } catch (Exception) { throw; } } }
/// <summary> /// delete a chargeable in the timesheet /// </summary> /// <param name="timesheetID"></param> public void deleteChargeableForID(int ChargeableId) { using (var context = new PetoEntities()) { ChargeableJob c = context.ChargeableJobs.FirstOrDefault(x => x.ChargeableId == ChargeableId); if (c != null) { // subtract the values from the timesheet TimeSheet t = context.TimeSheets.FirstOrDefault(x => x.TimeSheetId == c.TimeSheetId); if (t != null) { if (c.EmpHours > 0) { t.TotalHours -= c.EmpHours; } if (c.TravelDistance > 0) { t.TotalDistance -= c.TravelDistance; } if (c.TruckDistance > 0) { t.TotalTruck -= c.TruckDistance; } if (c.Accomodations > 0 || c.Misc > 0) { t.TotalExpenses -= c.Accomodations - c.Misc; } } context.ChargeableJobs.DeleteObject(c); context.SaveChanges(); } } }
/// <summary> /// update lab test /// </summary> /// <param name="day"></param> /// <param name="tests"></param> /// <param name="timesheet"></param> /// <param name="manager"></param> public bool updateLabTest(string day, string density, string lab, int timesheet, bool manager, ref decimal totalLab) { using (var context = new PetoEntities()) { try { if (manager) { ManagerTest t = context.ManagerTests.FirstOrDefault(x => x.TimeSheetId == timesheet && x.Day == day); t.Day = day; if (density != string.Empty) { t.DensityTest = Convert.ToInt32(density); } if (lab != string.Empty) { totalLab -= Convert.ToInt32(lab); t.LabTest = Convert.ToInt32(lab); totalLab += t.LabTest.Value; } context.SaveChanges(); return true; } else { EmpTest t = context.EmpTests.FirstOrDefault(x => x.TimeSheetId == timesheet && x.Day == day); if (density != string.Empty) { t.DensityTest = Convert.ToInt32(density); } if (lab != string.Empty) { totalLab -= Convert.ToInt32(lab); t.LabTest = Convert.ToInt32(lab); totalLab += t.LabTest.Value; } context.SaveChanges(); return true; } } catch (Exception) { return false; } } }
/// <summary> /// delete a nonchargeable job in the timesheet /// </summary> /// <param name="timesheetID"></param> public void deleteNonChargeableForID(int NonChargeId) { using (var context = new PetoEntities()) { NonChargeable n = context.NonChargeables.FirstOrDefault(x => x.NonChargeId == NonChargeId); if (n != null) { // subtract the values from the timesheet before deleting TimeSheet t = context.TimeSheets.FirstOrDefault(x => x.TimeSheetId == n.TimeSheetId); if (t != null) { if (n.Hours > 0) { t.TotalHours -= n.Hours; } if (n.Distance > 0) { t.TotalDistance -= n.Distance; } if (n.Accomodation > 0 || n.Misc > 0) { t.TotalExpenses -= n.Accomodation - n.Misc; } } context.NonChargeables.DeleteObject(n); context.SaveChanges(); } } }
/// <summary> /// update manager chargeable expense record /// </summary> /// <param name="hours"></param> /// <param name="accom"></param> /// <param name="distance"></param> /// <param name="misc"></param> /// <param name="day"></param> /// <param name="projectNo"></param> /// <param name="classification"></param> /// <param name="activity"></param> /// <param name="timesheetID"></param> /// <returns></returns> public bool updateManagerChargeable(string bHours, string bAccom, string bDist, string truckDist, string bMisc, string day, int projectNo, string classification, string activity, int timesheetID, string remarks, ref decimal totalHours, ref int totalDist, ref int totalTruck, ref decimal totalExpense) { using (var context = new PetoEntities()) { try { TimesheetManager tm = new TimesheetManager(); ManagerChargeable cJob = context.ManagerChargeables.FirstOrDefault(x => x.ProjectId == projectNo && x.TimeSheetId == timesheetID && x.Day == day && x.Classification == classification && x.Activity == activity); // update fields if (cJob != null) { // Hours if (bHours != string.Empty) { if (cJob.BillingHours.HasValue) { totalHours -= cJob.BillingHours.Value; } cJob.BillingHours = Convert.ToDecimal(bHours.Trim()); // totalize hours totalHours += cJob.BillingHours.Value; } // Misc if (bMisc != string.Empty) { if (cJob.BillingMisc.HasValue) { totalExpense -= cJob.BillingMisc.Value; } cJob.BillingMisc = Convert.ToDecimal(bMisc.Trim()); totalExpense += cJob.BillingMisc.Value; } if (projectNo > 0) { cJob.ProjectId = projectNo; } if (remarks != string.Empty) { cJob.Remarks = remarks; } if (classification != "Select") { cJob.Classification = classification; } if (activity != "Select") { cJob.Activity = activity; } // Distance if (bDist != string.Empty) { if (cJob.BillingTravelDistance.HasValue) { totalDist -= cJob.BillingTravelDistance.Value; } // assign inputted value cJob.BillingTravelDistance = Convert.ToInt32(bDist.Trim()); // totalize distance totalDist += cJob.BillingTravelDistance.Value; } // truck distance if (truckDist != string.Empty) { // subtract the value if it already exists if (cJob.TruckDistance.HasValue) { totalTruck -= cJob.TruckDistance.Value; } cJob.TruckDistance = Convert.ToInt32(truckDist); totalTruck += cJob.TruckDistance.Value; } // Accom if (bAccom != string.Empty) { if (cJob.BillingAccomodation.HasValue) { totalExpense -= cJob.BillingAccomodation.Value; } cJob.BillingAccomodation = Convert.ToDecimal(bAccom.Trim()); // totalize expense totalExpense += cJob.BillingAccomodation.Value; } context.SaveChanges(); return true; } else { return false; } } catch (Exception) { return false; } } }
/// <summary> /// copy nonchargeable record to manager nonchargeable record /// </summary> /// <param name="n"></param> public void copyToManagerNonChargeable(NonChargeable n) { using (var context = new PetoEntities()) { try { ManagerNonChargeable mNCh = new ManagerNonChargeable(); mNCh.Hours = n.Hours; mNCh.Accomodations = n.Accomodation; mNCh.Misc = n.Misc; mNCh.Distance = n.Distance; mNCh.Remarks = n.Remarks; mNCh.TimeSheetId = n.TimeSheetId; mNCh.TypeHours = n.TypeHours; mNCh.TypeExpense = n.TypeExpense; mNCh.Day = n.Day; context.ManagerNonChargeables.AddObject(mNCh); context.SaveChanges(); } catch (Exception) { throw; } } }
/// <summary> /// update a employee user /// </summary> /// <param name="username"></param> /// <param name="fName"></param> /// <param name="mName"></param> /// <param name="lName"></param> /// <param name="branch"></param> /// <param name="manager"></param> public void updateEmployee(string username, string status, string branch, string manager) { using (var context = new PetoEntities()) { User u = context.Users.FirstOrDefault(x => x.username == username); if (u != null) { if (branch != string.Empty) { u.branch = branch; } if (manager != string.Empty) { u.ManagedBy = manager; } if (u.Status != string.Empty) { u.Status = status; } context.SaveChanges(); } } }