public async Task Hanlde_CreateEntityCommand_AddsEntityDefinitionToProjectAsync() { // arrange var project = CreateProject(); var command = new CreateEntityCommand { Id = project.Id, Name = "NewEntityName", Description = "NewEntityDescription" }; var session = new Mock <ISession>(); session.Setup(s => s.Get <Project>(project.Id, command.ExpectedVersion, It.IsAny <CancellationToken>())).Returns(Task.FromResult(project)); var target = new ProjectCommandHandler(session.Object); // act await target.Handle(command); // assert var entityDefinition = project.Schema.Entities.FirstOrDefault(e => e.Name == command.Name); Assert.NotNull(entityDefinition); Assert.Equal(command.Name, entityDefinition.Name); Assert.Equal(command.Description, entityDefinition.Description); session.Verify(s => s.Commit(It.IsAny <CancellationToken>())); }
private CreateEntityCommand CreateCreateEntityCommand(string entityName, bool addElement) { var attributeModel = new AttributeDto() { Name = "Id", DataType = EnumDataTypes.String, AllowNull = false, Length = 32 }; var command = new CreateEntityCommand() { Name = entityName, Attributes = new List <AttributeDto>() { attributeModel } }; if (addElement) { var elementEntityCommand = CreateCreateEntityCommand("ElementChild", false); var elementDto = new ElementDto() { Entity = elementEntityCommand, DataType = EnumDataTypes.Object }; command.Elements = new List <ElementDto>() { elementDto }; } return(command); }
public override void Handle(CreateEntityCommand <EquipmentModel> command) { var entity = new EquipmentItemEntity(); this.UpdateItem(entity, command.Model); this.itemRepository.Add(entity); }
public ActionResult Create(CustomerDTO RecordToInsert) { var cmd = new CreateEntityCommand <CustomerDTO>(RecordToInsert, User.Identity.Name); CommandProcessor.ExecuteCommand(cmd, Container); return(RedirectToAction("Index")); }
public static Entity ToEntity(this CreateEntityCommand cmd) { return(new Entity { Name = cmd.Name, Email = cmd.Email, EntityTypeId = cmd.EntityTypeId }); }
public async override Task <T> HandleAsync(CreateEntityCommand <T> request, CancellationToken cancellationToken) { var dbSet = dbContextProvider.GetDBSet <T>(); request.Model.Id = Guid.NewGuid(); await dbSet.InsertAsync(request.Model, cancellationToken); return(await dbSet.QueryByIdAsync(request.Model.Id, cancellationToken)); }
public void Handle(CreateEntityCommand <MainCategoryModel> command) { var entity = new MainCategoryEntity { Name = command.Model.Name, }; this.mainCategoryRepository.Add(entity); }
public async Task <EntityResponse> CreateAsync(CreateEntityCommand createCommand) { _createCommandValidator.ValidateAndThrowIfFailed(createCommand); var entity = _mapper.Map <CreateEntityCommand, Entity>(createCommand); var createdEntiy = await _entitiesRepository.SaveAsync(entity); return(_mapper.Map <Entity, EntityResponse>(createdEntiy)); }
public override void Handle(CreateEntityCommand <OtherItemModel> command) { var entity = new OtherItemEntity { StatInfo = new StatInfoEntity(), }; this.UpdateItem(entity, command.Model); this.itemRepository.Add(entity); }
public void Handle(CreateEntityCommand <SkillModel> command) { var skill = new SkillEntity() { StatInfo = new StatInfoEntity(), }; this.UpdateSkillEntityFromModel(skill, command.Model); this.skillRepository.Add(skill); }
public void Handle(CreateEntityCommand <SubCategoryModel> command) { var mainCategory = this.mainCategoryRepository.FindById(command.Model.MainCategoryId); var entity = new SubCategoryEntity { Name = command.Model.Name, MainCategory = mainCategory, }; this.subCategoryRepository.Add(entity); }
public void Handle(CreateEntityCommand <TierModel> command) { var equipment = this.equipmentRepository.FindById(command.Model.EquipmentItemId); var tier = new TierEntity { Name = command.Model.Name, Tier = command.Model.Tier, EquipmentItem = equipment, }; this.tierRepository.Add(tier); }
public async Task <ResultDto <bool> > Post([FromBody] CreateEntityCommand item) { try { var result = await _mediator.Send(item); return(FormatResult(result)); } catch (Exception ex) { return(FormatError <bool>(ex.Message)); } }
public async Task <ActionResult <Customer> > Customer([FromBody] CreateCustomerDto customerDto) { try { var command = new CreateEntityCommand <Customer> { Entity = mapper.Map <Customer>(customerDto) }; return(await mediator.Send(command)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task Process(CreateEntityCommand <Product> request, CancellationToken cancellationToken) { if (request.Entity.CategoryId is null) { return; } var category = await _context.Set <Category>() .SingleOrDefaultAsync(c => c.Id == request.Entity.CategoryId, cancellationToken); if (category is null) { throw new EntityNotFoundException(); } }
public bool Execute(CreateEntityCommand <T> Command, ICommandProcessor CommandProcessor) { IDTOConverter <T> converter = null; try { converter = (IDTOConverter <T>)CommandProcessor.UnityContainer.Resolve(typeof(IDTOConverter <T>)); } catch (Exception) { throw new ApplicationException("A Converter has not been found for this DTO, please make sure it was registered in the Unity Container Configuration"); } var converted = converter.Convert(Command.Entity); var dapperRepository = CommandProcessor.UnityContainer.Resolve <IDefaultDomainRepository>(); dapperRepository.Create(converted); return(true); }
public IActionResult Post([FromBody] CreateEntityCommand cmd) => createCommand.Execute(cmd).Match( Succ: x => x.Match <IActionResult>(Ok, BadRequest), Fail: ex => StatusCode(500, ex));
public async Task <IActionResult> Create(CreateEntityCommand createCommand) { var createdEntity = await _entitiesService.CreateAsync(createCommand); return(this.CreatedAtAction(nameof(GetById), new { id = createdEntity.Id }, createdEntity)); }
public Task <T> Handle(CreateEntityCommand <T> request, CancellationToken cancellationToken) { return(repository.Add(request.Entity)); }
public abstract void Handle(CreateEntityCommand <TModel> command);
public WorkResult Create(TModel model) { var command = new CreateEntityCommand <TModel>(model); return(this.Handle(this.createHandler, command)); }
public async Task <IActionResult> InsertAsync([FromBody] T obj, CancellationToken cancellationToken) { var createRequest = new CreateEntityCommand <T>(accountId, obj); return(this.Ok(await mediator.Send(createRequest, cancellationToken))); }
public override async Task HandleAsync(CreateEntityCommand <TEntity> command) { Repository.Add(command.Entity); await Repository.SaveChangesAsync(); }