//Adds selected users to a project protected void buttonAssignUser_Click(object sender, EventArgs e) { AssignLabel.Text = ""; foreach (ListItem l in lbUnassignedUsers.Items) { if (l.Selected) { EmployeeProject ep = new EmployeeProject() { empId = Convert.ToInt32(l.Value), projId = Convert.ToInt32(ddlAllProjects.SelectedValue) }; try { ff.EmployeeProjects.InsertOnSubmit(ep); ff.SubmitChanges(); } catch (Exception ex) { AssignLabel.Text = "An error has occured: " + ex.Message; AssignLabel.ForeColor = System.Drawing.Color.Red; } } } populateListBoxes(); }
//Removes selected users to a project protected void buttonUnassignUser_Click(object sender, EventArgs e) { AssignLabel.Text = ""; foreach (ListItem l in lbAssignedEmployees.Items) { if (l.Selected) { EmployeeProject ep = new EmployeeProject() { empId = Convert.ToInt32(l.Value), projId = Convert.ToInt32(ddlAllProjects.SelectedValue) }; try { ff.EmployeeProjects.Attach(ep); ff.EmployeeProjects.DeleteOnSubmit(ep); ff.SubmitChanges(); } catch (System.Data.SqlClient.SqlException sx) { Trace.Write("An error has occured: " + sx.Message); AssignLabel.Text = "An error has occured: Is a selected user a Responsible Engineer?"; AssignLabel.ForeColor = System.Drawing.Color.Red; } catch (Exception ex) { Trace.Write("An error has occured: " + ex.Message); AssignLabel.Text = "An error has occured; Please check server log"; AssignLabel.ForeColor = System.Drawing.Color.Red; } } } populateListBoxes(); }
public void SetUp() { e = new Employee(); d = new Department(); ep = new EmployeeProject(); p = new Project(); q = null; results = null; currentRowIndex = 0; }
/// <summary> /// Creates a project /// </summary> /// <param name="model">Project name</param> public void Create(ProjectServiceModel model) { var project = new Project { Name = model.Name, Description = model.Description, StartDate = model.StartDate, EndDate = model.EndDate, CompanyId = model.CompanyId, ProjectCode = $"#{DateTime.UtcNow.Day}{DateTime.UtcNow.Hour}{DateTime.UtcNow.Minute}{DateTime.UtcNow.Millisecond}" }; data.Projects.Add(project); var employeeProject = new EmployeeProject { Employee = employeeDataService.FindById(model.ProjectManager).Result, Project = project }; data.EmployeeProjects.Add(employeeProject); data.SaveChanges(); }
public IActionResult AddProject(AddProjectViewModel project) { if (ModelState.IsValid) { EmployeeProject newEmployee = new EmployeeProject { EmployeeId = project.EmployeeId, Name = project.Name, Start = project.Start, Finish = project.Finish, Completed = project.Completed, JobPosition = project.JobPosition, ProjectId = project.ProjectId, Notes = project.Notes }; _employeeRepository.AddEmpProject(newEmployee); var successMessage = "Project Info Created Successfully. Name: " + newEmployee.EmployeeId; TempData["successAlert"] = successMessage; // return RedirectToAction(successMessage, ""); return(PartialView("_PartialMessage")); } return(View()); }
partial void EmployeeProjects_Inserting(EmployeeProject entity) { //string EmpName = SessionManager.Session["UserName"].ToString(); //string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["IntrinsicKey"].ConnectionString; //SqlConnection conn = new SqlConnection(connString); //string sql = "Select EmpID from EmployeeDetails where UserName='******'"; //SqlDataAdapter da = new SqlDataAdapter(sql, conn); //DataSet ds = new DataSet(); //da.Fill(ds, "Emp"); entity.EmpID = Convert.ToInt32(SessionManager.Session["EmpID"].ToString()); //entity.EmployeeProject.MonthID = 7; //entity.Months.MonthID= 7; //entity.Months.MonthName = "July"; //var s = entity.c_Date; ////var Fdate = new Date(s); ////var Tmnth = ("0" + (s.getMonth() + 1)).slice(-2) //// Fmnth = ("0" + (Fdate.getMonth() + 1)).slice(-2), //// Fday = ("0" + Fdate.getDate()).slice(-2); ////Fyear = Fdate.getFullYear(); //string month = s.ToString("MMMM"); ////entity.Months.MonthName = month; //// entity.Months.MonthName = s.ToString("MMMM"); //string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["IntrinsicKey"].ConnectionString; //SqlConnection conn = new SqlConnection(connString); //string getMonthID = "select MonthID from Month where MonthName='" + month + "'"; //SqlDataAdapter daM = new SqlDataAdapter(getMonthID, conn); //DataSet dsM = new DataSet(); //daM.Fill(dsM, "Month"); //if (dsM.Tables["Month"].Rows[0][0].ToString() != "") //{ //entity.Months.MonthName. = 7; // // entity.Months.MonthID = Convert.ToInt32(dsM.Tables["Month"].Rows[0][0].ToString()); // // entity.ProjectDetail.ProjectID = Convert.ToInt32(dsM.Tables["Month"].Rows[0][0].ToString()); //} }
partial void InsertEmployeeProject(EmployeeProject instance);
private void attach_EmployeeProjects(EmployeeProject entity) { this.SendPropertyChanging(); entity.Employee = this; }
public void Add(EmployeeProject entity) { _entities.Add(entity); }
public static void deleteEmployeeProject(EmployeeProject EmployeeProjectObj) { EmployeeProjectDBMapper dbm = new EmployeeProjectDBMapper(); dbm.delete(EmployeeProjectObj); }
public static void saveEmployeeProject(DataTable dt, ref EmployeeProject mo) { foreach (DataRow dr in dt.Rows) { saveEmployeeProject(dr, ref mo); } }
/// <summary> /// Reload the EmployeeProject from the database /// </summary> /// <remarks> /// use this method when you want to relad the EmployeeProject /// from the database, discarding any changes /// </remarks> public static void reload(ref EmployeeProject mo) { if (mo == null) { throw new System.ArgumentNullException("null object past to reload function"); } mo = (EmployeeProject)new EmployeeProjectDBMapper().findByKey(mo.Id); }
public async Task <IActionResult> UpdateEmployeeProject(int EmployeeProjectId, EmployeeProject employeeProject) { try { var res = await _service.UpdateEmployeeProject(EmployeeProjectId, employeeProject); if (res != null) { return(Ok(res)); } return(StatusCode(StatusCodes.Status204NoContent)); } catch (Exception ex) { throw; } }
public void saveEmployeeProject(EmployeeProject mo) { base.save(mo); }
public EmployeeProject AddEmpProject(EmployeeProject project) { _context.EmployeeProjects.Add(project); _context.SaveChanges(); return(project); }
partial void DeleteEmployeeProject(EmployeeProject instance);
public static void Initialize(ProjectManagementSystemDbContext _context) { if (_context.Project.Any()) { return; } var customers = new Customer[] { new Customer { FirstName = "Adam", LastName = "Nowak", CompanyName = "Diet System Company", NIP = "18492793019", Email = "*****@*****.**", Phone = "+48345198429" }, new Customer { FirstName = "Grażyna", LastName = "Olchowik", Email = "*****@*****.**", Phone = "+44738987219" }, }; _context.Customer.AddRange(customers); _context.SaveChanges(); var employees = new Employee[] { new Employee { FirstName = "John", LastName = "Goldenwick", Email = "*****@*****.**", PhoneNumber = "+12673549074" }, new Employee { FirstName = "Bogdan", LastName = "Jaworski", Email = "*****@*****.**", NIP = "83506209659", PhoneNumber = "+48735016009" }, new Employee { FirstName = "Нюша", LastName = "Сатю", Email = "*****@*****.**", PhoneNumber = "+7348567209" }, }; _context.Employee.AddRange(employees); _context.SaveChanges(); var projects = new Project[] { new Project { Name = "Advertising campaign for ITServicesInternational", Description = "Creating WebPage with offer and blog from DB, logo and business card. To discuss with ITServices manager.", StartDate = new DateTime(2018, 06, 01, 10, 00, 00), Customer = customers.Single(d => d.FirstName == "Adam") }, new Project { Name = "Web application for DietSystemCompany", Description = "Creating WebPage with WebApi. All content the Company give us later.", StartDate = new DateTime(2018, 06, 20, 08, 30, 00), Customer = customers.Single(d => d.FirstName == "Grażyna") }, new Project { Name = "Garden system for PsikankaPoland", Description = "Creating WebPage with WebApi and devices based on arduino with phisical system. All details later.", StartDate = new DateTime(2018, 08, 10, 18, 00, 00), Customer = customers.Single(d => d.FirstName == "Grażyna") }, new Project { Name = "BMW Car Configurator Optimization", Description = "For better working on mobile devices. Seriously", StartDate = new DateTime(2018, 11, 25, 16, 00, 00), Customer = customers.Single(d => d.FirstName == "Adam") }, }; _context.Project.AddRange(projects); _context.SaveChanges(); var employeeProjects = new EmployeeProject[] { new EmployeeProject { Employee = employees.Single(d => d.FirstName == "John"), Project = projects.Single(d => d.Name == "Advertising campaign for ITServicesInternational") }, new EmployeeProject { Employee = employees.Single(d => d.FirstName == "Bogdan"), Project = projects.Single(d => d.Name == "Advertising campaign for ITServicesInternational") }, new EmployeeProject { Employee = employees.Single(e => e.FirstName == "Нюша"), Project = projects.Single(d => d.Name == "Advertising campaign for ITServicesInternational") }, }; _context.EmployeeProject.AddRange(employeeProjects); _context.SaveChanges(); }
protected void gvUnassignedEmployees_RowCommand(object sender, GridViewCommandEventArgs e) { lblBudgetError.Text = ""; try { if (parentWpID == null) { if (e.CommandName == "btnAdd") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvUnassignedEmployees.Rows[row]; EmployeeWorkPackage ewp = new EmployeeWorkPackage(); EmployeeProject ep = new EmployeeProject(); ep.projId = Convert.ToInt32(Session["projID"]); ewp.projId = Convert.ToInt32(Session["projID"]); ewp.wpId = Session["wpID"].ToString(); ewp.empId = Convert.ToInt32(selectedRow.Cells[1].Text); ep.empId = ewp.empId; var qry = from emp in ff.EmployeeWorkPackages where (emp.empId == ewp.empId && emp.wpId == Session["wpID"].ToString()) select emp; if (qry.ToArray().Length > 0) { lblError.Text = "Employee is already a part of the work package."; } else { var qry2 = from emp in ff.EmployeeProjects where (emp.projId == ep.projId && emp.empId == ep.empId) select emp; if (qry2.ToArray().Length == 0) ff.EmployeeProjects.InsertOnSubmit(ep); ff.EmployeeWorkPackages.InsertOnSubmit(ewp); ff.SubmitChanges(); updategvEmployees(); lblError.Text = ""; divAssignEmp.Visible = true; } } } else { if (e.CommandName == "btnAdd") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvUnassignedEmployees.Rows[row]; EmployeeWorkPackage ewp = new EmployeeWorkPackage(); EmployeeProject ep = new EmployeeProject(); ep.projId = Convert.ToInt32(Session["projID"]); ewp.projId = Convert.ToInt32(Session["projID"]); ewp.wpId = Session["wpID"].ToString(); ewp.empId = Convert.ToInt32(selectedRow.Cells[1].Text); ep.empId = ewp.empId; var qry = from emp in ff.EmployeeWorkPackages where (emp.empId == ewp.empId && emp.wpId == Session["wpID"].ToString()) select emp; if (qry.ToArray().Length > 0) { lblError.Text = "Employee is already a part of the work package."; divAssignEmp.Visible = true; } else { var qry2 = from emp in ff.EmployeeProjects where (emp.projId == ep.projId && emp.empId == ep.empId) select emp; if (qry2.ToArray().Length == 0) ff.EmployeeProjects.InsertOnSubmit(ep); ff.EmployeeWorkPackages.InsertOnSubmit(ewp); ff.SubmitChanges(); updategvEmployees(); lblError.Text = ""; } } } } catch (Exception exception) { //lblException.Text = exception.StackTrace; //lblError.Text = exception.StackTrace; } }
protected void populateManageProject() { try { ff.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues); if (Session["projID"] == null) Response.Redirect("~/PM/ProjectList.aspx"); if (Session["wpID"] != null) Session["wpID"] = null; if (divChangeAlloc.Visible == false) divOriginalAlloc.Visible = true; divChangeAlloc.Visible = false; lblProjID2.Text = Session["projID"].ToString(); //Get project name var proj = from p in ff.Projects where p.projId == Convert.ToInt32(Session["projID"]) select p; lblProjName2.Text = proj.First().projName; try { lblProjectManager2.Text = ff.Employees .Where(a => a.empId == proj.First().manager).First().firstName + " " + ff.Employees .Where(a => a.empId == proj.First().manager).First().lastName; } catch (Exception e) { lblProjectManager2.Text = ""; } if (proj.First().allocated_dollars == null) lblAlloc2.Text = "UNDEFINED"; else lblAlloc2.Text = proj.First().allocated_dollars.ToString(); if (proj.First().unallocated_dollars == null) lblUnalloc2.Text = "UNDEFINED"; else lblUnalloc2.Text = proj.First().unallocated_dollars.ToString(); getAllActiveWP(); getAllUnactiveWP(); identifyRole(); string[] name = lblProjectManager2.Text.Split(' '); var query = (from emp in ff.Employees where emp.firstName == name[0] && emp.lastName == name[1] select new { emp.empId }).First(); try { Roles.AddUserToRole(name[0].ToLower() + "_" + name[1].ToLower(), "ProjectManager"); } catch (Exception exception) { } try { EmployeeProject ep = new EmployeeProject(); ep.projId = Convert.ToInt32(lblProjID2.Text); ep.empId = query.empId; ff.EmployeeProjects.InsertOnSubmit(ep); ff.SubmitChanges(); } catch (Exception exception) { } } catch (Exception exception) { //lblException.Text = exception.StackTrace; } }
[TestMethod()] public void TestLoadAndSaveEmployeeProject() { ModelContext.beginTrans(); try { CsModelMappers.EmployeeProjectDBMapper pdb = new CsModelMappers.EmployeeProjectDBMapper(); long count = pdb.RecordCount(); if (pdb.SelectFromObjectName != pdb.ManagedTableName) { long countFromSelectObject = pdb.dbConn.getLngValue("select count(*) from " + pdb.SelectFromObjectName); Assert.AreEqual(count, countFromSelectObject, "Count of records in managedTableName {0} and SelectFromObjectName {1} should be equal, as there needs to be exactly 1 to 1 match between records in managed table and selectFromObject.", pdb.ManagedTableName, pdb.SelectFromObjectName); } if (count == 0) { Assert.Inconclusive("No EmployeeProject in database, table is empty"); } else { /** * using (DataContext ctx = DBUtils.Current().dbContext()) { * * var query = ctx.ExecuteQuery<EmployeeProject>(@"SELECT * FROM " + pdb.SelectFromObjectName ).Skip(1).Take(1); * var lst = query.ToList(); * * Assert.AreEqual(lst.Count, 1, "Expected to receive 1 record, got: " + lst.Count); * * } * todo: fix boolean fields by generating properties of original fields **/ object pid = ModelContext.CurrentDBUtils.getObjectValue("select top 1 " + pdb.pkFieldName + " from " + pdb.ManagedTableName); EmployeeProject p = pdb.findByKey(pid); EmployeeProject p2 = (EmployeeProject)p.copy(); //Test equality and hash codes Assert.AreEqual(p.GetHashCode(), p2.GetHashCode()); Assert.AreEqual(p, p2); p.isDirty = true; // force save pdb.save(p); // now reload object from database p = null; p = pdb.findByKey(pid); //test fields to be equal before and after save Assert.IsTrue(p.PrEmployeeProjectId == p2.PrEmployeeProjectId, "Expected Field EmployeeProjectId to be equal"); Assert.IsTrue(p.PrEPEmployeeId.GetValueOrDefault() == p2.PrEPEmployeeId.GetValueOrDefault(), "Expected Field EPEmployeeId to be equal"); Assert.IsTrue(p.PrEPProjectId.GetValueOrDefault() == p2.PrEPProjectId.GetValueOrDefault(), "Expected Field EPProjectId to be equal"); Assert.IsTrue(p.PrAssignDate.GetValueOrDefault() == p2.PrAssignDate.GetValueOrDefault(), "Expected Field AssignDate to be equal"); Assert.IsTrue(p.PrEndDate.GetValueOrDefault() == p2.PrEndDate.GetValueOrDefault(), "Expected Field EndDate to be equal"); Assert.IsTrue(p.PrRate.GetValueOrDefault() == p2.PrRate.GetValueOrDefault(), "Expected Field Rate to be equal"); p.isDirty = true; //to force save ModelContext.Current.saveModelObject(p); p = ModelContext.Current.loadModelObject <EmployeeProject>(p.Id); p.loadObjectHierarchy(); string json = JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); System.IO.FileInfo jf = new System.IO.FileInfo(".\\EmployeeProject.json"); System.IO.File.WriteAllText(jf.FullName, json); if (pdb.isPrimaryKeyAutogenerated) { p.isNew = true; p.isDirty = true; try { pdb.save(p); } catch (System.Exception e) { Assert.IsTrue(e.Message.ToUpper().Contains("UNIQUE INDEX") || e.Message.Contains("Violation of UNIQUE KEY constraint"), "Insert statement produced error other than violation of unique key:" + e.Message); } } } } finally { ModelContext.rollbackTrans(); // 'Nothing should be saved to the database! } }
public static EmployeeProject loadFromDataRow(DataRow r) { DataRowLoader a = new DataRowLoader(); IModelObject mo = new EmployeeProject(); a.DataSource = r; a.load(mo); return (EmployeeProject)mo; }
public void testVBNetCreateRecords() { ModelContext.Current.config.DoCascadeDeletes = true; ModelContext.beginTrans(); ModelContext.Current.addGlobalModelValidator(typeof(Employee), typeof(CsharpEmployeeValidator)); DateTime hireDate = new DateTime(DateTime.Now.Year + 10, 1, 1); try { EmployeeRank er = EmployeeRankFactory.Create(); er.PrRank = "My New Rank"; Employee employee = EmployeeFactory.Create(); NUnit.Framework.Assert.IsTrue(employee is IAuditable, "Empoyee must implement IAuditable"); employee.PrRank = er; employee.PrEmployeeName = "test employee"; employee.PrSalary = 100m; employee.PrSSINumber = "1030045"; employee.PrTelephone = "2234455"; employee.PrHireDate = hireDate; employee.PrIsActive = true; Guid g = Guid.NewGuid(); employee.PrSampleGuidField = g; employee.PrEmployeeProjectAdd(EmployeeProjectFactory.Create()); EmployeeProject emplProj = employee.PrEmployeeProjectGetAt(0); emplProj.PrAssignDate = new DateTime(DateTime.Now.Year + 10, 3, 1); emplProj.PrEndDate = new DateTime(DateTime.Now.Year + 10, 6, 1); emplProj.PrEPProjectId = 1; emplProj.PrProject = ProjectFactory.Create(); emplProj.PrProject.PrProjectName = "MyProject"; NUnit.Framework.Assert.IsTrue(employee.isNew); NUnit.Framework.Assert.IsTrue(employee.isDirty); NUnit.Framework.Assert.IsTrue(employee.NeedsSave); // 3 ways to persist to database // method 1: use ModelContext.Current().save NUnit.Framework.Assert.IsTrue(employee.CreateDate == null, "Before save, created date is null"); NUnit.Framework.Assert.IsTrue(employee.UpdateDate == null, "Before save, UpdateDate is not null"); ModelContext.Current.saveModelObject(employee); NUnit.Framework.Assert.IsTrue(employee.PrSSINumber == "12345XX", "12345XX value in PrSSINumber is Proof that validator was called"); NUnit.Framework.Assert.IsTrue(employee.CreateDate != null, "Before save, created date is not null"); NUnit.Framework.Assert.IsTrue(employee.UpdateDate != null, "Before save, UpdateDate is not null"); NUnit.Framework.Assert.IsTrue(employee.CreateUser != null, "Before save, CreateUser date is not null"); NUnit.Framework.Assert.IsTrue(employee.UpdateUser != null, "Before save, UpdateUser is not null"); NUnit.Framework.Assert.IsTrue(employee.UpdateDate.GetValueOrDefault().ToString("dd/MM/yyyy") == employee.CreateDate.GetValueOrDefault().ToString("dd/MM/yyyy"), "update date = create date after saving new"); NUnit.Framework.Assert.IsTrue(employee.UpdateUser == employee.CreateUser, "update date = create date after saving new"); long x = (long)employee.Id; NUnit.Framework.Assert.IsFalse(employee.isNew, "After save, model object isNew property must return false"); NUnit.Framework.Assert.IsFalse(employee.isDirty, "After save to db, model object isDirty property must return false"); employee = EmployeeDataUtils.findByKey(x); NUnit.Framework.Assert.IsNotNull(employee, "New employee not found"); NUnit.Framework.Assert.IsFalse(employee.isNew, "After load from db, model object isNew property returns false"); NUnit.Framework.Assert.IsFalse(employee.isDirty, "After load from db, model object isDirty property returns false"); NUnit.Framework.Assert.AreEqual(employee.PrSampleGuidField, g); NUnit.Framework.Assert.AreEqual(employee.PrRank.PrRank, "My New Rank"); NUnit.Framework.Assert.AreEqual(employee.PrSalary, 100m); NUnit.Framework.Assert.AreEqual(employee.PrEmployeeName, "test employee"); NUnit.Framework.Assert.AreEqual(employee.PrSSINumber, "12345XX"); NUnit.Framework.Assert.AreEqual(employee.PrHireDate, hireDate); NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjects.ToList().Count, 1); NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject"); //change some values on child and parent objects employee.PrEmployeeProjectGetAt(0).PrEndDate = new DateTime(DateTime.Now.Year + 10, 6, 1); employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName = "MyProject Updated"; // here we are updating parent record of child object of employee! NUnit.Framework.Assert.IsTrue(employee.NeedsSave, "After changing parent or child obejcts values, e.NeedsSave must be true"); NUnit.Framework.Assert.IsFalse(employee.isDirty, "After changing parent or child obejcts values, e.isDirty must be false since we did not change anything on the Model Object"); // method 2: call [ModelObject]DataUtils.save EmployeeDataUtils.saveEmployee(employee); var lst = EmployeeDataUtils.findList("hiredate between ? and ?", new DateTime(DateTime.Now.Year + 10, 1, 1), new DateTime(DateTime.Now.Year + 10, 12, 1)); NUnit.Framework.Assert.AreEqual(1, lst.Count); employee = EmployeeDataUtils.findByKey(x); //NUnit.Framework.Assert.IsTrue(e.UpdateDate > e.CreateDate, "after update of record, update must be date > create date "); // note that above test cannot be sucess since save is happening too fast NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrEndDate, new DateTime(DateTime.Now.Year + 10, 6, 1)); NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject Updated", "Expected to have parent record of child updated!"); employee.PrSSINumber = "XXXXX"; employee.PrEmployeeInfo = EmployeeInfoFactory.Create(); employee.PrEmployeeInfo.PrAddress = "2 nikoy thefanous street"; employee.PrEmployeeInfo.PrSalary = 3000; NUnit.Framework.Assert.IsTrue(employee.NeedsSave, "After changing value, e.NeedsSave must be true"); NUnit.Framework.Assert.IsTrue(employee.isDirty, "After changing value e.isDirty must be true"); // method 3: call [ModelObject]dbMapper.save new EmployeeDBMapper().save(employee); employee = EmployeeDataUtils.findByKey(x); NUnit.Framework.Assert.AreEqual(employee.PrSSINumber, "XXXXX"); NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrEndDate, new DateTime(DateTime.Now.Year + 10, 6, 1)); NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject Updated", "Expected to have parent record of child updated!"); employee.PrEmployeeProjectsClear(); NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjects.ToList().Count, 0, "Expected to have no Projects linked after call to clear"); EmployeeDataUtils.saveEmployee(employee); employee = EmployeeDataUtils.findByKey(x); NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjects.ToList().Count, 0, "Expected to have no Projects linked, after reloading from db"); List <Employee> empls = EmployeeDataUtils.findList("EmployeeName={0} and Salary between {1} and {2} and HireDate={3}", "test employee", 0, 100, hireDate); NUnit.Framework.Assert.IsTrue(empls.Count > 0, "Employee Count not the expected!"); EmployeeDataUtils.deleteEmployee(employee); employee = EmployeeDataUtils.findByKey(x); NUnit.Framework.Assert.IsNull(employee, "New employee must have been deleted!"); // now let's test string primary key EmployeeType et = EmployeeTypeFactory.Create(); et.PrEmployeeType = "A Description"; et.PrEmployeeTypeCode = "XX"; EmployeeType et1 = EmployeeTypeFactory.Create(); et1.PrEmployeeType = "A Description 1"; et1.PrEmployeeTypeCode = "XX1"; EmployeeType et2 = EmployeeTypeFactory.Create(); et2.PrEmployeeType = "A Description 2"; et2.PrEmployeeTypeCode = "XX2"; EmployeeTypeDataUtils.saveEmployeeType(et, et1, et2); et2 = EmployeeTypeDataUtils.findByKey("XX2"); NUnit.Framework.Assert.IsNotNull(et2, "New employeetype must have been created!"); et1 = EmployeeTypeDataUtils.findByKey("XX1"); NUnit.Framework.Assert.IsNotNull(et1, "New employeetype must have been created!"); Project p = ProjectFactory.Create(); p.PrIsActive = true; p.PrProjectTypeId = ModelLibVBGenCode.EnumProjectType.EXTERNAL; p.PrProjectName = "Test"; ProjectDataUtils.saveProject(p); long pid = p.PrProjectId; p = ProjectDataUtils.findByKey(pid); NUnit.Framework.Assert.IsNotNull(p, "New project must have been saved to the db!"); NUnit.Framework.Assert.AreEqual(p.PrProjectTypeId, ModelLibVBGenCode.EnumProjectType.EXTERNAL); p.PrProjectTypeId = null; // test null value to enumaration ProjectDataUtils.saveProject(p); p = ProjectDataUtils.findByKey(pid); NUnit.Framework.Assert.IsNotNull(p, "New project must have been saved to the db!"); NUnit.Framework.Assert.IsNull(p.PrProjectTypeId, "project type id must be null after saved to the db, instead got value:" + p.PrProjectTypeId); List <Employee> elst = EmployeeDataUtils.findList(); EmployeeEvaluation ep = EmployeeEvaluationFactory.Create(); ep.PrEmployeeId = elst[0].PrEmployeeId; ep.PrEvaluatorId = elst[1].PrEmployeeId; ep.PrEvaluationDate = hireDate; EmployeeEvaluationDataUtils.saveEmployeeEvaluation(ep); // insert NUnit.Framework.Assert.IsTrue(ep.PrEmployeeEvaluationId > 0); long eid = ep.PrEmployeeEvaluationId; EmployeeEvaluation ep2 = EmployeeEvaluationDataUtils.findByKey(eid); NUnit.Framework.Assert.IsNotNull(ep2); NUnit.Framework.Assert.AreEqual(ep, ep2); ep2.PrEvaluationDate = new DateTime(hireDate.Year, hireDate.Month + 1, 1); EmployeeEvaluationDataUtils.saveEmployeeEvaluation(ep2); // update EmployeeEvaluationDataUtils.deleteEmployeeEvaluation(ep2); //delete ep2 = EmployeeEvaluationDataUtils.findByKey(eid); NUnit.Framework.Assert.IsNull(ep2); Bank alphaBank = BankDataUtils.findOne("bankcode='09'"); if (alphaBank == null) { alphaBank = BankFactory.Create(); alphaBank.PrBankCode = "09"; alphaBank.PrBankName = "ALPHA Bank"; BankDataUtils.saveBank(alphaBank); } Account pa = AccountDataUtils.findOne("Account='ALPHA'"); if ((pa == null)) { pa = AccountFactory.Create(); pa.PrAccount = "ALPHA"; pa.PrDescription = "ALPHA TEST"; pa.PrAccountTypeid = 1; pa.PrBankaccnumber = "000000000004"; pa.PrBankAccountInfo = AccountBankInfoFactory.Create(); pa.PrBankAccountInfo.PrBankId = alphaBank.PrBANKID; pa.PrBankAccountInfo.PrCompanyName = "UNIT TESTS LTD"; pa.PrBankAccountInfo.PrCompanyBankCode = "111"; AccountDataUtils.saveAccount(pa); } } finally { ModelContext.rollbackTrans(); } }
public static void saveEmployeeProject(DataRow dr, ref EmployeeProject mo) { if (mo == null) { mo = new EmployeeProject(); } foreach (DataColumn dc in dr.Table.Columns) { mo.setAttribute(dc.ColumnName, dr[dc.ColumnName]); } saveEmployeeProject(mo); }
public void testVBNetSerializationAndDeserialization() { ModelContext.beginTrans(); try { DateTime hireDate = new DateTime(DateTime.Now.Year, 1, 1); Employee employee = EmployeeFactory.Create(); employee.PrEmployeeName = "test employee"; employee.PrSalary = 100m; employee.PrSSINumber = "1030045"; employee.PrTelephone = "2234455"; employee.PrHireDate = hireDate; employee.PrIsActive = true; employee.PrEmployeeInfo = EmployeeInfoFactory.Create(); employee.PrEmployeeInfo.PrAddress = "some address"; employee.PrEmployeeInfo.PrSalary = 300.0M; // test parent object employee.PrRank = EmployeeRankFactory.Create(); employee.PrRank.PrRank = "Test me"; employee.PrEmployeeProjectAdd(EmployeeProjectFactory.Create()); EmployeeProject emplProj = employee.PrEmployeeProjectGetAt(0); emplProj.PrAssignDate = new DateTime(DateTime.Now.Year, 3, 1); emplProj.PrEndDate = new DateTime(DateTime.Now.Year, 6, 1); emplProj.PrEPProjectId = 1; emplProj.PrProject = ProjectFactory.Create(); emplProj.PrProject.PrProjectName = "MyProject 1"; employee.PrEmployeeProjectAdd(EmployeeProjectFactory.Create()); EmployeeProject emplProj2 = employee.PrEmployeeProjectGetAt(1); emplProj2.PrAssignDate = new DateTime(DateTime.Now.Year, 3, 1); emplProj2.PrEndDate = new DateTime(DateTime.Now.Year, 6, 1); emplProj2.PrEPProjectId = 2; emplProj2.PrProject = ProjectFactory.Create(); emplProj2.PrProject.PrProjectName = "MyProject 2"; string output = JsonConvert.SerializeObject(employee); //JavaScriptSerializer jss = new JavaScriptSerializer(); //object d = jss.Deserialize<object>(output); Employee employee2 = JsonConvert.DeserializeObject <Employee>(output); NUnit.Framework.Assert.AreEqual(2, employee2.PrEmployeeProjects.ToList().Count, "Expected 2 projects after desirialize"); NUnit.Framework.Assert.IsTrue(employee2.PrEmployeeInfo != null, "Expected employee info not null after desirialize"); NUnit.Framework.Assert.IsTrue(employee2.PrRank != null, "Expected employee Rank not null after desirialize"); EmployeeDataUtils.saveEmployee(employee2); long x = (long)employee2.Id; employee2 = EmployeeDataUtils.findByKey(x); NUnit.Framework.Assert.IsNotNull(employee2); NUnit.Framework.Assert.AreEqual(2, employee2.PrEmployeeProjects.ToList().Count, "Expected 2 projects after save"); NUnit.Framework.Assert.IsTrue(employee2.PrRank != null, "Expected employee Rank not null after save"); NUnit.Framework.Assert.IsTrue(employee2.PrEmployeeInfo != null, "Expected employee info not null after save"); } finally { ModelContext.rollbackTrans(); } }
public void Add(EmployeeProject model) { _dbContext.EmployeeProject.Add(model); }
public void Update(EmployeeProject entity) { _entities.Update(entity); }
/// <summary> /// Lukas Schütz Created /// </summary> /// <param name="employeeProject"></param> public void Update(EmployeeProject employeeProject) { _dbContext.EmployeeProject.Update(employeeProject); }
public void RemoveFlg(EmployeeProject entity) { entity.DeleteFlag = StatusDelete.DELETED; _entities.Update(entity); }
public void Delete(EmployeeProject model) { _dbContext.EmployeeProject.Remove(model); }
private void detach_EmployeeProjects(EmployeeProject entity) { this.SendPropertyChanging(); entity.Project = null; }
protected void gvUnassignedEmployees_RowCommand(object sender, GridViewCommandEventArgs e) { lblBudgetError.Text = ""; try { if (parentWpID == null) { if (e.CommandName == "btnAdd") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvUnassignedEmployees.Rows[row]; EmployeeWorkPackage ewp = new EmployeeWorkPackage(); EmployeeProject ep = new EmployeeProject(); ep.projId = Convert.ToInt32(Session["projID"]); ewp.projId = Convert.ToInt32(Session["projID"]); ewp.wpId = Session["wpID"].ToString(); ewp.empId = Convert.ToInt32(selectedRow.Cells[1].Text); ep.empId = ewp.empId; var qry = from emp in ff.EmployeeWorkPackages where (emp.empId == ewp.empId && emp.wpId == Session["wpID"].ToString()) select emp; if (qry.ToArray().Length > 0) { lblError.Text = "Employee is already a part of the work package."; } else { var qry2 = from emp in ff.EmployeeProjects where (emp.projId == ep.projId && emp.empId == ep.empId) select emp; if (qry2.ToArray().Length == 0) { ff.EmployeeProjects.InsertOnSubmit(ep); } ff.EmployeeWorkPackages.InsertOnSubmit(ewp); ff.SubmitChanges(); updategvEmployees(); lblError.Text = ""; divAssignEmp.Visible = true; } } } else { if (e.CommandName == "btnAdd") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvUnassignedEmployees.Rows[row]; EmployeeWorkPackage ewp = new EmployeeWorkPackage(); EmployeeProject ep = new EmployeeProject(); ep.projId = Convert.ToInt32(Session["projID"]); ewp.projId = Convert.ToInt32(Session["projID"]); ewp.wpId = Session["wpID"].ToString(); ewp.empId = Convert.ToInt32(selectedRow.Cells[1].Text); ep.empId = ewp.empId; var qry = from emp in ff.EmployeeWorkPackages where (emp.empId == ewp.empId && emp.wpId == Session["wpID"].ToString()) select emp; if (qry.ToArray().Length > 0) { lblError.Text = "Employee is already a part of the work package."; divAssignEmp.Visible = true; } else { var qry2 = from emp in ff.EmployeeProjects where (emp.projId == ep.projId && emp.empId == ep.empId) select emp; if (qry2.ToArray().Length == 0) { ff.EmployeeProjects.InsertOnSubmit(ep); } ff.EmployeeWorkPackages.InsertOnSubmit(ewp); ff.SubmitChanges(); updategvEmployees(); lblError.Text = ""; } } } } catch (Exception exception) { //lblException.Text = exception.StackTrace; //lblError.Text = exception.StackTrace; } }
partial void UpdateEmployeeProject(EmployeeProject instance);
public void CreateEmployeeProject(EmployeeProject employee) { hitss.EP.Add(employee); hitss.SaveChanges(); }
public void CreateNewEmployeeProjectObject() { EmployeeProject employeeProject = new EmployeeProject(); Assert.IsInstanceOfType(employeeProject, typeof(EmployeeProject)); }
protected void populateManageProject() { try { ff.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues); if (Session["projID"] == null) { Response.Redirect("~/PM/ProjectList.aspx"); } if (Session["wpID"] != null) { Session["wpID"] = null; } if (divChangeAlloc.Visible == false) { divOriginalAlloc.Visible = true; } divChangeAlloc.Visible = false; lblProjID2.Text = Session["projID"].ToString(); //Get project name var proj = from p in ff.Projects where p.projId == Convert.ToInt32(Session["projID"]) select p; lblProjName2.Text = proj.First().projName; try { lblProjectManager2.Text = ff.Employees .Where(a => a.empId == proj.First().manager).First().firstName + " " + ff.Employees .Where(a => a.empId == proj.First().manager).First().lastName; } catch (Exception e) { lblProjectManager2.Text = ""; } if (proj.First().allocated_dollars == null) { lblAlloc2.Text = "UNDEFINED"; } else { lblAlloc2.Text = proj.First().allocated_dollars.ToString(); } if (proj.First().unallocated_dollars == null) { lblUnalloc2.Text = "UNDEFINED"; } else { lblUnalloc2.Text = proj.First().unallocated_dollars.ToString(); } getAllActiveWP(); getAllUnactiveWP(); identifyRole(); string[] name = lblProjectManager2.Text.Split(' '); var query = (from emp in ff.Employees where emp.firstName == name[0] && emp.lastName == name[1] select new { emp.empId }).First(); try { Roles.AddUserToRole(name[0].ToLower() + "_" + name[1].ToLower(), "ProjectManager"); } catch (Exception exception) { } try { EmployeeProject ep = new EmployeeProject(); ep.projId = Convert.ToInt32(lblProjID2.Text); ep.empId = query.empId; ff.EmployeeProjects.InsertOnSubmit(ep); ff.SubmitChanges(); } catch (Exception exception) { } } catch (Exception exception) { //lblException.Text = exception.StackTrace; } }