public JsonResult Create(DepartmentDto model) { string errs = GetModelStateError(); if (!string.IsNullOrEmpty(errs)) { return(Json(new OperateMessage <string>(OperateResult.Fail, true, errs))); } bool IsSucceed = _DepartmentAppService.Create(new DepartmentDto() { ID = Guid.NewGuid(), Code = model.Code, ContactNumber = model.ContactNumber, CreateTime = DateTime.Now, CreatorID = _currUser.ID, IsDeleted = model.IsDeleted, LastUpdateTime = DateTime.Now, LastUpdateUserID = _currUser.ID, Manager = model.Manager, Name = model.Name, ParentId = model.ParentId, Remarks = model.Remarks, }); if (IsSucceed) { return(Json(new OperateMessage <string>("/Department/Index"))); } return(Json(new OperateMessage <string>(IsSucceed ? OperateResult.Success : OperateResult.Fail, true, IsSucceed ? "添加成功!" : "添加失败!"))); }
public async Task Should_Create_New_Department_And_Add_Child_Department() { await _departmentAppService.Create( new CreateDepartmentDto { Name = "IT", Description = "IT", CostCenter = "1234" }); await _departmentAppService.Create( new CreateDepartmentDto { Name = "Soft", Description = "Soft", CostCenter = "1234" }); await UsingDbContextAsync(async context => { var itDepart = await context.Departments.FirstOrDefaultAsync(d => d.Name == "IT"); var softDepart = await context.Departments.FirstOrDefaultAsync(d => d.Name == "Soft"); itDepart.ShouldNotBeNull(); softDepart.ShouldNotBeNull(); await _departmentAppService.AddChildDepartmentAsync(new AddChildDepartmentInput { ParentDepartmentId = itDepart.Id, ChildDepartmentId = softDepart.Id }); softDepart = await context.Departments.FirstOrDefaultAsync(d => d.Name == "Soft"); softDepart.ParentDepartment.Id.ShouldBe(itDepart.Id); }); }
/// <summary> /// 新增或编辑功能 /// </summary> /// <param name="dto"></param> /// <returns></returns> public IActionResult Edit(DepartmentDto dto) { if (!ModelState.IsValid) { return(Json(new { Result = "Faild", Message = GetModelStateError() })); } if (dto.ID != Guid.Empty ? _service.Edit(dto) : _service.Create(dto)) { return(Json(new { Result = "Success" })); } return(Json(new { Result = "Faild" })); }
public DepartmentCreateResponse Create(DepartmentCreateRequest request) { return(_departmentAppService.Create(request)); }
public async Task <IActionResult> Post([FromBody] CreateDepartmentCommand command) { var result = _service.Create(command); return(await Response(result, result.Notifications)); }