protected override async Task <bool> WriteIntoAsync(ProductPurchase target, ProductPurchasePayload source) { var frontendUser = await _frontendUserRepository.TryFindAsync(source.FrontendUserId); var product = await _productRepository.TryFindAsync(source.ProductId); if (frontendUser == null || product == null) { return(false); } target.Accountable = frontendUser; target.Entity = product; target.KarmaEarned = product.Amount; product.Amount = 0; await _productRepository.Save(product); await _frontendUserRepository.RecalculateKarma <ProductPurchase, Product>(frontendUser, target); return(true); }
protected override async Task <bool> WriteIntoAsync(TaskExecution target, TaskExecutionPayload source) { var frontendUser = await _frontendUserRepository.TryFindAsync(source.FrontendUserId); var taskTemplate = await _taskTemplateRepository.TryFindAsync(source.TaskTemplateId); if (frontendUser == null || taskTemplate == null) { return(false); } target.Accountable = frontendUser; target.Entity = taskTemplate; target.KarmaEarned = taskTemplate.Reward; taskTemplate.LastExecutionAt = DateTime.Now; await _taskTemplateRepository.Save(taskTemplate); await _frontendUserRepository.RecalculateKarma <TaskExecution, TaskTemplate>(frontendUser, target); return(true); }