コード例 #1
0
        private static async Task <Category> GetCategoryAsync(IPersistenceService persistence, int userId, string name)
        {
            var category = await
                           persistence.GetEntitySet <Category>()
                           .SingleOrDefaultAsync(c => c.UserId == userId && c.Name == name);

            if (category == null)
            {
                throw new ValidationErrorException("Category with '{0}' name does not exist.", name);
            }

            return(category);
        }
コード例 #2
0
        private async static Task <Transaction> GetTransactionAsync(IPersistenceService persistence, string id, int categoryId)
        {
            Guid guid;

            if (!Guid.TryParseExact(id, "N", out guid))
            {
                throw new ValidationErrorException("Transaction ID has invalid format.");
            }

            var transaction = await
                              persistence.GetEntitySet <Transaction>()
                              .SingleOrDefaultAsync(t => t.Id == guid && t.CategoryId == categoryId);

            if (transaction == null)
            {
                throw new ValidationErrorException("Transaction with '{0}' ID does not exist.", id);
            }

            return(transaction);
        }