public JsonResult SaveRecord(Timesheet t) { var status = false; using (TimesheetEntities dc = new TimesheetEntities()) { if (t.TimesheetID > 0) { var v = dc.Timesheets.Where(a => a.TimesheetID == t.TimesheetID).FirstOrDefault(); if (v != null) { v.ChangeDate = t.ChangeDate; v.User = t.User; v.Start = t.Start; v.End = t.End; v.Description = t.Description; } } else { dc.Timesheets.Add(t); } dc.SaveChanges(); status = true; } return(new JsonResult { Data = new { status = status } }); }
public ActionResult GetTimesheetCounts(string onlyComplete) { ReportChartDataViewModel model = new ViewModels.ReportChartDataViewModel(); TimesheetEntities entities = new TimesheetEntities(); try { model.Labels = (from wa in entities.WorkAssignments orderby wa.Id_WorkAssignment select wa.Title).ToArray(); if (onlyComplete == "1") { model.Counts = (from ts in entities.Timesheets where (ts.WorkComplete == true) orderby ts.Id_WorkAssignment group ts by ts.Id_WorkAssignment into grp select grp.Count()).ToArray(); } else { model.Counts = (from ts in entities.Timesheets orderby ts.Id_WorkAssignment group ts by ts.Id_WorkAssignment into grp select grp.Count()).ToArray(); } } finally { entities.Dispose(); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Complaint() { try { if (_UtilitySession.Session != null) { TimesheetEntities _TimesheetEntities = new TimesheetEntities(); ViewBag.Name = _UtilitySession.Session.user.name; string User_id = _UtilitySession.Session.user.id; LabourComplaintDetailDTO _LabourComplaintDetailDTO = new LabourComplaintDetailDTO(); _LabourComplaintDetailDTO.user = _UtilitySession.Session.user; _LabourComplaintDetailDTO._TimesheetComGridPostDTO = await Task.Run(() => _Repository.getComplaintTimesheetData(User_id)); _LabourComplaintDetailDTO.PageSize = 5; _LabourComplaintDetailDTO.TotalCount = _LabourComplaintDetailDTO._TimesheetComGridPostDTO.Count; return(View(_LabourComplaintDetailDTO)); } else { return(RedirectToAction("Index", "Home")); } } catch (Exception e) { ViewBag.Error = e.ToString(); return(View()); } }
public async Task<ActionResult> AttendanceDashboard() { try { if (_UtilitySession.Session != null) { TimesheetEntities _TimesheetEntities = new TimesheetEntities(); ViewBag.Name = _UtilitySession.Session.user.name; string User_id = _UtilitySession.Session.user.id; LabourDetailDTO _LabourDetailDTO = new LabourDetailDTO(); _LabourDetailDTO._TimesheetGridDTO = await Task.Run(() => _Repository.getTimesheetAllData()); _LabourDetailDTO.PageSize = 5; _LabourDetailDTO.TotalCount = _LabourDetailDTO._TimesheetGridDTO.Count; return View(_LabourDetailDTO); } else { return RedirectToAction("Index", "Home"); } } catch (Exception e) { ViewBag.Error = e.ToString(); return View(); } }
public ActionResult HoursPerWorkAssignmentAsExcel2() { StringBuilder csv = new StringBuilder(); // luodaan CSV-muotoinen tiedosto TimesheetEntities entities = new TimesheetEntities(); try { DateTime today = DateTime.Today; DateTime tomorrow = today.AddDays(1); // haetaan kaikki kuluvan päivän tuntikirjaukset List <Timesheets> allTimesheetsToday = (from ts in entities.Timesheets where (ts.StartTime > today) && (ts.StartTime < tomorrow) && (ts.WorkComplete == true) select ts).ToList(); foreach (Timesheets timesheet in allTimesheetsToday) { csv.AppendLine(timesheet.Id_Employee + ";" + timesheet.StartTime + ";" + timesheet.StopTime + ";"); } } finally { entities.Dispose(); } // palautetaan CSV-tiedot selaimelle byte[] buffer = Encoding.UTF8.GetBytes(csv.ToString()); return(File(buffer, "text/csv", "Työtunnit.csv")); }
public ActionResult Test(TimesheetEntry entry) { TimesheetEntities ent = new TimesheetEntities(); entry = ent.TimesheetEntries.First(); return View(entry); }
public JsonResult GetAllRecords() { using (TimesheetEntities dc = new TimesheetEntities()) { //return timesheets only for authenticated user var events = dc.Timesheets.Where(p => p.User == User.Identity.Name).ToList(); return(new JsonResult { Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
// GET: Reports public ActionResult HoursPerWorkAssignment() { //tähän luotu luokka TimesheetEntities entities = new TimesheetEntities(); try { DateTime today = DateTime.Today; DateTime tomorrow = today.AddDays(1); // haetaan kaikki kuluvan päivän tuntikirjaukset List <Timesheet> allTimesheetsToday = (from sh in entities.Timesheets where (sh.StartTime > today) && (sh.StartTime < tomorrow) && (sh.WorkCompleted == true) select sh).ToList(); // ryhmitellään kirjaukset tehtävittäin ja lasketaan kestot List <HoursPerWorkAssignmentsModel> model = new List <HoursPerWorkAssignmentsModel>(); foreach (Timesheet timesheet in allTimesheetsToday) { int assignmentId = timesheet.id_WorkAssignment.Value; HoursPerWorkAssignmentsModel existing = model.Where( m => m.WorkAssignmentId == assignmentId).FirstOrDefault(); if (existing != null) { existing.TotalHours += (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours; } else { existing = new HoursPerWorkAssignmentsModel() { WorkAssignmentId = assignmentId, WorkAssigmentName = timesheet.WorkAssignment.Title, TotalHours = (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours }; model.Add(existing); } } return(View(model)); } finally { entities.Dispose(); } }
public string[] GetAll() { string[] assignmentNames = null; TimesheetEntities entities = new TimesheetEntities(); try { assignmentNames = (from wa in entities.WorkAssignments where (wa.Active == true) select wa.Title).ToArray(); } finally { entities.Dispose(); } return(assignmentNames); }
public JsonResult DeleteRecord(int recID) { var status = false; using (TimesheetEntities dc = new TimesheetEntities()) { var v = dc.Timesheets.Where(a => a.TimesheetID == recID).FirstOrDefault(); if (v != null) { dc.Timesheets.Remove(v); dc.SaveChanges(); status = true; } } return(new JsonResult { Data = new { status = status } }); }
public string[] GetAll() { string[] employeeNames = null; TimesheetEntities entities = new TimesheetEntities(); try { //Jos olisi lista List<string> alkuun ja ToArrayn tilaalle ToLista(); employeeNames = (from e in entities.Employees where (e.Active == true) select e.FirstName + " " + e.LastName).ToArray(); } finally { entities.Dispose(); } return(employeeNames); }
public string[] GetAll() { string[] assingnmentNames = null; TimesheetEntities entities = new TimesheetEntities(); try { //Jos olisi lista List<string> alkuun ja ToArrayn tilaalle ToList(); assingnmentNames = (from wa in entities.WorkAssignments where (wa.Active == true) select wa.Title).ToArray(); } finally { entities.Dispose(); } return(assingnmentNames); }
public string[] GetAll() { string[] employeeNames = null; TimesheetEntities entities = new TimesheetEntities(); try { employeeNames = (from e in entities.Employees where (e.Active == true) select e.FirstName + " " + e.LastName).ToArray(); } finally { entities.Dispose(); } return(employeeNames); }
public string PutEmployeeImage() { TimesheetEntities entities = new TimesheetEntities(); try { Employee newEmployee = new Employee() { FirstName = "Heebo", LastName = "X", EmployeePicture = File.ReadAllBytes(@"C:\Users\maria\Koodit\Heebo.png") }; entities.Employees.Add(newEmployee); entities.SaveChanges(); return("OK!"); } finally { entities.Dispose(); } }
public bool PostStatus(FotoModel input)//, string Name, byte[]FotoData) { TimesheetEntities entities = new TimesheetEntities(); try { string[] nameParts = input.Name.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); string first = nameParts[0]; string last = nameParts[1]; Employee existing = (from ts in entities.Employees where (ts.FirstName == first) && (ts.LastName == last) select ts).FirstOrDefault(); if (existing != null) { existing.EmployeePicture = input.Fotodata; } else { return(false); } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public ActionResult Login(User user) { using (TimesheetEntities db = new TimesheetEntities()) { var userValues = db.Users.Where(x => x.Email == user.Email && x.Password == user.Password).FirstOrDefault(); if (userValues == null) { //Error message for incorrect email or password user.LoginErrorMessage = "The Email or Password field is invalid."; //user.Password = Convert.ToString(Crypto.Decode(user.Password)); return(View("Login", user)); } else { //if no action within a time frame, session will redirect to /home/login(condition in view) not users/index Session["Email"] = user.Email; Session["Name"] = userValues.FirstName; return(RedirectToAction("Index", "Users")); } } }
public byte[] GetEmployeeImage(string employeeName) { TimesheetEntities entities = new TimesheetEntities(); try { string[] nameParts = employeeName.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); string first = nameParts[0]; string last = nameParts[1]; byte[] bytes = (from e in entities.Employees where (e.Active == true) && (e.FirstName == first) && (e.LastName == last) select e.EmployeePicture).FirstOrDefault(); return(bytes); } finally { entities.Dispose(); } }
public ActionResult Edit([Bind(Include = "LocationID,LocationName,SectionID")] Location location) { try { if (ModelState.IsValid) { using (var context = new TimesheetEntities()) { Location loc = context.Locations.Find(location.LocationID); if (loc != null) { if (!(String.IsNullOrEmpty(location.LocationName) || (context.chkLocationNameExist(location.LocationName) && loc.LocationName != location.LocationName))) { db.Entry(location).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.ValLocationName = String.IsNullOrEmpty(location.LocationName) ? "You have not entered a value for Location" : $"There already exist a Location named \"{location.LocationName}\""; } } else { ViewBag.LocationName = $"This location could not be found in the database"; } } } ViewBag.SectionID = new SelectList(db.Sectors, "SectorName", "SectorName", location.SectionID); } catch (Exception ex) { ViewBag.SectionID = new SelectList(db.Sectors, "SectorName", "SectorName", location.SectionID); ViewBag.ValLocationName = $"An error occured while updating this Location \n{ex.Message}"; } return(View(location)); }
public ActionResult HoursPerWorkAssignmentAsExcel2() { StringBuilder csv = new StringBuilder(); TimesheetEntities entities = new TimesheetEntities(); try { DateTime today = DateTime.Today; DateTime tomorrow = today.AddDays(1); // haetaan kaikki kuluvan päivän tuntikirjaukset List <Timesheet> allTimesheetsToday = (from sh in entities.Timesheets where (sh.StartTime > today) && (sh.StartTime < tomorrow) && (sh.WorkCompleted == true) select sh).ToList(); // ryhmitellään kirjaukset tehtävittäin ja lasketaan kestot List <HoursPerWorkAssignmentsModel> model = new List <HoursPerWorkAssignmentsModel>(); foreach (Timesheet timesheet in allTimesheetsToday) { csv.AppendLine(timesheet.Id_Employee + "," + timesheet.StartTime + "," + timesheet.StopTime + ","); } } finally { entities.Dispose(); } //palautetaan CSV-tiedot selaimelle byte[] buffer = Encoding.UTF8.GetBytes(csv.ToString()); return(File(buffer, "Text/csv", "Työtunnit.csv")); }
public ActionResult Edit([Bind(Include = "SectorName,SectionID")] Sector sector, string oldSectorName) { try { if (ModelState.IsValid) { using (var context = new TimesheetEntities()) { Sector sec = context.Sectors.Find(sector.SectionID); if (sec != null) { if (!(String.IsNullOrEmpty(sector.SectorName) || (context.chkSectorNameExist(sector.SectorName) && sec.SectorName != sector.SectorName))) { db.Entry(sector).State = EntityState.Modified; db.SaveChanges(); //db.updateSector(oldSectorName, sector.SectorName); return(RedirectToAction("Index")); } else { ViewBag.ErrorValidation = String.IsNullOrEmpty(sector.SectorName) ? "You have not entered a value for Sector" : $"There already exist a Sector named \"{sector.SectorName}\""; } } else { ViewBag.ErrorValidation = $"This sector ID {sector.SectionID}could not be found in the database"; } } } } catch (Exception ex) { ViewBag.ErrorValidation = $"An error occured during update {ViewBag.oldSectorName}. ({ex.Message})"; } return(View(sector)); }
public string PutEmployeeImage() { TimesheetEntities entities = new TimesheetEntities(); try { Employee newEmployee = new Employee() { FirstName = "Aaro", LastName = "aalto", EmployeePicture = System.IO.File.ReadAllBytes(@"C:\Temp\Heebo.png") }; entities.Employees.Add(newEmployee); entities.SaveChanges(); return("OK!"); } finally { entities.Dispose(); } //return "Error"; }
public bool PostStatus(WorkAssignmentOperationModel input) { TimesheetEntities entities = new TimesheetEntities(); try { WorkAssignments assignment = (from wa in entities.WorkAssignments where (wa.Active == true) && (wa.Title == input.AssignmentTitle) select wa).FirstOrDefault(); if (assignment == null) { return(false); } if (input.Operation == "Start") { int assignmentId = assignment.Id_WorkAssignment; Timesheets newEntry = new Timesheets() { Id_WorkAssignment = assignmentId, StartTime = DateTime.Now, WorkComplete = false, Active = true, CreatedAt = DateTime.Now }; entities.Timesheets.Add(newEntry); //Päivitetään samalla work-assignmentin tilatietoja assignment.InProgress = true; assignment.InProgressAt = DateTime.Now; assignment.LastModifiedAt = DateTime.Now; } else if (input.Operation == "Stop") { int assignmentId = assignment.Id_WorkAssignment; Timesheets existing = (from ts in entities.Timesheets where (ts.Id_WorkAssignment == assignmentId) && (ts.Active == true) && (ts.WorkComplete == false) orderby ts.StartTime descending select ts).FirstOrDefault(); if (existing != null) { existing.StopTime = DateTime.Now; existing.WorkComplete = true; existing.LastModifiedAt = DateTime.Now; //Päivitetään samalla work-assignmentin tilatietoja assignment.InProgress = false; assignment.Completed = true; assignment.CompletedAt = DateTime.Now; assignment.LastModifiedAt = DateTime.Now; } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public bool PostStatus(WorkAssigmentOperationModel input) { TimesheetEntities entities = new TimesheetEntities(); try { //Jos olisi lista List<string> alkuun ja ToArrayn tilaalle ToLista(); WorkAssignment assingnment = (from wa in entities.WorkAssignments where (wa.Active == true) && (wa.Title == input.AssignmentTitle) select wa).FirstOrDefault(); if (assingnment == null) { return(false); } if (input.Operation == "Start") { int assignmentid = assingnment.Id_WorkAssignment; Timesheet newEntry = new Timesheet() { id_WorkAssignment = assignmentid, StartTime = DateTime.Now, WorkCompleted = false, Active = true, CreatedAt = DateTime.Now }; entities.Timesheets.Add(newEntry); } else if (input.Operation == "Stop") { int assignmentid = assingnment.Id_WorkAssignment; Timesheet existing = (from ts in entities.Timesheets where (ts.id_WorkAssignment == assignmentid) && (ts.Active == true) && (ts.WorkCompleted == false) orderby ts.StartTime descending select ts).FirstOrDefault(); if (existing != null) { existing.StopTime = DateTime.Now; existing.WorkCompleted = true; existing.LastModifiedAt = DateTime.Now; } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public bool PostStatus(WorkAssignmentOperationModel input) { TimesheetEntities entities = new TimesheetEntities(); try { WorkAssignment assignment = (from wa in entities.WorkAssignments where (wa.Active == true) && (wa.Title == input.AssignmentTitle) select wa).FirstOrDefault(); if (assignment == null) { return(false); } //string value; //decimal number; NumberStyles style; CultureInfo provider; provider = new CultureInfo("fi-FI"); string valueString = input.Latitude.ToString("R", CultureInfo.InvariantCulture); style = NumberStyles.AllowDecimalPoint; if (input.Operation == "Start") { int assignmentId = assignment.id_WorkAssignment; Timesheet newEntry = new Timesheet() { id_WorkAssignment = assignmentId, StartTime = DateTime.Now, WorkComplete = false, Active = true, CreatedAt = DateTime.Now, Latitude = Convert.ToDecimal(input.Latitude), Longitude = Convert.ToDecimal(input.Longitude) }; entities.Timesheets.Add(newEntry); } else if (input.Operation == "Stop") { int assignmentId = assignment.id_WorkAssignment; Timesheet existing = (from ts in entities.Timesheets where (ts.id_WorkAssignment == assignmentId) && (ts.Active == true) && (ts.WorkComplete == false) orderby ts.StartTime descending select ts).FirstOrDefault(); if (existing != null) { existing.StopTime = DateTime.Now; existing.WorkComplete = true; existing.LastModifiedAt = DateTime.Now; } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public Repository() { this.db = new TimesheetEntities(); }
public void NewContext() { db = new TimesheetEntities(); }