Exemplo n.º 1
0
        public virtual async Task <NotificationResult> InsertAsync(InsertRecipeCommand command)
        {
            var result = new NotificationResult();
            var item   = new RecipeInfo(command);

            result.Add(item.GetNotificationResult());
            if (!result.IsValid)
            {
                return(result);
            }
            result.Add(await _recipeRepository.InsertAsync(item));

            if (result.IsValid)
            {
                if (command.RecipeIngredients != null && command.RecipeIngredients.Count > 0)
                {
                    foreach (var recipeIngredientCommand in command.RecipeIngredients)
                    {
                        var recipeIngredient = new RecipeIngredientInfo(recipeIngredientCommand);
                        recipeIngredient.SetRecipeId(item.Id.Value);
                        result.Add(await _recipeIngredientRepository.InsertAsync(recipeIngredient));
                    }
                }

                result.Data = item.Id;
                result.AddMessage(Shared.Domain.Resources.Handler.InsertSuccess_Message);
            }
            else
            {
                result.AddErrorOnTop(Shared.Domain.Resources.Handler.InsertError_Message);
            }
            return(result);
        }
Exemplo n.º 2
0
        public virtual async Task <NotificationResult> UpdateAsync(UpdateRecipeCommand command)
        {
            var result = new NotificationResult();
            var item   = new RecipeInfo(command);

            result.Add(item.GetNotificationResult());
            if (!result.IsValid)
            {
                return(result);
            }
            result.Add(await _recipeRepository.UpdateAsync(item));
            if (result.IsValid)
            {
                result.Data = item.Id;
                result.AddMessage(Shared.Domain.Resources.Handler.UpdateSuccess_Message);
            }
            else
            {
                result.AddErrorOnTop(Shared.Domain.Resources.Handler.UpdateError_Message);
            }

            return(result);
        }