protected override async Task <bool> TryBuildCommand(ICommandUpdateCore <TMolde> command, RequestContextCore Context) { var oldEntity = await GetOldEntityAsync(command); if (oldEntity == null) { command.Messages.Add(Constants.CommonMessages.THE_ITEM_DOES_NOT_EXIST); return(false); } var newEntity = await CreateNewEntityAsync(oldEntity, command); Entity.UpdateWithContext(Context, newEntity); if (command.Model is INotifiable) { var notifyobject = (INotifiable)command.Model; command.Notifications.Add(notifyobject.Notification); } return(true); }
protected virtual async Task <TEntity> CreateNewEntityAsync(TEntity oldEntity, ICommandUpdateCore <TMolde> command) { var createdAt = oldEntity.CreatedAt; var entity = Mapper.Map(command.Model, oldEntity); entity.CreatedAt = createdAt; return(entity); }
protected virtual async Task <TEntity> GetOldEntityAsync(ICommandUpdateCore <TMolde> command) { return(await Entity.FindAsync(command.Model.Id)); }