public async Task <DepartmentProjection> CreateDepartment([FromBody] CreateDepartmentDTO input) { var command = new CreateDepartmentCommand(input); var result = await _commandDispatcher.Execute(command); return(result); }
public async Task <Guid> CreateDepartmentAsync(CreateDepartmentCommand command) { var department = new Department(command.Name, command.IsEnabled, command.ParentId); _departmentRepository.Add(department); await _unitOfWork.CommitAsync(); return(department.Id); }
public void Post() { var command = new CreateDepartmentCommand { Name = "someName", }; this.commandDispatcher.Dispatch(command); }
public void setup_dispatcher_to_verify_createDepartmentCommands_are_the_same(CreateDepartmentCommand command) { CommandDispatcherMock.Setup(a => a.Execute(It.IsAny <CreateDepartmentCommand>())) .Callback <ICommand <DepartmentProjection> >((a) => { DepartmentCommand = (CreateDepartmentCommand)a; }) .ReturnsAsync(new DepartmentProjection() { Name = command.Input.Name, }); }
public async Task <IActionResult> CreateDepartment(CreateDepartmentCommand createDepartment) { var result = await Mediator.Send(createDepartment); if (result.Success == false) { return(result.ApiResult); } return(Created(Url.Link("GetDepartmentInfo", new { id = result.Data.Id }), result.Data)); }
public override async Task <GuidRequired> CreateDepartment(CreateDepartmentRequest request, ServerCallContext context) { var command = new CreateDepartmentCommand { Name = request.Name, IsEnabled = request.IsEnabled, ParentId = request.ParentId, }; var result = await _organizationApp.CreateDepartmentAsync(command); return(result); }
public async Task <IActionResult> Create([Bind("DepartmentID,DepartmentName")] Department department) { if (ModelState.IsValid) { var command = new CreateDepartmentCommand(department); var handler = CommandHandlerFactory.Build(command); handler.Execute(_context); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public ActionResult AddDepartment(DepartmentModel model) { if (model.Name.IsNullOrWhiteSpace()) { this.ModelState.AddModelError("Name", "部门名字为空"); return(this.View(model)); } if (model.Descn.IsNullOrWhiteSpace()) { this.ModelState.AddModelError("Descn", "部门描述为空"); return(this.View(model)); } if (this.permissionQuery.CountUsingDepartmentName(model.Name) > 0) { this.ModelState.AddModelError("Descn", "部门已经存在"); return(this.View(model)); } var check = this.CheckCurrentOperator(GroupSort.Super); if (check.IsNotNullOrEmpty()) { this.ModelState.AddModelError("Name", check); return(this.View(model)); } try { var command = new CreateDepartmentCommand(NewId.GenerateString(NewId.StringLength.L24)) { Name = model.Name, Descn = model.Descn }; var handler = this.commandBus.Send(command); if (handler.Ok()) { return(this.RedirectToAction("EditDepartment", new { aggregateId = command.AggregateId })); } } catch (Exception dex) { this.ModelState.AddModelError("Name", dex.GetMessage()); } return(this.View(model)); }
public DepartmentAggregateRoot Create(IWorkContext context, CreateDepartmentCommand command) { this.ApplyEvent(new CreateDepartmentEvnet { AggregateId = this.AggregateId, CreateDate = context.WorkTime, Creator = context.GetWorkerName(), Version = this.Version, Name = command.Name, Descn = command.Descn, }); return(this); }
public Department Create(CreateDepartmentCommand command) { var depart = new Department(0, command.Name, command.Description, command.Active); if (_repository.DepartmentExists(command.Name)) { AddNotification("Department", "O Departamento já existe!"); } if (depart.IsValid()) { _repository.Save(depart); } return(depart); }
public async Task ShouldGetModelForValidInformation() { var command = new CreateDepartmentCommand { AdminUserId = _adminUserId, TenantId = _tenantId, Departments = new List <string> { "a", "b" } }; var departmentModel = await _commandHandler.Handle(command, CancellationToken.None); Assert.Null(departmentModel.Errors); Assert.True(departmentModel.Items.Single().Departments.Count > 0); }
public async Task <ActionResult> Create(Guid?businessUnitId) { var businessUnits = await Mediator.Send(new GetBusinessUnitListQuery()); businessUnits.BusinessUnits = businessUnits.BusinessUnits.ToList(); ViewBag.BusinessUnits = businessUnits.BusinessUnits.Count == 0 ? null : businessUnits.BusinessUnits; if (businessUnitId == null) { return(PartialView("_Create")); } var department = new CreateDepartmentCommand { BusinessUnitId = businessUnitId.Value }; return(PartialView("_CreateDepartmentInBU", department)); }
public async Task <IActionResult> Add(AddDepartmentsModel model) { var groupKey = Guid.NewGuid(); model.Time = model.Time.Date; var departments = new List <Department> { new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.Ceo, Time = model.Time, EmployeeNumber = model.CeoNo }, new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.InternalControl, Time = model.Time, EmployeeNumber = model.InternalControlNo }, new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.StrategicInvestment, Time = model.Time, EmployeeNumber = model.StrategicInvestmentNo }, new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.HumanResources, Time = model.Time, EmployeeNumber = model.HumanResourcesNo }, new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.FinancialManagement, Time = model.Time, EmployeeNumber = model.FinancialManagementNo }, new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.ProductDevelopment, Time = model.Time, EmployeeNumber = model.ProductDevelopmentNo }, new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.SupplyChain, Time = model.Time, EmployeeNumber = model.SupplyChainNo }, new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.UserCenter, Time = model.Time, EmployeeNumber = model.UserCenterNo }, new Department { CapUpdated = CapUpdate.UnUpdate, GroupKey = groupKey, Organization = Organization.ExternalContact, Time = model.Time, EmployeeNumber = model.ExternalContactrNo } }; var command = new CreateDepartmentCommand { Departments = departments }; await _mediatR.Send(command, new CancellationToken()); return(RedirectToAction("Index")); }
public async Task <ActionResult <bool> > CreateDepartmentAsync([FromBody] CreateDepartmentCommand createDepartmentCommand) { bool commandResult = false; _logger.LogInformation( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", createDepartmentCommand.GetType().Name, nameof(createDepartmentCommand.Name), createDepartmentCommand.Name, createDepartmentCommand); commandResult = await _mediator.Send(createDepartmentCommand); if (!commandResult) { return(BadRequest()); } return(Ok()); }
public async void given_create_department_command_command_dispatcher_should_get_same_command_created_in_controller() { var mockAgg = new DepartmentControllerMockAggregate(); var controller = mockAgg.DepartmentControllerFactory(); var input = new CreateDepartmentDTO { Name = "testName", }; var command = new CreateDepartmentCommand(input); mockAgg.setup_dispatcher_to_verify_createDepartmentCommands_are_the_same(command); var result = await controller.CreateDepartment(input); //Assert Assert.IsType <DepartmentProjection>(result); Assert.Equal(result.Name, input.Name); }
public async Task <IActionResult> Create([Bind("DepartmentID,Name,Budget,StartDate,InstructorID")] CreateDepartmentCommand command) { try { await Mediator.Send(command); return(RedirectToAction(nameof(Index))); } catch (System.Exception) { var result = await Mediator.Send(new GetInstructorLookupCommand()); ViewData["InstructorID"] = new SelectList(result, "ID", "FullName", command.InstructorID); return(View(new Domain.Entities.Department { Name = command.Name, Budget = command.Budget, StartDate = command.StartDate, InstructorID = command.InstructorID })); } }
public async Task CanCreateDepartment() { var client = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory); //Init model var command = new CreateDepartmentCommand { Departments = new List <string> { "Tasarim" } }; var json = JsonConvert.SerializeObject(command); // The endpoint or route of the controller action. var httpResponse = await client.PostAsync(requestUri : "/Department", content : new StringContent(json, Encoding.UTF8, StringConstants.ApplicationJson)); // Must be successful. httpResponse.EnsureSuccessStatusCode(); Assert.True(httpResponse.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode); }
public async Task <ActionResult> Create(CreateDepartmentCommand command) { if (await Mediator.Send(command) == null) { return(BadRequest()); } var request = await Mediator.Send(new GetDepartmentListQuery() { BusinessUnitId = command.BusinessUnitId }); if (request != null) { return(Json(new { id = request.BusinessUnitId, count = request.Departments.Count, view = await this.RenderViewAsync("_DepartmentsTable", request, true) })); } return(Ok()); }
public static ICommandHandler <CreateDepartmentCommand> Build(CreateDepartmentCommand command) { return(new CreateDepartmentCommandHandler(command)); }
public async Task <IActionResult> Create(CreateDepartmentCommand command) => Json(await Mediator.Send(command));
public static DepartmentAggregateRoot Register(IWorkContext context, CreateDepartmentCommand command) { return(new DepartmentAggregateRoot(command.AggregateId).Create(context, command)); }
public async Task <IActionResult> AddDepartment([FromBody] CreateDepartmentCommand department) { var command = await _mediator.Send(department); return(Ok(command)); }
public void Run() { IExecutable command = null; string line = Console.ReadLine(); while (line != "end") { string[] tokens = line.Split(); switch (tokens[0]) { case "create-company": command = new CreateCompanyCommand(db, tokens[1], tokens[2], tokens[3], decimal.Parse(tokens[4])); break; case "create-employee": string departmentName = null; if (tokens.Length > 5) { departmentName = tokens[5]; } command = new CreateEmployeeCommand(db, tokens[1], tokens[2], tokens[3], tokens[4], departmentName); break; case "create-department": string mainDepartmentName = null; if (tokens.Length > 5) { mainDepartmentName = tokens[5]; } command = new CreateDepartmentCommand(db, tokens[1], tokens[2], tokens[3], tokens[4], mainDepartmentName); break; case "pay-salaries": command = new PaySalariesCommand(tokens[1], db); break; case "show-employees": command = new ShowEmployeesCommand(tokens[1], db); break; } try { Console.Write(command.Execute()); } catch (Exception e) { Console.WriteLine(e.Message); } finally { line = Console.ReadLine(); } } }
public async Task <IActionResult> Post([FromBody] CreateDepartmentCommand command) { var result = _service.Create(command); return(await Response(result, result.Notifications)); }
public async Task <ActionResult <ResponseModel <CreateDepartmentModel> > > Post([FromBody] CreateDepartmentCommand command) { try { var userId = Claims[ClaimTypes.Sid].ToInt(); var tenantId = Guid.Parse(Claims[ClaimTypes.UserData]); command.AdminUserId = userId; command.TenantId = tenantId; var createDepartmentModel = await Mediator.Send(command); return(Ok(createDepartmentModel)); } catch (NotFoundException) { return(NotFound()); } catch (ObjectAlreadyExistsException ex) { return(Conflict(new ResponseModel <CreateDepartmentModel>(new Error(HttpStatusCode.Conflict, ex)))); } catch { return(StatusCode(HttpStatusCode.InternalServerError.ToInt())); } }
public async Task <ActionResult <int> > Create(CreateDepartmentCommand command) { return(await Mediator.Send(command)); }
public async Task <IActionResult> Create([FromBody] CreateDepartmentCommand command) { await Mediator.Send(command); return(NoContent()); }
public void Run() { IExecutable command = null; var line = Console.ReadLine(); while (line != "end") { var tokens = line.Split(); switch (tokens[0]) { case "create-company": command = new CreateCompanyCommand(this.db, tokens[1], tokens[2], tokens[3], decimal.Parse(tokens[4])); break; case "create-employee": string departmentName = null; if (tokens.Length > 5) { departmentName = tokens[5]; } command = new CreateEmployeeCommand(this.db, tokens[1], tokens[2], tokens[3], tokens[4], departmentName); break; case "create-department": string mainDepartmentName = null; if (tokens.Length > 5) { mainDepartmentName = tokens[5]; } command = new CreateDepartmentCommand(this.db, tokens[1], tokens[2], tokens[3], tokens[4], mainDepartmentName); break; case "pay-salaries": command = new PaySalariesCommand(tokens[1], this.db); break; case "show-employees": command = new ShowEmployeesCommand(tokens[1], this.db); break; } try { Console.Write(command.Execute()); } catch (Exception e) { Console.WriteLine(e.Message); } finally { line = Console.ReadLine(); } } }