Esempio n. 1
0
        public async Task <Guid> Create(Guid plantId, CreatePlantEventModel model)
        {
            Plant plant = await _database.Plants.FindAsync(plantId);

            if (plant is null)
            {
                throw new PlantNotFoundException(plantId);
            }

            if (EventOccuredBeforePlantedOrInTheFuture(plant, model.Occured))
            {
                throw new EventOccurenceDateBeforePlantDateOrInTheFutureException();
            }

            if (model.Type.IsCreationRestricted())
            {
                throw new EventTypeIsCreationRestrictedException(model.Type);
            }

            Event @event = plant.AddEvent(model.Type, model.Description, model.Occured);

            _database.Plants.Update(plant);
            await _database.SaveAsync();

            return(@event.Id);
        }
Esempio n. 2
0
        public static Event DomainModel(Plant plant = null, EventType type = EventType.Fungi, DateTime?occured = null)
        {
            Plant eventOwner = plant ?? Plants.ModelFactory.DomainModel();

            return(eventOwner.AddEvent(type, "Spotted some fungi on the leaves.", occured ?? DateTime.Now));
        }
Esempio n. 3
0
 protected override Event CreateDomainObject() =>
 _eventOwnerPlant.AddEvent(EventType.Disease, "Spotted some brown leaves.");