Browse Source

Progress

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
c66f9ce3d0
  1. 37
      src/Squidex.Write/Schemas/SchemaDomainObject.cs

37
src/Squidex.Write/Schemas/SchemaDomainObject.cs

@ -16,6 +16,7 @@ using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.Dispatching; using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Write.Schemas.Commands; using Squidex.Write.Schemas.Commands;
using System.Collections.Generic;
namespace Squidex.Write.Schemas namespace Squidex.Write.Schemas
{ {
@ -111,35 +112,49 @@ namespace Squidex.Write.Schemas
isDeleted = true; isDeleted = true;
} }
public SchemaDomainObject AddField(AddField command) public SchemaDomainObject Create(CreateSchema command)
{ {
Guard.Valid(command, nameof(command), () => $"Cannot add field to schema {Id}"); Guard.Valid(command, nameof(command), () => "Cannot create schema");
VerifyCreatedAndNotDeleted(); VerifyNotCreated();
RaiseEvent(SimpleMapper.Map(command, new FieldAdded { FieldId = new NamedId<long>(totalFields + 1, command.Name) })); var @event = SimpleMapper.Map(command, new SchemaCreated { SchemaId = new NamedId<Guid>(Id, command.Name) });
if (command.Fields != null)
{
@event.Fields = new List<SchemaCreatedField>();
foreach (var commandField in command.Fields)
{
var eventField = SimpleMapper.Map(commandField, new SchemaCreatedField());
@event.Fields.Add(eventField);
}
}
RaiseEvent(@event);
return this; return this;
} }
public SchemaDomainObject UpdateField(UpdateField command) public SchemaDomainObject AddField(AddField command)
{ {
Guard.Valid(command, nameof(command), () => $"Cannot update schema '{Id}'"); Guard.Valid(command, nameof(command), () => $"Cannot add field to schema {Id}");
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(command, SimpleMapper.Map(command, new FieldUpdated())); RaiseEvent(SimpleMapper.Map(command, new FieldAdded { FieldId = new NamedId<long>(totalFields + 1, command.Name) }));
return this; return this;
} }
public SchemaDomainObject Create(CreateSchema command) public SchemaDomainObject UpdateField(UpdateField command)
{ {
Guard.Valid(command, nameof(command), () => "Cannot create schema"); Guard.Valid(command, nameof(command), () => $"Cannot update schema '{Id}'");
VerifyNotCreated(); VerifyCreatedAndNotDeleted();
RaiseEvent(SimpleMapper.Map(command, new SchemaCreated { SchemaId = new NamedId<Guid>(Id, command.Name) })); RaiseEvent(command, SimpleMapper.Map(command, new FieldUpdated()));
return this; return this;
} }

Loading…
Cancel
Save