public ActionResult GetEmployeeCounts(string onlyComplete4) { ReportChartDataViewModel model = new ReportChartDataViewModel(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { model.Labels = (from wa in entities.WorkAssignments orderby wa.Id_WorkAssignment select wa.Title).ToArray(); if (onlyComplete4 == "1") { model.Counts = (from ts in entities.Timesheets where (ts.WorkComplete == true) orderby ts.Id_Employee group ts by ts.Id_Employee into grp select grp.Count()).ToArray(); } else { model.Counts = (from ts in entities.Timesheets orderby ts.Id_Employee group ts by ts.Id_Employee into grp select grp.Count()).ToArray(); } } finally { entities.Dispose(); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(ContractorsViewModel model) { MobileWorkDataEntities db = new MobileWorkDataEntities(); Contractors con = new Contractors(); con.CompanyName = model.CompanyName; con.ContactPerson = model.ContactPerson; con.PhoneNumber = model.PhoneNumber; con.EmailAddress = model.EmailAddress; con.VatId = model.VatId; con.HourlyRate = model.HourlyRate; con.CreatedAt = DateTime.Now; con.LastModifiedAt = DateTime.Now; con.DeletedAt = model.DeletedAt; con.Active = model.Active; db.Contractors.Add(con); try { db.SaveChanges(); } catch (Exception ex) { } return(RedirectToAction("Index")); }//create
public ActionResult HoursPerWorkAssignmentAsExcel2() { StringBuilder csv = new StringBuilder(); // luodaan CSV-muotoinen tiedosto MobileWorkDataEntities entities = new MobileWorkDataEntities(); 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 + ";" + timesheet.Comments + ";"); } } finally { entities.Dispose(); } // palautetaan CSV-tiedot selaimelle byte[] buffer = Encoding.UTF8.GetBytes(csv.ToString()); return(File(buffer, "text/csv", "Työtunnit2.csv")); }
}//Index // GET: Departments/Details/5 public ActionResult Details(int?id) { DepartmentsViewModel model = new DepartmentsViewModel(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { Departments departmentdetail = entities.Departments.Find(id); if (departmentdetail == null) { return(HttpNotFound()); } // muodostetaan näkymämalli tietokannan rivien pohjalta DepartmentsViewModel view = new DepartmentsViewModel(); view.Id_Department = departmentdetail.Id_Department; view.DepartmentName = departmentdetail.DepartmentName; model = view; } finally { entities.Dispose(); } return(View(model)); }//details
// GET: Departments public ActionResult Index() { List <DepartmentsViewModel> model = new List <DepartmentsViewModel>(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { List <Departments> departments = entities.Departments.OrderBy(Departments => Departments.DepartmentName).ToList(); // muodostetaan näkymämalli tietokannan rivien pohjalta foreach (Departments department in departments) { DepartmentsViewModel view = new DepartmentsViewModel(); view.Id_Department = department.Id_Department; view.DepartmentName = department.DepartmentName; model.Add(view); } } finally { entities.Dispose(); } return(View(model)); }//Index
public string PutEmployeeImage() { MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { Employees newEmployee = new Employees() { FirstName = "Teppo", LastName = "Testaaja", //EmployeePicture = File.ReadAllBytes(@"C:\TEMP\Matti.png") EmployeePicture = File.ReadAllBytes(@"D:\VisualStudio2017\MobileBackendMVC - Api\MobileBackendMVC - Api\Images\Matti.png") }; entities.Employees.Add(newEmployee); entities.SaveChanges(); return("OK!"); } finally { entities.Dispose(); } return("Error"); }
}//details // GET: Contractors/Create public ActionResult Create() { MobileWorkDataEntities db = new MobileWorkDataEntities(); ContractorsViewModel model = new ContractorsViewModel(); return(View(model)); }//create
}//details // GET: Customers/Create public ActionResult Create() { MobileWorkDataEntities entities = new MobileWorkDataEntities(); CustomersViewModel model = new CustomersViewModel(); return(View(model)); }//create
}//details // GET: Departments/Create public ActionResult Create() { MobileWorkDataEntities entities = new MobileWorkDataEntities(); DepartmentsViewModel model = new DepartmentsViewModel(); return(View(model)); }//create
}//details // GET: WorkAssignments/Create public ActionResult Create() { MobileWorkDataEntities db = new MobileWorkDataEntities(); WorkAssignmentsViewModel model = new WorkAssignmentsViewModel(); ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); return(View(model)); }//create
}//details // GET: Employees/Create public ActionResult Create() { MobileWorkDataEntities entities = new MobileWorkDataEntities(); EmployeesViewModel model = new EmployeesViewModel(); ViewBag.DepartmentName = new SelectList((from d in db.Departments select new { Id_Department = d.Id_Department, DepartmentName = d.DepartmentName }), "Id_Department", "DepartmentName", null); ViewBag.CompanyName = new SelectList((from c in db.Contractors select new { Id_Contractor = c.Id_Contractor, CompanyName = c.CompanyName }), "Id_Contractor", "CompanyName", null); return(View(model)); }//create
// GET: Timesheets public ActionResult Index() { List <TimeSheetsViewModel> model = new List <TimeSheetsViewModel>(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { //List<Timesheets> timesheets = entities.Timesheets.OrderByDescending(Timesheets => Timesheets.StartTime).ToList(); List <Timesheets> timesheets = entities.Timesheets.OrderBy(Timesheets => Timesheets.StartTime).ToList(); CultureInfo fiFi = new CultureInfo("fi-FI"); // muodostetaan näkymämalli tietokannan rivien pohjalta foreach (Timesheets timesheet in timesheets) { TimeSheetsViewModel view = new TimeSheetsViewModel(); view.Id_Timesheet = timesheet.WorkAssignments.Id_WorkAssignment; view.StartTime = timesheet.StartTime.GetValueOrDefault(); view.StopTime = timesheet.StopTime.GetValueOrDefault(); view.Comments = timesheet.Comments; view.WorkComplete = timesheet.WorkComplete; view.CreatedAt = timesheet.CreatedAt.GetValueOrDefault(); view.LastModifiedAt = timesheet.LastModifiedAt.GetValueOrDefault(); view.DeletedAt = timesheet.DeletedAt.GetValueOrDefault(); view.Active = timesheet.Active; view.Id_Employee = timesheet.Id_Employee; view.FirstName = timesheet.Employees?.FirstName; view.LastName = timesheet.Employees?.LastName; view.Id_Customer = timesheet.Customers?.Id_Customer; view.CustomerName = timesheet.Customers?.CustomerName; ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); view.Id_Contractor = timesheet.Contractors?.Id_Contractor; view.CompanyName = timesheet.Contractors?.CompanyName; ViewBag.CompanyName = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null); view.Id_WorkAssignment = timesheet.WorkAssignments?.Id_WorkAssignment; view.Title = timesheet.WorkAssignments?.Title; model.Add(view); } } finally { entities.Dispose(); } return(View(model)); }//Index
}//details // GET: Timesheets/Create public ActionResult Create() { MobileWorkDataEntities entities = new MobileWorkDataEntities(); TimeSheetsViewModel model = new TimeSheetsViewModel(); ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); ViewBag.CompanyName = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null); return(View(model)); }//create
// GET: Reports public ActionResult HoursPerWorkAssignment() { MobileWorkDataEntities entities = new MobileWorkDataEntities(); 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(); // ryhmitellään kirjaukset tehtävittäin, ja lasketaan kestot List <HoursPerWorkAssignmentModel> model = new List <HoursPerWorkAssignmentModel>(); foreach (Timesheets timesheet in allTimesheetsToday) { int assignmentId = timesheet.Id_WorkAssignment.Value; HoursPerWorkAssignmentModel existing = model.Where( m => m.Id_WorkAssignment == assignmentId).FirstOrDefault(); if (existing != null) { existing.TotalHours += (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours; } else { existing = new HoursPerWorkAssignmentModel() { Id_WorkAssignment = assignmentId, WorkAssignmentName = timesheet.WorkAssignments.Title, TotalHours = (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours, WorkComplete = timesheet.WorkComplete, StartTime = timesheet.StartTime.Value, StopTime = timesheet.StopTime.Value, Comments = timesheet.Comments }; model.Add(existing); } } return(View(model)); } finally { entities.Dispose(); } }
}//details // GET: PinCodes/Create public ActionResult Create() { MobileWorkDataEntities entities = new MobileWorkDataEntities(); PinCodesViewModel model = new PinCodesViewModel(); ViewBag.CompanyName = new SelectList((from c in db.Contractors select new { Id_Contractor = c.Id_Contractor, CompanyName = c.CompanyName }), "Id_Contractor", "CompanyName", null); ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); ViewBag.FirstName = new SelectList((from c in db.Employees select new { Id_Employee = c.Id_Employee, FirstName = c.FirstName }), "Id_Employee", "FirstName", null); ViewBag.LastName = new SelectList((from c in db.Employees select new { Id_Employee = c.Id_Employee, LastName = c.LastName }), "Id_Employee", "LastName", null); return(View(model)); }
// GET: Timesheets/Details/5 public ActionResult Details(int?id) { TimeSheetsViewModel model = new TimeSheetsViewModel(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { Timesheets timesheetdetail = entities.Timesheets.Find(id); if (timesheetdetail == null) { return(HttpNotFound()); } // muodostetaan näkymämalli tietokannan rivien pohjalta TimeSheetsViewModel view = new TimeSheetsViewModel(); view.Id_Timesheet = timesheetdetail.Id_Timesheet; view.StartTime = timesheetdetail.StartTime.GetValueOrDefault(); view.StopTime = timesheetdetail.StopTime.GetValueOrDefault(); view.Comments = timesheetdetail.Comments; view.WorkComplete = timesheetdetail.WorkComplete; view.CreatedAt = timesheetdetail.CreatedAt.GetValueOrDefault(); view.LastModifiedAt = timesheetdetail.LastModifiedAt.GetValueOrDefault(); view.DeletedAt = timesheetdetail.DeletedAt.GetValueOrDefault(); view.Active = timesheetdetail.Active; view.Id_Employee = timesheetdetail.Id_Employee; view.FirstName = timesheetdetail.Employees?.FirstName; view.LastName = timesheetdetail.Employees?.LastName; view.Id_Customer = timesheetdetail.Customers?.Id_Customer; view.CustomerName = timesheetdetail.Customers?.CustomerName; ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); view.Id_Contractor = timesheetdetail.Contractors?.Id_Contractor; view.CompanyName = timesheetdetail.Contractors?.CompanyName; ViewBag.CompanyName = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null); view.Id_WorkAssignment = timesheetdetail.WorkAssignments?.Id_WorkAssignment; view.Title = timesheetdetail.WorkAssignments?.Title; model = view; } finally { entities.Dispose(); } return(View(model)); }//details
public ActionResult Create(EmployeesViewModel model) { MobileWorkDataEntities entities = new MobileWorkDataEntities(); Employees emp = new Employees(); emp.Id_Employee = model.Id_Employee; emp.FirstName = model.FirstName; emp.LastName = model.LastName; emp.PhoneNumber = model.PhoneNumber; emp.EmailAddress = model.EmailAddress; emp.EmployeeReference = model.EmployeeReference; emp.DeletedAt = model.DeletedAt; emp.Active = model.Active; emp.EmployeePicture = model.EmployeePicture; db.Employees.Add(emp); int contractorId = int.Parse(model.CompanyName); if (contractorId > 0) { Contractors con = db.Contractors.Find(contractorId); emp.Id_Contractor = con.Id_Contractor; } int departmentId = int.Parse(model.DepartmentName); if (departmentId > 0) { Departments dep = db.Departments.Find(departmentId); emp.Id_Department = dep.Id_Department; } try { db.SaveChanges(); } catch (Exception ex) { } ViewBag.DepartmentName = new SelectList((from d in db.Departments select new { Id_Department = d.Id_Department, DepartmentName = d.DepartmentName }), "Id_Department", "DepartmentName", null); ViewBag.CompanyName = new SelectList((from c in db.Contractors select new { Id_Contractor = c.Id_Contractor, CustomerName = c.CompanyName }), "Id_Contractor", "CompanyName", null); return(RedirectToAction("Index")); }//create
// GET: Employees public ActionResult Index() { List <EmployeesViewModel> model = new List <EmployeesViewModel>(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { List <Employees> employees = entities.Employees.OrderBy(Employees => Employees.LastName).ToList(); // muodostetaan näkymämalli tietokannan rivien pohjalta foreach (Employees employee in employees) { EmployeesViewModel view = new EmployeesViewModel(); view.Id_Employee = employee.Id_Employee; view.FirstName = employee.FirstName; view.LastName = employee.LastName; view.PhoneNumber = employee.PhoneNumber; view.EmailAddress = employee.EmailAddress; view.EmployeeReference = employee.EmployeeReference; view.DeletedAt = employee.DeletedAt; view.Active = employee.Active; view.EmployeePicture = employee.EmployeePicture; view.Id_PinCode = employee.PinCodes.FirstOrDefault()?.Id_PinCode; view.PinCode = employee.PinCodes.FirstOrDefault()?.PinCode; ViewBag.PinCode = new SelectList((from u in db.PinCodes select new { Id_PinCode = u.Id_PinCode, PinCode = u.PinCode }), "Id_PinCode", "PinCode", null); view.Id_Contractor = employee.Contractors?.Id_Contractor; view.CompanyName = employee.Contractors?.CompanyName; view.Id_Department = employee.Departments?.Id_Department; view.DepartmentName = employee.Departments?.DepartmentName; model.Add(view); } } finally { entities.Dispose(); } return(View(model)); }//Index
public ActionResult Create(TimeSheetsViewModel model) { MobileWorkDataEntities entities = new MobileWorkDataEntities(); Timesheets tsv = new Timesheets(); tsv.Id_Timesheet = model.Id_Timesheet; tsv.StartTime = model.StartTime; tsv.StopTime = model.StopTime; tsv.Comments = model.Comments; tsv.CreatedAt = DateTime.Now; tsv.LastModifiedAt = DateTime.Now; tsv.Active = model.Active; db.Timesheets.Add(tsv); int employeeId = int.Parse(model.FirstName); if (employeeId > 0) { Employees emp = db.Employees.Find(employeeId); tsv.Id_Employee = emp.Id_Employee; } int employeeLastId = int.Parse(model.LastName); if (employeeLastId > 0) { Employees emp = db.Employees.Find(employeeLastId); tsv.Id_Employee = emp.Id_Employee; } ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); ViewBag.CompanyName = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null); try { db.SaveChanges(); } catch (Exception ex) { } return(RedirectToAction("Index")); }//create
public string[] GetAll() { string[] customerNames = null; MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { customerNames = (from c in entities.Customers where (c.Active == true) select c.CustomerName).ToArray(); } finally { entities.Dispose(); } return(customerNames); }
public string[] GetAll() { string[] assignmentNames = null; MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { assignmentNames = (from wa in entities.WorkAssignments where (wa.Active == true) select wa.Title).ToArray(); } finally { entities.Dispose(); } return(assignmentNames); }
// GET: PinCodes public ActionResult Index() { List <PinCodesViewModel> model = new List <PinCodesViewModel>(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { List <PinCodes> pincodes = entities.PinCodes.OrderBy(PinCodes => PinCodes.PinCode).ToList(); // muodostetaan näkymämalli tietokannan rivien pohjalta foreach (PinCodes pincode in pincodes) { PinCodesViewModel view = new PinCodesViewModel(); view.Id_PinCode = pincode.Id_PinCode; view.PinCode = pincode.PinCode; view.CreatedAt = pincode.CreatedAt; view.LastModifiedAt = pincode.LastModifiedAt; view.DeletedAt = pincode.DeletedAt; view.Active = pincode.Active; view.Id_Customer = pincode.Customers?.Id_Customer; view.CustomerName = pincode.Customers?.CustomerName; ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); view.Id_Contractor = pincode.Contractors?.Id_Contractor; view.CompanyName = pincode.Contractors?.CompanyName; ViewBag.CompanyName = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null); view.Id_Employee = pincode.Employees?.Id_Employee; view.FirstName = pincode.Employees?.FirstName; view.LastName = pincode.Employees?.LastName; model.Add(view); } } finally { entities.Dispose(); } return(View(model)); }//Index
// GET: WorkAssignments public ActionResult Index() { List <WorkAssignmentsViewModel> model = new List <WorkAssignmentsViewModel>(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { List <WorkAssignments> workAssignments = entities.WorkAssignments.OrderBy(WorkAssignments => WorkAssignments.Deadline).ToList(); CultureInfo fiFi = new CultureInfo("fi-FI"); // muodostetaan näkymämalli tietokannan rivien pohjalta foreach (WorkAssignments workAssignment in workAssignments) { WorkAssignmentsViewModel view = new WorkAssignmentsViewModel(); view.Id_WorkAssignment = workAssignment.Id_WorkAssignment; view.Title = workAssignment.Title; view.Description = workAssignment.Description; view.Deadline = workAssignment.Deadline; view.CreatedAt = workAssignment.CreatedAt; view.InProgress = workAssignment.InProgress; view.InProgressAt = workAssignment.InProgressAt; view.CompletedAt = workAssignment.CompletedAt; view.Completed = workAssignment.Completed; view.LastModifiedAt = workAssignment.LastModifiedAt; view.DeletedAt = workAssignment.DeletedAt; view.Active = workAssignment.Active; view.Id_Customer = workAssignment.Customers?.Id_Customer; view.CustomerName = workAssignment.Customers?.CustomerName; ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); model.Add(view); } } finally { entities.Dispose(); } return(View(model)); }//Index
public string[] GetAll() { string[] employeeNames = null; MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { employeeNames = (from e in entities.Employees where (e.Active == true) select e.FirstName + " " + e.LastName).ToArray(); } finally { entities.Dispose(); } return(employeeNames); }
}//Index // GET: PinCodes/Details/5 public ActionResult Details(int?id) { PinCodesViewModel model = new PinCodesViewModel(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { PinCodes pincodedetail = entities.PinCodes.Find(id); if (pincodedetail == null) { return(HttpNotFound()); } // muodostetaan näkymämalli tietokannan rivien pohjalta PinCodesViewModel view = new PinCodesViewModel(); view.Id_PinCode = pincodedetail.Id_PinCode; view.PinCode = pincodedetail.PinCode; view.CreatedAt = pincodedetail.CreatedAt; view.LastModifiedAt = pincodedetail.LastModifiedAt; view.DeletedAt = pincodedetail.DeletedAt; view.Active = pincodedetail.Active; view.Id_Customer = pincodedetail.Customers?.Id_Customer; view.CustomerName = pincodedetail.Customers?.CustomerName; ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); view.Id_Contractor = pincodedetail.Contractors?.Id_Contractor; view.CompanyName = pincodedetail.Contractors?.CompanyName; ViewBag.CompanyName = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null); view.Id_Employee = pincodedetail.Employees?.Id_Employee; view.FirstName = pincodedetail.Employees?.FirstName; view.LastName = pincodedetail.Employees?.LastName; model = view; } finally { entities.Dispose(); } return(View(model)); }//details
}//Index // GET: WorkAssignments/Details/5 public ActionResult Details(int?id) { WorkAssignmentsViewModel model = new WorkAssignmentsViewModel(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { WorkAssignments workassdetail = entities.WorkAssignments.Find(id); if (workassdetail == null) { return(HttpNotFound()); } // muodostetaan näkymämalli tietokannan rivien pohjalta WorkAssignmentsViewModel view = new WorkAssignmentsViewModel(); view.Id_WorkAssignment = workassdetail.Id_WorkAssignment; view.Title = workassdetail.Title; view.Description = workassdetail.Description; view.Deadline = workassdetail.Deadline; view.CreatedAt = workassdetail.CreatedAt; view.InProgress = workassdetail.InProgress; view.InProgressAt = workassdetail.InProgressAt; view.CompletedAt = workassdetail.CompletedAt; view.Completed = workassdetail.Completed; view.LastModifiedAt = workassdetail.LastModifiedAt; view.DeletedAt = workassdetail.DeletedAt; view.Active = workassdetail.Active; view.Id_Customer = workassdetail.Customers?.Id_Customer; view.CustomerName = workassdetail.Customers?.CustomerName; ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", view.Id_Customer); model = view; } finally { entities.Dispose(); } return(View(model)); }//details
}//Index // GET: Employees/Details/5 public ActionResult Details(int?id) { EmployeesViewModel model = new EmployeesViewModel(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { Employees employeedetail = entities.Employees.Find(id); if (employeedetail == null) { return(HttpNotFound()); } // muodostetaan näkymämalli tietokannan rivien pohjalta EmployeesViewModel view = new EmployeesViewModel(); view.Id_Employee = employeedetail.Id_Employee; view.FirstName = employeedetail.FirstName; view.LastName = employeedetail.LastName; view.PhoneNumber = employeedetail.PhoneNumber; view.EmailAddress = employeedetail.EmailAddress; view.EmployeeReference = employeedetail.EmployeeReference; view.DeletedAt = employeedetail.DeletedAt; view.Active = employeedetail.Active; view.EmployeePicture = employeedetail.EmployeePicture; view.Id_Contractor = employeedetail.Contractors?.Id_Contractor; view.CompanyName = employeedetail.Contractors?.CompanyName; view.Id_Department = employeedetail.Departments?.Id_Department; view.DepartmentName = employeedetail.Departments?.DepartmentName; model = view; } finally { entities.Dispose(); } return(View(model)); }//details
// GET: Contractors public ActionResult Index() { List <ContractorsViewModel> model = new List <ContractorsViewModel>(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { List <Contractors> contractors = entities.Contractors.OrderBy(Contractors => Contractors.CompanyName).ToList(); // muodostetaan näkymämalli tietokannan rivien pohjalta foreach (Contractors contractor in contractors) { ContractorsViewModel view = new ContractorsViewModel(); view.Id_Contractor = contractor.Id_Contractor; view.CompanyName = contractor.CompanyName; view.ContactPerson = contractor.ContactPerson; view.PhoneNumber = contractor.PhoneNumber; view.EmailAddress = contractor.EmailAddress; view.VatId = contractor.VatId; view.HourlyRate = contractor.HourlyRate; view.CreatedAt = contractor.CreatedAt; view.LastModifiedAt = contractor.LastModifiedAt; view.DeletedAt = contractor.DeletedAt; view.Active = contractor.Active; view.Id_PinCode = contractor.PinCodes.FirstOrDefault()?.Id_PinCode; view.PinCode = contractor.PinCodes.FirstOrDefault()?.PinCode; ViewBag.PinCode = new SelectList((from u in db.PinCodes select new { Id_PinCode = u.Id_PinCode, PinCode = u.PinCode }), "Id_PinCode", "PinCode", null); model.Add(view); } } finally { entities.Dispose(); } return(View(model)); }//Index
public ActionResult Create(WorkAssignmentsViewModel model) { MobileWorkDataEntities db = new MobileWorkDataEntities(); WorkAssignments wam = new WorkAssignments(); wam.Title = model.Title; wam.Description = model.Description; wam.Deadline = model.Deadline; wam.CreatedAt = DateTime.Now; wam.InProgress = model.InProgress; wam.InProgressAt = model.InProgressAt; wam.CompletedAt = model.CompletedAt; wam.Completed = model.Completed; wam.LastModifiedAt = DateTime.Now; wam.Active = true;; db.WorkAssignments.Add(wam); int customerId = int.Parse(model.CustomerName); if (customerId > 0) { Customers cus = db.Customers.Find(customerId); wam.Id_Customer = cus.Id_Customer; } ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); try { db.SaveChanges(); } catch (Exception ex) { } return(RedirectToAction("Index")); }//create
public ActionResult Create(DepartmentsViewModel model) { MobileWorkDataEntities entities = new MobileWorkDataEntities(); Departments dep = new Departments(); dep.DepartmentName = model.DepartmentName; db.Departments.Add(dep); try { db.SaveChanges(); } catch (Exception ex) { } return(RedirectToAction("Index")); }//create