public static void CreateEquipmentAssignmentRecord(EquipmentAssignmentRecordModel newAssignment) { foreach (EquipmentModel item in newAssignment.SelectedItems) { using (var connection = new System.Data.SqlClient.SqlConnection(CnnString("WorkDeskDB"))) { var p = new DynamicParameters(); p.Add("@EmployeeId", newAssignment.EmployeeId); p.Add("@EquipmentId", item.Id); if (newAssignment.Id == 0) { p.Add("@DepartmentId", null); } else { p.Add("@DepartmentId", newAssignment.DepartmentId); } p.Add("@DateOut", newAssignment.DateOut); p.Add("@IsStandardIssue", newAssignment.IsStandardIssue); p.Add("@IsDepartment", newAssignment.IsDepartment); if (newAssignment.IsStandardIssue == false) { p.Add("@DueDate", newAssignment.DueDate); p.Add("@JobsiteId", newAssignment.Jobsite); } else { p.Add("@DueDate", null); p.Add("@JobsiteId", null); } connection.Execute("dbo.spEquipmentAssignmentRecord_Insert", p, commandType: System.Data.CommandType.StoredProcedure); } } }
//CONSTRUCTOR public AssignItemWindowViewModel() { NewEquipmentAssignmentRecord = new EquipmentAssignmentRecordModel(); LoadDataSourcesCommand = new RelayCommand <object>(LoadDataSources); AddItemToListCommand = new RelayCommand <object>(AddItemToList); CreateAssignmentRecordCommand = new RelayCommand <object>(CreateAssignmentRecord); Equipment = new ObservableCollection <EquipmentModel>(); Departments = new ObservableCollection <DepartmentModel>(); AuthorizedEmployees = new ObservableCollection <EmployeeModel>(); SelectedItems = new ObservableCollection <EquipmentModel>(); Jobsites = new ObservableCollection <JobsiteModel>(); }
//DATA VALIDATION public void ValidateData(EquipmentAssignmentRecordModel record) { StringBuilder message = new StringBuilder(); if (record.IsDepartment == false && SelectedEmployee == null) { string userMessage = "Please select an employee to receive the assignment."; message.Append(userMessage); message.AppendLine(); message.AppendLine(); } if (record.IsDepartment && SelectedDepartment == null) { string userMessage = "Please select a department to receive the assignment."; message.Append(userMessage); message.AppendLine(); message.AppendLine(); } if (record.IsStandardIssue == false && DueDate == default) { string dueDateMessage = "You have selected NO to Standard Issue. Therefore, please select a due date for the selected items."; message.Append(dueDateMessage); message.AppendLine(); message.AppendLine(); } if (record.DateOut == default) { string assignedDateMessage = "Please select an assignment date."; message.Append(assignedDateMessage); message.AppendLine(); message.AppendLine(); } if (record.SelectedItems == null) { string selectedItemsMessage = "Please select one or more items to create an assignment."; message.AppendLine(selectedItemsMessage); message.AppendLine(); message.AppendLine(); } if (message.Length == 0) { string successMessage = "The items have been assigned successfully."; message.AppendLine(successMessage); message.AppendLine(); } MessageBox.Show(message.ToString(), "Adjustment Needed"); message.Clear(); }
//ASSEMBLE DATA public void AssembleData(EquipmentAssignmentRecordModel record) { record.DateOut = AssignedDate; record.SelectedItems = SelectedItems.ToList(); record.IsDepartment = IsDepartment; record.IsStandardIssue = IsStandardIssue; if (record.IsStandardIssue == false) { record.DueDate = DueDate; record.Jobsite = Destination; } if (record.IsDepartment) { record.DepartmentId = SelectedDepartment.Id; } if (IsDepartment == false) { record.EmployeeId = SelectedEmployee.Id; } }
public static async Task <ObservableCollection <EmployeeModel> > EmployeeQueryAsync() { using (var connection = new System.Data.SqlClient.SqlConnection(CnnString(database))) { var employees = new Dictionary <int, EmployeeModel>(); await connection.QueryAsync <EmployeeModel>("dbo.spGetEmployeeData_All", new[] { typeof(EmployeeModel), typeof(EmailModel), typeof(JobTitleModel), typeof(PhoneModel), typeof(DepartmentModel), typeof(EmployeeStatusModel), typeof(CitationModel), typeof(CertificationModel), typeof(EquipmentAssignmentRecordModel), typeof(RestrictionModel) } , obj => { EmployeeModel employeeModel = obj[0] as EmployeeModel; EmailModel emailModel = obj[1] as EmailModel; JobTitleModel titleModel = obj[2] as JobTitleModel; PhoneModel phoneModel = obj[3] as PhoneModel; DepartmentModel departmentModel = obj[4] as DepartmentModel; EmployeeStatusModel statusModel = obj[5] as EmployeeStatusModel; CitationModel citationModel = obj[6] as CitationModel; CertificationModel certificationModel = obj[7] as CertificationModel; EquipmentAssignmentRecordModel equipmentAssignmentRecord = obj[8] as EquipmentAssignmentRecordModel; RestrictionModel restrictionModel = obj[9] as RestrictionModel; //employeemodel var employeeEntity = new EmployeeModel(); if (!employees.TryGetValue(employeeModel.Id, out employeeEntity)) { employees.Add(employeeModel.Id, employeeEntity = employeeModel); } //list<emailmodel> if (employeeEntity.Emails == null) { employeeEntity.Emails = new ObservableCollection <EmailModel>(); } if (emailModel != null) { if (!employeeEntity.Emails.Any(x => x.Id == emailModel.Id)) { employeeEntity.Emails.Add(emailModel); } } //phonemodel if (employeeEntity.Phones == null) { employeeEntity.Phones = new ObservableCollection <PhoneModel>(); } if (phoneModel != null) { if (!employeeEntity.Phones.Any(x => x.Id == phoneModel.Id)) { employeeEntity.Phones.Add(phoneModel); } } //title if (employeeEntity.JobTitle == null) { if (titleModel != null) { employeeEntity.JobTitle = titleModel; } } //department if (employeeEntity.Department == null) { if (departmentModel != null) { employeeEntity.Department = departmentModel; } } //status if (employeeEntity.Status == null) { if (statusModel != null) { employeeEntity.Status = statusModel; } } //citation if (employeeEntity.Citations == null) { employeeEntity.Citations = new ObservableCollection <CitationModel>(); } if (citationModel != null) { if (!employeeEntity.Citations.Any(x => x.Id == citationModel.Id)) { employeeEntity.Citations.Add(citationModel); } } //certification if (employeeEntity.Certifications == null) { employeeEntity.Certifications = new ObservableCollection <CertificationModel>(); } if (certificationModel != null) { if (!employeeEntity.Certifications.Any(x => x.Id == certificationModel.Id)) { employeeEntity.Certifications.Add(certificationModel); } } //restriction if (employeeEntity.Restrictions == null) { employeeEntity.Restrictions = new ObservableCollection <RestrictionModel>(); } if (restrictionModel != null) { if (!employeeEntity.Restrictions.Any(x => x.Id == restrictionModel.Id)) { employeeEntity.Restrictions.Add(restrictionModel); } } //equipment record if (employeeEntity.EquipmentAssignments == null) { employeeEntity.EquipmentAssignments = new ObservableCollection <EquipmentAssignmentRecordModel>(); } if (equipmentAssignmentRecord != null) { if (!employeeEntity.EquipmentAssignments.Any(x => x.Id == equipmentAssignmentRecord.Id)) { employeeEntity.EquipmentAssignments.Add(equipmentAssignmentRecord); } } return(employeeEntity); });; var result = employees.Values.ToList(); var employeeCollection = new ObservableCollection <EmployeeModel>(result); return(employeeCollection); } }
public async Task <ObservableCollection <EmployeeModel> > GetEmployeeList() { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("WorkDeskDB"))) { var sql = @"SELECT e.id, e.FirstName, e.LastName, e.Nickname, e.HireDate, em.id as ID, em.Address, em.Type, jt.id as ID, jt.Name, p.id as ID, p.Number, p.Type, d.id as ID, d.Name, es.id as ID, es.Name, ecitt.id as ID, cit.Name, ecitt.Date, ecitt.Description, ecert.id as ID, cet.Name, cet.Description, ecert.InitialDate, ecert.EmployeeID, eqa.id as ID, eq.InventoryID, eq.Description, eqa.DateOut, eqa.DateIn, eqa.ConditionOut, eqa.ConditionIn, eqa.DueDate FROM dbo.Employees e LEFT JOIN dbo.Emails em ON em.EmployeeID = e.id LEFT JOIN dbo.JobTitles jt ON e.JobTitleID = jt.id LEFT JOIN Phones p ON p.EmployeeID = e.id LEFT JOIN dbo.Departments d ON e.DepartmentID = d.id LEFT JOIN dbo.EmployeeStatus es ON e.StatusID = es.id LEFT JOIN dbo.EmployeeCitationType ecitt ON e.id = ecitt.EmployeeID LEFT JOIN dbo.CitationTypes cit ON ecitt.CitationTypeID = cit.id LEFT JOIN dbo.EmployeeCertificationType ecert ON e.id = ecert.EmployeeID LEFT JOIN dbo.CertificationType cet ON ecert.NameID = cet.id LEFT JOIN EquipmentAssignments eqa ON eqa.EmployeeID = e.id LEFT JOIN Equipment eq ON eqa.EquipmentID = eq.id" ; var employees = new Dictionary <int, EmployeeModel>(); await connection.QueryAsync <EmployeeModel> (sql, new[] { typeof(EmployeeModel), typeof(EmailModel), typeof(TitleModel), typeof(PhoneModel), typeof(DepartmentModel), typeof(EmployeeStatusModel), typeof(CitationModel), typeof(CertificationModel), typeof(EquipmentAssignmentRecordModel) } , obj => { EmployeeModel employeeModel = obj[0] as EmployeeModel; EmailModel emailModel = obj[1] as EmailModel; TitleModel titleModel = obj[2] as TitleModel; PhoneModel phoneModel = obj[3] as PhoneModel; DepartmentModel departmentModel = obj[4] as DepartmentModel; EmployeeStatusModel statusModel = obj[5] as EmployeeStatusModel; CitationModel citationModel = obj[6] as CitationModel; CertificationModel certificationModel = obj[7] as CertificationModel; EquipmentAssignmentRecordModel equipmentAssignmentRecord = obj[8] as EquipmentAssignmentRecordModel; //employeemodel EmployeeModel employeeEntity = new EmployeeModel(); if (!employees.TryGetValue(employeeModel.ID, out employeeEntity)) { employees.Add(employeeModel.ID, employeeEntity = employeeModel); } //list<emailmodel> if (employeeEntity.Emails == null) { employeeEntity.Emails = new ObservableCollection <EmailModel>(); } if (emailModel != null) { if (!employeeEntity.Emails.Any(x => x.ID == emailModel.ID)) { employeeEntity.Emails.Add(emailModel); } } //phonemodel if (employeeEntity.Phones == null) { employeeEntity.Phones = new ObservableCollection <PhoneModel>(); } if (phoneModel != null) { if (!employeeEntity.Phones.Any(x => x.ID == phoneModel.ID)) { employeeEntity.Phones.Add(phoneModel); } } //title if (employeeEntity.JobTitle == null) { if (titleModel != null) { employeeEntity.JobTitle = titleModel; } } //department if (employeeEntity.Department == null) { if (departmentModel != null) { employeeEntity.Department = departmentModel; } } //status if (employeeEntity.JobStatus == null) { if (statusModel != null) { employeeEntity.JobStatus = statusModel; } } //citation if (employeeEntity.Citations == null) { employeeEntity.Citations = new ObservableCollection <CitationModel>(); } if (citationModel != null) { if (!employeeEntity.Citations.Any(x => x.ID == citationModel.ID)) { employeeEntity.Citations.Add(citationModel); } } //certification if (employeeEntity.Certifications == null) { employeeEntity.Certifications = new ObservableCollection <CertificationModel>(); } if (certificationModel != null) { if (!employeeEntity.Certifications.Any(x => x.ID == certificationModel.ID)) { employeeEntity.Certifications.Add(certificationModel); } } //equipment record if (employeeEntity.EquipmentAssignments == null) { employeeEntity.EquipmentAssignments = new ObservableCollection <EquipmentAssignmentRecordModel>(); } if (equipmentAssignmentRecord != null) { if (!employeeEntity.EquipmentAssignments.Any(x => x.ID == equipmentAssignmentRecord.ID)) { employeeEntity.EquipmentAssignments.Add(equipmentAssignmentRecord); } } return(employeeEntity); });; var result = employees.Values.ToList(); ObservableCollection <EmployeeModel> employeeCollection = new ObservableCollection <EmployeeModel>(result); return(employeeCollection); } }