/// <summary> /// Implementation of <see cref="ICategoryCommands.CreateNewCategory(string, string, string, string, bool, DateTime?, DateTime?)"/> /// </summary> /// <param name="code">The category code</param> /// <param name="name">The category name</param> /// <param name="url">The category url</param> /// <param name="description">The category description</param> /// <param name="isVisible">Whether the category is visible</param> /// <param name="visibleFrom">The date and time of when the category starts to be visible</param> /// <param name="visibleTo">The date and time till when the category is visible</param> /// <returns>The category id</returns> public virtual async Task <Guid> CreateNewCategory(string code, string name, string url, string description, bool isVisible, DateTime?visibleFrom, DateTime?visibleTo) { try { var category = Category.Create(code, name, url); if (!string.IsNullOrEmpty(description)) { category.ChangeDescription(description); } if (isVisible) { if (!visibleFrom.HasValue && !visibleTo.HasValue) { category.SetAsVisible(); } else { category.SetAsVisible(visibleFrom, visibleTo); } } Repository.Add(category); await Repository.SaveChangesAsync(); var @event = new CategoryCreatedEvent(category.Id, name, code); EventBus.RaiseEvent(@event); return(category.Id); } catch { throw; } }
private CategoryAggregateRoot(Guid categoryId, Guid runningNumberId, string name, string colorCode) : this() { var creationEvent = new CategoryCreatedEvent(categoryId, runningNumberId, name, colorCode); this.Apply(creationEvent); this.RaiseEvent(creationEvent); }
public CategoryAggregate(Category cc) { var c = new CategoryCreatedEvent(cc.UniqueId, cc.Name, cc.DisplayName, cc.WhatWeAreLookingFor, cc.Version); ApplyChange(c); }
public Helper SetupCategorySavedEvent(CategoryCreatedEvent evnt) { MockEventDispatcher .Setup(x => x.Publish(It.Is <CategoryCreatedEvent>(s => s.Id == evnt.Id))) .Returns(Task.CompletedTask) .Verifiable(); return(this); }
private void Apply(CategoryCreatedEvent e) { Version = e.Version; Name = e.Name; DisplayName = e.DisplayName; UniqueId = e.UniqueId; WhatWeAreLookingFor = e.WhatWeAreLookingFor; this.Key = e.UniqueId.GetAggregateKey(); }
private void Handle(CategoryCreatedEvent evnt) { _parentId = evnt.ParentId; _name = evnt.Name; _url = evnt.Url; _thumb = evnt.Thumb; _type = evnt.Type; _isShow = evnt.IsShow; _sort = evnt.Sort; }
public async override Task <ExecutionStatus> HandleEvent(DomainEvent @event) { CategoryCreatedEvent categoryCreateEvent = @event as CategoryCreatedEvent; var category = _mapper.Map <Category>(categoryCreateEvent); var execution = await _zEsCategoryRepository.AddAsync(category); return(execution.RemoveGeneric()); }
public void CategoryCreatedEvent_Ctor_Should_Set_Arguments_Correctly() { Guid categoryId = Guid.NewGuid(); string name = "category"; string code = "code"; var @event = new CategoryCreatedEvent(categoryId, name, code); Assert.Equal(categoryId, @event.CategoryId); Assert.Equal(name, @event.Name); Assert.Equal(code, @event.Code); Assert.Equal(categoryId, @event.AggregateId); Assert.Equal(typeof(Catalog.Models.Category), @event.AggregateType); }
public async Task <ResponseModel> Handle(CategoryCreateRequest request, CancellationToken cancellationToken) { var category = this.mapper.Map <Category>(request); this.db.Categories.Add(category); await this.db.SaveChangesAsync(cancellationToken); var eventPost = new CategoryCreatedEvent(request.Name); this.eventBus.Publish(eventPost); return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.OK, Message = "The category was created successfully" }); }
private void onCategoryCreated(CategoryCreatedEvent e) { Id = e.CategoryId; _name = e.Name; }
private void Apply(CategoryCreatedEvent obj) { this.AggregateId = obj.AggregateId; this.Name = obj.Name; this.ColorCode = obj.ColorCode; }