public async Task<IHttpActionResult> PutDepartment(int id, Department department) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != department.DepartmentID) { return BadRequest(); } db.Entry(department).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public Department Create(Department department) { if(department == null) throw new ArgumentNullException(nameof(department)); if(department.CompanyId < 1) throw new ValidationException("Missing companyId"); if (string.IsNullOrEmpty(department.DepartmentName)) throw new ValidationException("Department name too long."); var existing = GetByCompany(department.CompanyId) .FirstOrDefault(d => d.DepartmentName == department.DepartmentName); if(existing != null) throw new ValidationException("Department with same name already exists."); var result = new Department { DepartmentName = department.DepartmentName, CompanyId = department.CompanyId }; _context.Departments.Add(result); _context.SaveChanges(); return result; }
public List<Department> getDepartments() { List<Department> _Departments = new List<Department>(); Query = "SELECT department.id, department.name " + "FROM department ORDER BY department.name"; try { Data.SqlCommand cm = new Data.SqlCommand(); cm.CommandText = Query; cm.Connection = cn; Data.SqlDataReader rd = cm.ExecuteReader(); while (rd.Read()) { Department _Department = new Department(); _Department.Id = rd.GetInt16(0); _Department.Name = rd.GetString(1); _Departments.Add(_Department); } rd.Close(); cm = null; } catch (Exception) { throw; } return (_Departments); }
public Manager(string firstName, string lastName, int id, decimal salary, Department department, params Employee[] employees) : base(firstName, lastName, id, salary, department) { List<Employee> input=new List<Employee>(); input.AddRange(employees); this.employeesUnderCommand =input; }
protected Employee(string id, string firstName, string lastName , decimal salary, Department department) : base(id, firstName, lastName) { this.Salary = salary; this.Department = department; }
public Department getDepartment(int UserId) { Department _Department = new Department(); Query = "SELECT department.id, department.name " + "FROM department INNER JOIN [User] ON [User].departmentid = department.id " + "WHERE User.Id = " + UserId + " ORDER BY department.name"; try { Data.SqlCommand cm = new Data.SqlCommand(); cm.CommandText = Query; cm.Connection = cn; Data.SqlDataReader rd = cm.ExecuteReader(); rd.Read(); if(rd.HasRows) { _Department.Id = rd.GetInt16(0); _Department.Name = rd.GetString(1); } rd.Close(); cm = null; } catch (Exception) { throw; } return (_Department); }
private void loadInfoPreview() { AB = new AccountBusiness(); account = AB.GetAccount(Page.User.Identity.Name); EB = new EmployeeBusiness(); employee = EB.GetEmployee(account.Employee_Id); DB = new DepartmentBusiness(); department = DB.GetDepartment(employee.Department_Id); imgAvatar.ImageUrl = WebHelper.Instance.GetImageURL(employee.Employee_Avatar, 128, 128, false); imgAvatar.PostBackUrl = WebHelper.Instance.GetURL() + "Account"; lblUserName.Text = account.Account_UserName; lblRole.Text = account.Role_Name; lblFirstName.Text = employee.Employee_FirtName; lblLastName.Text = employee.Employee_LastName; lblEmail.Text = employee.Employee_Email; lblAddress.Text = employee.Employee_Address; lblPhoneNumber.Text = employee.Employee_PhoneNumber; if (employee.Employee_DateOfBirth.ToShortDateString().Equals("1/1/1900")) lblDOB.Text = ""; else lblDOB.Text = employee.Employee_DateOfBirth.ToShortDateString(); if (employee.Employee_Gender) lblGender.Text = "Male"; else lblGender.Text = "Female"; hplnkModifyProfile.NavigateUrl = WebHelper.Instance.GetURL() + "Account"; lblDepartmentName.Text = department.Department_Name; lblDescription.Text = department.Department_Description; }
/// <summary> /// 부서-소속원 정보 (<see cref="DepartmentMember"/>)를 검색하기 위한 Criteria를 빌드합니다. /// </summary> public QueryOver<DepartmentMember, DepartmentMember> BuildQueryOverOfDepartmentMember( Department department, User user, EmployeeTitle employeeTitle, bool? isLeader, bool? isActive) { if(IsDebugEnabled) log.Debug(@"부서-소속원 정보 (DepartmentMember)를 검색하기 위한 Criteria를 빌드합니다... " + @"department={0}, user={1}, employeeTitle={2}, isLeader={3}, isActive={4}", department, user, employeeTitle, isLeader, isActive); var query = QueryOver.Of<DepartmentMember>(); if(department != null) query.AddWhere(dm => dm.Department == department); if(user != null) query.AddWhere(dm => dm.User == user); if(employeeTitle != null) query.AddWhere(dm => dm.EmployeeTitle == employeeTitle); if(isLeader.HasValue) query.AddWhere(dm => dm.IsLeader == isLeader); if(isActive.HasValue) query.AddNullAsTrue(dm => dm.IsActive, isActive); return query; }
public NHibernatePerformanceTests() { using (ISession db = NHibernateHelper.OpenSession()) { // delete any records from previous run var deptQuery = (from dept in db.Query<Department>() select dept).ToList(); using (db.BeginTransaction()) { foreach (var item in deptQuery) { db.Delete(item); } db.Transaction.Commit(); } var personQuery = (from pers in db.Query<Person>() select pers).ToList(); using (db.BeginTransaction()) { foreach (var item in personQuery) { db.Delete(item); } db.Transaction.Commit(); } Department myDepartment = new Department() { name = "Operations" }; db.Save(myDepartment); } }
public void DepartmentCreate() { Department instance1 = new Department(); Assert.IsNotNull(instance1, "DepartmentTest.DepartmentNew: Unable to create instance using new()"); Department instance2 = DepartmentService.Create(); Assert.IsNotNull(instance2, "DepartmentTest.DepartmentCreate: Unable to create instance"); }
public WorkersViewModel(Department Department) { base.Name = "ПЕРСОНАЛ"; }
public Manager(int id, string firstName, string lastName, double salary, Department department, params Employee[] employees) : base(id, firstName, lastName, salary, department) { this.set = new HashSet<Employee>(); this.AddEmployees(employees); }
protected void btnSave_Click(object sender, EventArgs e) { //connect using (DefaultConnectionEF conn = new DefaultConnectionEF()) { //instantiate a new deparment object in memory Department d = new Department(); //decide if updating or adding, then save if (Request.QueryString.Count > 0) { Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); d = (from dep in conn.Departments where dep.DepartmentID == DepartmentID select dep).FirstOrDefault(); } //fill the properties of our object from the form inputs d.Name = txtName.Text; d.Budget = Convert.ToDecimal(txtBudget.Text); if (Request.QueryString.Count == 0) { conn.Departments.Add(d); } conn.SaveChanges(); //redirect to updated departments page Response.Redirect("departments.aspx"); } }
protected Employee(int id, string firstName, string lastName, Department department, decimal salary) : base(id, firstName, lastName) { this.Department = department; this.salary = salary; }
public void AddDepartment(Department department) { TreeViewItem tvi = new TreeViewItem(); TextBlock nameBlock = new TextBlock(); nameBlock.VerticalAlignment = VerticalAlignment.Center; nameBlock.Text = department.Name; tvi.Header = new StackPanel { Height = 22.0, Orientation = Orientation.Horizontal, Children = { nameBlock } }; tvi.DataContext = department; if (this.departmentNode.ContainsKey(department.Pid)) { this.departmentNode[department.Pid].Items.Add(tvi); } else { this.WorkName.Items.Add(tvi); } if (!this.departmentNode.ContainsKey(department.Id)) { this.departmentNode.Add(department.Id, tvi); } }
static void PullUpDepartment(Department dep) { // Locate department one level up var depAbove = dep. Query. Ancestors<Department>(). First(); // // Disconnect original department // In fact, remove the member; cf. ".Parent". // dep.Untyped.Parent.Remove(); // // Move employees one department up. // Note: the manager does not move. // foreach (var m in dep.Member.ToList()) { m.Untyped.Remove(); depAbove.Member.Add(m); } }
public object CreateDepartment(string DPName, string ParentId) { IDbTransaction tran = Utility.Database.BeginDbTransaction(); try { lock (forlock) { string NEW_DPID = Utility.MaxValue<Department>("D", 6, tran); Department insert_obj = new Department(); insert_obj.DPID = NEW_DPID;//主键 insert_obj.DPName = DPName;//文件名称 insert_obj.PDPID = ParentId;//父类ID Utility.Database.Insert<Department>(insert_obj, tran); Utility.Database.Commit(tran); return new { insert_obj = insert_obj }; } } catch (Exception e) { Utility.Database.Rollback(tran); return PackResult.JsonMsg(false, "CreateDepartment失败!" + e.Message); } }
public void TestEntityEquals_IdEquals() { _department = new Department( "A" ); _department2 = new Department( "A" ); Assert.IsTrue( _department.Equals( _department2 ) ); Assert.IsTrue( _department == _department2 ); Assert.IsFalse( _department != _department2 ); }
public DepartmentPoint(int coord, Department dep) { Coord = coord; Owner = null; GrowableCoords = new List<int>(4); Department = dep; }
public void TestShortcutCreate() { string storeName = "TestShortcutCreate" + DateTime.Now.Ticks; string aliceId; using (var context = CreateEntityContext(storeName)) { var sales = new Department(context) { Name = "Sales", DeptId = 1 }; var bob = new Person(context) { Name = "Bob" }; var alice = new Person(context) { Name = "Alice", Age = 54, Department = sales, Friends = new Collection<IPerson> { bob } }; context.SaveChanges(); aliceId = alice.Id; } using (var context = CreateEntityContext(storeName)) { var alice = context.Persons.FirstOrDefault(x => x.Id == aliceId); Assert.IsNotNull(alice); Assert.AreEqual("Alice", alice.Name); Assert.AreEqual(54, alice.Age); Assert.IsNotNull(alice.Department); Assert.AreEqual("Sales", alice.Department.Name); Assert.AreEqual(1, alice.Friends.Count); Assert.AreEqual("Bob", alice.Friends.First().Name); } }
public static IList<Department> GetDepartments() { IList<Department> departments = new List<Department>(); using (ManagementEntity context = new ManagementEntity()) { try { var listOfDepartments = (from d in context.Departments select d); if (listOfDepartments != null) { foreach (var item in listOfDepartments) { Department department = new Department(); department.ID = item.Id; department.Address = item.Addresse; department.Name = item.Name; department.PhoneNumber = item.Phone; departments.Add(department); } } } catch (InvalidOperationException ex) { throw ex; } } return departments; }
protected void btnSave_Click(object sender, EventArgs e) { //connect using (DefaultConnection db = new DefaultConnection()) { //create new department in memory Department dep = new Department(); //check url if(!String.IsNullOrEmpty(Request.QueryString["DepartmentID"])) { Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]); dep = (from d in db.Departments where d.DepartmentID == DepartmentID select d).FirstOrDefault(); } //fill new properties of the new department dep.Name = txtName.Text; dep.Budget = Convert.ToDecimal(txtBudget.Text); //save the new department if(String.IsNullOrEmpty(Request.QueryString["DepartmentID"])) { db.Departments.Add(dep); } db.Departments.Add(dep); db.SaveChanges(); //redirect to department list page Response.Redirect("departments.aspx"); } }
public List<Department> GetAllDepartments() { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM Departments"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List<Department> departments = new List<Department>(); while (reader.Read()) { Department department = new Department(); department.DepartmentID = (int)reader["DepartmentID"]; department.Code = reader["Code"].ToString(); department.Name = reader["Name"].ToString(); departments.Add(department); } reader.Close(); connection.Close(); return departments; }
public static bool SaveDepartmentForm(DepartmentManagerFormModel model) { bool success = false; spiffaiwebEntities db = LoadDB(); try { var department = new Department(); department.DepartmentName = model.DepartmentName; department.DepartmentEmail = model.DepartmentEmail; department.IsDelete = model.IsActive; if (model.DepartmentId > 0) { //Edit department.DepartmentId = model.DepartmentId; db.Entry(department).State = EntityState.Modified; db.SaveChanges(); success = true; } else { //Create db.Departments.Add(department); db.SaveChanges(); success = true; } } catch (Exception) { throw; } return success; }
public Employee(string firstName, string lastName, int id, decimal salary, Department department) : base(firstName, lastName, id) { this.Salary = salary; this.Department = department; }
public override void Seed() { if (this.CompanyDbContext.Departments.Any()) { return; } var uniqueDepartmentNames = RandomDataGenerator.Instance.GetUniqueStringsCollection(MinNameLength, MaxNameLength, this.SeedDataCount); for (int i = 0; i < this.SeedDataCount; i++) { var department = new Department() { Name = uniqueDepartmentNames[i] }; this.CompanyDbContext.Departments.Add(department); if (i % 100 == 0) { this.CompanyDbContext.SaveChanges(); } } this.CompanyDbContext.SaveChanges(); }
protected void ButtonAddDepartment_Click(object sender, EventArgs e) { Page.Validate("wholePage"); //Bypass the add employee validators RequiredFieldValidatorEmail.IsValid = true; RequiredFieldValidatorName.IsValid = true; RequiredFieldValidatorPhoneNumber.IsValid = true; RequiredFieldValidatorPasscode.IsValid = true; if (Page.IsValid) { //create a temporary department Department current = new Department(); //set the name to the current department entry from the textbox current.Name = TextBoxDepartment.Text; //add the department entry into the database database.Departments.AddObject(current); //save changes made to the database and update the drop down list with the departments database.SaveChanges(); UpdateDepartments(); //clear the department textbox TextBoxDepartment.Text = null; } }
//添加 protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { if (this.txtDepartmentName.Text == "") { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('部门不能为空');</script>"); return; } Department dep = new Department(); dep.DepartmentId = Guid.NewGuid().ToString(); dep.DepartmentName = this.txtDepartmentName.Text; dep.Account = AccountsManager.GetAccountByAccountId(oepr.Account.AccountId); dep.IsDefault = false; dep.AddDate = DateTime.Now.ToString(); bool b = DepartmentManager.AddDepartment(dep); if (b) { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('添加成功'); window.location='DepartmentManager.aspx';</script>"); return; } else { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('已经存在此部门');</script>"); return; } }
static void Main(string[] args) { //Declare the object variables Employee employee = null; Employees employees = new Employees(); Department department = new Department("IT", "Information Technology"); //Add employee Larry Wilson employee = new Employee("43109", "Larry", "Robert", "Wilson", "Manager", GenderType.Male, MaritalStatusType.Married, new DateTime(1954, 6, 11), new DateTime(1996, 4, 11), "(213) 335-2226", "(310) 456-1234", 11000, department); employees.Add(employee); //Add employee John Brown //Add employee Lizzy Jones //Loop and display each Employee's information foreach (Employee emp in employees) { Console.WriteLine(emp.ToString()); } Console.ReadLine(); }
public static EmployeeViewModel ConvertToViewModel(this Employee employee, Department department, Employee manager, Salary salary, Title title) { var employeeViewModel = new EmployeeViewModel { BirthDate = employee.BirthDate.Value.ToShortDateString(), CurrentManager = string.Empty, Id = employee.PersistenceId.ToString(), FirstName = employee.FirstName, Gender = employee.Gender.DisplayName, HireDate = employee.HireDate.Value.ToShortDateString(), LastName = employee.LastName, }; if (manager != null) { employeeViewModel.CurrentManager = manager.FirstName + " " + manager.LastName; } if (department != null) { employeeViewModel.CurrentDepartment = department.Name; } if (salary != null) { employeeViewModel.CurrentSalary = salary.Amount.ToString(); } if (title != null) { employeeViewModel.CurrentTitle = title.Name; } return employeeViewModel; }
public async Task <bool> Delete(Department entity) { _db.Departments.Remove(entity); return(await Save()); }
public async Task <bool> Update(Department entity) { _db.Departments.Update(entity); return(await Save()); }