/// <summary> /// 部门信息维护 /// </summary> /// <param name="source"></param> /// <returns></returns> public DepartmentDto AddOrUpdateDepartment(DepartmentDto source) { var isAddNew = string.IsNullOrEmpty(source.Id); if (isAddNew) { source.Id = Guid.NewGuid().ToString(); var entity = Mapper.Map <DepartmentDto, Department>(source); _dbContext.Set <Department>().Add(entity); } else { var target = _dbContext.Set <Department>().Where(s => s.Id == source.Id).FirstOrDefault(); if (target == null) { CommonFunc.ThrowExceptionIfRecordNotExists(EntityNames.Dept, source.Id, OperateType.Update, _logger); } else if (!Enumerable.SequenceEqual(source.Version, target.Version)) { var modifiedUser = GetEmployeeDetail(target.LastUpdateUserId); CommonFunc.ThrowExceptionIfRecordHasBeenModified(EntityNames.Dept, source.Id, modifiedUser.EmName, target.LastUpdateTime, OperateType.Update, _logger); } Mapper.Map(source, target); } _dbContext.SaveChanges(); return(GetDepartmentDetail(source.Id)); }
public ResultHelper AddDepartment(DepartmentDto departmentDto) { try { if (IsThere(departmentDto)) { return(new ResultHelper(false, departmentDto.DepartmentID, ResultHelper.IsThereItem)); } department item = new department(); item.DepartmentID = departmentDto.DepartmentID; item.Description = departmentDto.Description; item.Other = departmentDto.Other; item.SubUnitID = departmentDto.SubUnitID; item.Name = departmentDto.Name; using (UnitOfWork unitOfWork = new UnitOfWork()) { unitOfWork.GetRepository <department>().Insert(item); unitOfWork.saveChanges(); return(new ResultHelper(true, item.DepartmentID, ResultHelper.SuccessMessage)); } } catch (Exception ex) { return(new ResultHelper(false, departmentDto.DepartmentID, ResultHelper.UnSuccessMessage)); } }
public department_update_others_normal(string exchangeName, DepartmentDto dto, string currentDBStr) { base.MessageBodyByte = ByteConvertHelper.Object2Bytes(dto); base.exchangeName = exchangeName; base.MessageRouter = this.GetType().Name; _currentDBStr = currentDBStr; }
private void GetSubTree(ref TreeViewItem iSubTree, DepartmentDto department) { var subItem = new TreeViewItem { Header = department.Details.Manager.Name, Tag = new Uri(string.Format(@"/EmployeeDetailsPage.xaml?id={0}", department.Details.Manager.Id), UriKind.Relative) }; iSubTree.Items.Add(subItem); foreach (var employee in department.Employees) { subItem = new TreeViewItem { Header = employee.Name, Tag = new Uri(string.Format(@"/EmployeeDetailsPage.xaml?id={0}", employee.Id), UriKind.Relative) }; iSubTree.Items.Add(subItem); } foreach (var subDept in department.SubDepartments) { subItem = new TreeViewItem { Header = subDept.Details.Name, Tag = new Uri(string.Format(@"/DepartmentDetailsPage.xaml?id={0}", subDept.Details.Id), UriKind.Relative) }; iSubTree.Items.Add(subItem); GetSubTree(ref subItem, subDept); } }
public static DepartmentDto GetDepartmentBaseInfoDto() { var dto = new DepartmentDto(); using (var session = Dmo.NewSession()) { var employeeId = GetCurrentBindingEmployeeID(session); var query = new DQueryDom(new JoinAlias(typeof(Employee))); query.Where.Conditions.Add(DQCondition.EQ("ID", employeeId)); query.Columns.Add(DQSelectColumn.Field("Department_ID")); query.Columns.Add(DQSelectColumn.Field("Department_Name")); query.Columns.Add(DQSelectColumn.Field("Department_Depth")); using (var reader = session.ExecuteReader(query)) { if (reader.Read()) { dto.ID = (long?)reader[0] ?? 0; if (dto.ID > 0) { dto.Name = (string)reader[1]; dto.Department_Depth = (int?)reader[2] ?? 0; } } } } return(dto); }
public async Task <IActionResult> Put(int id, [FromBody] DepartmentDto DepartmentDto) { var retVal = await _departmentRepo.Update(id, DepartmentDto); _logger.LogInformation($"UPDATED {id}"); return(Ok(retVal)); }
public async Task <ResponseDto <DepartmentDto> > Update(Guid id, DepartmentDto DepartmentDto) { if (id != DepartmentDto.DepartmentId) { return new ResponseDto <DepartmentDto>() { Message = "Incorrect input data.", StatusCode = HttpStatusCode.BadRequest, } } ; Department Department = _mapper.Map <Department>(DepartmentDto); _dbContext.Entry(Department).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); return(new ResponseDto <DepartmentDto>() { Id = DepartmentDto.DepartmentId, Data = DepartmentDto, Success = true, Message = "Department details updated successfully.", StatusCode = HttpStatusCode.OK, }); } }
public async Task <ResponseDto <DepartmentDto> > Delete(Guid id) { Department Department = await _dbContext.Departments.FirstOrDefaultAsync(p => p.DepartmentId == id); if (Department == null) { return new ResponseDto <DepartmentDto>() { Message = $"No department found for the given id {id}", StatusCode = HttpStatusCode.NotFound, } } ; _dbContext.Departments.Remove(Department); await _dbContext.SaveChangesAsync(); DepartmentDto DepartmentDto = _mapper.Map <DepartmentDto>(Department); return(new ResponseDto <DepartmentDto>() { Id = id, Data = DepartmentDto, Success = true, Message = "Department deleted successfully.", StatusCode = HttpStatusCode.OK, }); }
public bool Update(DepartmentDto dto) { var department = Mapper.Map <Department>(dto); _departmentRepository.Update(department); return(_departmentRepository.SaveChanges() > 0); }
// GET: Department/Details/5 public ActionResult Details(int id) { DetailDepartment ModelView = new DetailDepartment(); string url = "departmentdata/finddepartment/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into department data transfer object //Department data DepartmentDto SelectedDepartment = response.Content.ReadAsAsync <DepartmentDto>().Result; ModelView.Department = SelectedDepartment; //Get associated user data string urlDonor = "departmentdata/finddonorsfordepartment/" + id; response = client.GetAsync(urlDonor).Result; IEnumerable <ApplicationUserDto> selectedUser = response.Content.ReadAsAsync <IEnumerable <ApplicationUserDto> >().Result; ModelView.Users = selectedUser; return(View(ModelView)); } else { return(RedirectToAction("Error")); } }
public async Task <IActionResult> Post(DepartmentDto departmentDto) { using (var logger = _loggerManager.CreateLogger()) { try { if (!ModelState.IsValid) { return(BadRequest()); } var departmentCreated = await _departmentService.Create(departmentDto); if (departmentCreated) { logger.LogInformation($"Department {departmentDto.Title} is added"); return(Ok()); } return(StatusCode(500)); } catch (Exception ex) { logger.LogError("Something happend while adding departments", ex); return(StatusCode(500)); } } }
public void Add(DepartmentDto DepartmentDto) { var Department = _mapper.Map <DepartmentDto, Department>(DepartmentDto); _unitofWork.DepartmentRepository.Add(Department); _unitofWork.SaveChanges(); }
public async Task <DepartmentDto> CreateAsync(int companyId, DepartmentDto departmentDto) { var company = await Uow.Companies.GetByIdAsync(companyId); if (company == null) { throw new ArgumentException($"Company with id: '{companyId}' not found", nameof(companyId)); } try { var entityToCreate = departmentDto.ToEntity(); entityToCreate.CompanyId = companyId; Uow.Departments.Create(entityToCreate); await Uow.CommitAsync(); return(entityToCreate.ToDto()); } catch (Exception e) { Logger.LogError(e, "Error while creating department"); throw; } }
// GET: Practices public ActionResult ListPractices() { List <ListPractices> ViewModel = new List <ListPractices>(); string URL = "PracticeData/GetPractices"; HttpResponseMessage HttpResponse = Client.GetAsync(URL).Result; if (HttpResponse.IsSuccessStatusCode) { IEnumerable <PracticeDTO> PracticeList = HttpResponse.Content.ReadAsAsync <IEnumerable <PracticeDTO> >().Result; foreach (var item in PracticeList) { URL = "DepartmentData/FindDepartment/" + item.DepartmentID; HttpResponse = Client.GetAsync(URL).Result; DepartmentDto NewDepartment = HttpResponse.Content.ReadAsAsync <DepartmentDto>().Result; ListPractices NewList = new ListPractices(); NewList.Practice = item; NewList.Department = NewDepartment; ViewModel.Add(NewList); } return(View(ViewModel)); } else { return(RedirectToAction("List")); } }
public static Department MapCreate(DepartmentDto department) { return(new Department { Name = department.Name, }); }
private async Task UpdateAsync(DepartmentDto department) { var request = new UpdateDepartmentDto() { Id = department.Id, Name = department.Name, Description = department.Description }; var response = await _departmentManager.UpdateAsync(request); if (response.Succeeded) { await GetAllDepartmentsWithPaging(); DepartmentDialogVisible = false; } else { foreach (var message in response.Messages) { await _message.Error(message); } } }
//public void UpdateDepartment (Models.Department department) // After AutoMapper public void UpdateDepartment(int id, DepartmentDto department) { //var _department = DBContext.Departments.Single(x => x.Department_ID == id); Models.Department _department = iMapper.Map <DepartmentDto, Models.Department>(department); DBContext.Entry(_department).State = System.Data.Entity.EntityState.Modified; DBContext.SaveChanges(); }
public async Task <IActionResult> Post([FromBody] DepartmentDto model) { //TODO: Implement Realistic Implementation await Task.Yield(); return(Created("", null)); }
//修改 public IActionResult Edit(int id) { DepartmentDto editDto = _departmentAppService.GetDtoByID(id); GenerateTempData(editDto); return(View(editDto)); }
public IEnumerable <DepartmentDto> GetAllDepartments() { var departmentDtos = new List <DepartmentDto>(); using (var connection = new SqlConnection(ConnectionString)) { var command = new SqlCommand("SELECT Id, Name FROM Departments", connection); command.Connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Int32.TryParse(reader["Id"].ToString().Trim(), out int id); var name = reader["Name"].ToString().Trim(); var department = new DepartmentDto(id, name); departmentDtos.Add(department); } } return(departmentDtos); }
public ActionResult Save(string id, string pid, string name, string remark) { try { var entity = new DepartmentDto { Id = int.Parse(id.IsNullOrEmpty() ? "0" : id), Pid = int.Parse(pid.IsNullOrEmpty() ? "0" : pid), Name = name, Remark = remark }; if (entity.Id == entity.Pid) { return(ToJsonErrorResult(1, "父级菜单不能设置成自己")); } var response = _departmentService.SaveDeparment(new SaveDepartmentRequest { Entity = entity }); if (!response.IsSuccess) { return(ToJsonErrorResult(1, response.MessageText)); } return(ToJsonResult(new { status = 0 })); } catch (Exception ex) { LogManager.DefaultLogger.ErrorFormat("保存部门信息出错:{0}", new { id, pid, name, err = ex.ToString() }.ToJson()); return(ToJsonFatalResult("保存部门信息出错")); } }
public IActionResult Update(DepartmentDto departmentDto) { Department department = _autoMapperBase.MapToSameType <DepartmentDto, Department>(departmentDto); _departmentService.Update(department); return(NoContent()); }
public async Task <ActionResult> PutDepartment(int id, DepartmentDto departmentDto) { if (id != departmentDto.DepartmentId) { return(BadRequest()); } var departmentFromRepo = await _departmentsRepo.GetDepartmentByIdAsync(id); try { _mapper.Map(departmentDto, departmentFromRepo); // await _departmentsRepo.UpdateDepartment(id); await _departmentsRepo.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { if (departmentFromRepo is null) { return(NotFound()); } else { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = ex.Message })); } } return(NoContent()); }
public IHttpActionResult FindDepartment(int id) { Department Department = db.departments.Find(id); if (Department == null) { return(NotFound()); } //Salon Salon = db.Salons //.Where(s => s.Members.Any(m => m.SalonID == Member.SalonID)) //.FirstOrDefault(); //if not found, return 404 status code. //if (Salon == null) // { // return NotFound(); //} DepartmentDto DepartmentDto = new DepartmentDto { departmentId = Department.departmentId, departmentName = Department.departmentName, email = Department.email, phone = Department.phone, fax = Department.fax, extension = Department.extension, category = Department.category }; //pass along data as 200 status code OK response return(Ok(DepartmentDto)); }
// GET: JobPosting/Details/5 public ActionResult Details(int id) { ShowJobPosting ViewModel = new ShowJobPosting(); ViewModel.isadmin = User.IsInRole("Admin"); string url = "jobpostingdata/findjobposting/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. Debug.WriteLine("Details:" + response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into department data transfer object JobPostingDto SelectedJobPosting = response.Content.ReadAsAsync <JobPostingDto>().Result; ViewModel.jobposting = SelectedJobPosting; url = "jobpostingdata/finddepartmentforjobposting/" + id; response = client.GetAsync(url).Result; DepartmentDto SelectedDepartment = response.Content.ReadAsAsync <DepartmentDto>().Result; ViewModel.department = SelectedDepartment; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IActionResult AddADepartment([FromBody] DepartmentDto departmentDto) { if (departmentDto == null) { return(BadRequest(ModelState)); } if (_npRepo.DepartmentExists(departmentDto.Name)) { ModelState.AddModelError("", "Department already exists."); return(StatusCode(404, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // var ContactInfoObj = _mapper.Map<CreateEmployeeDto, ContactInfo>(createEmployeeDto); var departmentObj = _mapper.Map <DepartmentDto, Department>(departmentDto); // employeePIObj.ContactInfo = ContactInfoObj; if (!_npRepo.CreateDepartment(departmentObj)) { ModelState.AddModelError("", $"Something went wrong when saving the record {departmentObj.Name}"); return(StatusCode(500, ModelState)); } return(Ok()); }
public IHttpActionResult GetDepartments() { IEnumerable <Department> Departments = db.departments.ToList(); List <DepartmentDto> DepartmentDtos = new List <DepartmentDto> { }; Debug.WriteLine("Files Received"); foreach (var Department in Departments) { DepartmentDto NewDepartment = new DepartmentDto { departmentId = Department.departmentId, departmentName = Department.departmentName, email = Department.email, phone = Department.phone, fax = Department.fax, extension = Department.extension, category = Department.category }; DepartmentDtos.Add(NewDepartment); } Debug.WriteLine("Get DepartmentDtos"); return(Ok(DepartmentDtos)); }
public void InsertDepartment(DepartmentDto depObject) { InvokeService <IDemoServerServiceContract>(c => { c.InsertDepartment(depObject); }); }
internal static async Task SeedDefaultDepartments(IApiClient client, TenantContainer tenantInfo) { await client.SignInWithUserPasswordAsync(tenantInfo.AdminName, tenantInfo.AdminPassword); { // create department 1.1 var defaultDepartment11 = new DepartmentDto { Id = Guid.NewGuid().ToString(), Name = "Head Office Operations", BranchOfficeId = tenantInfo.BranchOffice_One.Id.ToString(), }; await client.PostDepartmentAsync(defaultDepartment11); tenantInfo.Department_1_1.Department = defaultDepartment11; } { // create department 1.2 var defaultDepartment12 = new DepartmentDto { Id = Guid.NewGuid().ToString(), Name = "Head Office Sales", BranchOfficeId = tenantInfo.BranchOffice_One.Id.ToString() }; var createdDto12 = await client.PostDepartmentAsync(defaultDepartment12); tenantInfo.Department_1_2.Department = defaultDepartment12; } }
public object GetDeparmentList(DepartmentDto query) { query.Query = string.IsNullOrEmpty(query.Query) ? "" : query.Query; //连接表查询经理名称 var deparments = (from dep in _ctx.Deparment join worker in _ctx.Worker on dep.ManagerId equals worker.Id where dep.CompanyId == query.CompId && dep.Name.Contains(query.Query) select new { id = dep.Id, name = dep.Name, code = dep.Code, workerCount = dep.WorkerCount, manger = worker.Name, }).ToList(); deparments.AddRange((from dep in _ctx.Deparment where dep.CompanyId == query.CompId && dep.Name.Contains(query.Query) && dep.ManagerId == null select new { id = dep.Id, name = dep.Name, code = dep.Code, workerCount = dep.WorkerCount, manger = "无" }).ToList()); var result = new { totalCount = deparments.Count(), data = deparments.Skip((query.CurrentPage - 1) * query.CurrentPageSize).Take(query.CurrentPageSize), }; return(result); }
/// <summary> /// 部門データを登録する /// </summary> /// <param name="dto">部門データ</param> /// <returns>登録件数</returns> public int ExecUpdate(DepartmentDto dto) { if ( dto == null ) throw new ArgumentNullException("dto"); if ( dto.Id.HasValue ) { DepartmentDto data = _dao.GetData(dto.Id.Value); if ( data != null ) return ( _dao.UpdateData(dto) ); else return ( _dao.InsertData(dto) ); } else { return ( _dao.InsertData(dto) ); } }
/// <summary> /// 部門を削除する /// </summary> /// <param name="id">部門ID</param> /// <returns>削除件数</returns> public int ExecDelete(int id) { DepartmentDto data = new DepartmentDto(); data.Id = id; return ( _dao.DeleteData(data) ); }
public void TestEditService() { Include(PATH); IDepartmentEditService service = (IDepartmentEditService) GetComponent(typeof (IDepartmentEditService)); Assert.IsNotNull(service, "NotNull"); DepartmentDto data = service.GetData(2); Assert.AreEqual(2, data.Id.Value, "ID"); Assert.AreEqual("0002", data.Code, "Code"); Assert.AreEqual("技術部", data.Name, "Name"); Assert.AreEqual(2, data.ShowOrder, "Order"); // 挿入のテスト data = new DepartmentDto(); data.Code = "0102"; data.Name = "管理部"; data.ShowOrder = 4; Assert.AreEqual(1, service.ExecUpdate(data), "Insert"); // 更新のテスト data = new DepartmentDto(); data.Id = 2; data.Code = "0020"; data.Name = "技術事業部"; data.ShowOrder = 5; Assert.AreEqual(1, service.ExecUpdate(data), "Update"); data = service.GetData(2); Assert.AreEqual(2, data.Id.Value, "ID"); Assert.AreEqual("0020", data.Code, "Code"); Assert.AreEqual("技術事業部", data.Name, "Name"); Assert.AreEqual(5, data.ShowOrder, "Order"); }
/// <summary> /// 部門データを表示する /// </summary> /// <param name="data">部門データ</param> private void _ShowData(DepartmentDto data) { txtCode.Text = data.Code; txtName.Text = data.Name; txtOrder.Text = data.ShowOrder.ToString(); }
/// <summary> /// 登録ボタンを押したときの処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { try { if ( MessageBox.Show("本当に登録しますか?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No ) return; DepartmentDto data = new DepartmentDto(); if ( !_SetInputData(data) ) return; if ( _service.ExecUpdate(data) > 0 ) { _InitializeControls(); MessageBox.Show("登録しました", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { throw new ApplicationException("登録に失敗しました"); } } catch ( Exception ex ) { logger.ErrorFormat(EXCEPTION_MSG_FORMAT, ex.Message); MessageBox.Show(String.Format(EXCEPTION_MSG_FORMAT, ex.Message), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public void TestInsertOfDao() { Include(PATH); IDepartmentDao dao = (IDepartmentDao) GetComponent(typeof (IDepartmentDao)); Assert.IsNotNull(dao, "NotNull"); // 挿入のテスト DepartmentDto data = new DepartmentDto(); data.Code = "0102"; data.Name = "管理部"; data.ShowOrder = 4; Assert.AreEqual(1, dao.InsertData(data), "Insert"); // 更新のテスト int id = dao.GetId("0102"); data = new DepartmentDto(); data.Code = "0102"; data.Id = id; data.Name = "事業管理部"; data.ShowOrder = 4; Assert.AreEqual(1, dao.UpdateData(data), "Update"); data = dao.GetData(id); Assert.AreEqual(id, data.Id.Value, "ID"); Assert.AreEqual("0102", data.Code, "Code"); Assert.AreEqual("事業管理部", data.Name, "Name"); Assert.AreEqual(4, data.ShowOrder, "Order"); // 削除のテスト data = new DepartmentDto(); data.Id = id; Assert.AreEqual(1, dao.DeleteData(data), "Delete"); IList<DepartmentDto> list = dao.GetAll(); Assert.AreEqual(3, list.Count, "Count"); }
/// <summary> /// 入力データをセットする /// </summary> /// <param name="data">セット部門先データ</param> /// <returns>登録の可否</returns> private bool _SetInputData(DepartmentDto data) { bool ret = true; // 部門Id if ( _id.HasValue ) data.Id = _id.Value; else data.Id = null; // 部門コード if ( txtCode.Text != "" ) { if ( Regex.IsMatch(txtCode.Text, @"^\d{4}") ) { data.Code = txtCode.Text; } else { MessageBox.Show("コードに数字以外の文字があります", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ret = false; } } else { MessageBox.Show("コードを入力してください", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ret = false; } // 部門名 if ( txtName.Text != "" ) data.Name = txtName.Text; else { MessageBox.Show("名前を入力してください", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ret = false; } // 表示順番 if ( txtOrder.Text != "" ) { if ( Regex.IsMatch(txtOrder.Text, @"^\d{1,4}") ) { data.ShowOrder = Convert.ToInt32(txtOrder.Text); } else { MessageBox.Show("表示順番に数字以外の文字があります", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ret = false; } } else { MessageBox.Show("表示順番を入力してください", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ret = false; } return ret; }
private List<DepartmentDto> FillSubDepartments(Department d) { var res = new List<DepartmentDto>(); foreach (var subDepartment in d.SubDepartments) { var subDept = new DepartmentDto { Details = { Id = subDepartment.Id, Name = subDepartment.Name, Manager = new EmployeeDto { Address = subDepartment.Manager.Person.Address, Id = subDepartment.Manager.Id, Name = subDepartment.Manager.Person.Name, Salary = subDepartment.Manager.Salary } } }; subDept.Employees = subDepartment.Employees.Select(e => new EmployeeDto { Id = e.Id, Address = e.Person.Address, Name = e.Person.Name, Salary = e.Salary }).ToList(); subDept.SubDepartments = FillSubDepartments(subDepartment); res.Add(subDept); } return res; }