Esempio 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);
        }
Esempio n. 2
0
        public async Task <NotificationResult> CreateShoplistWithIngredients(InsertShoplistWithIngredientsCommand command)
        {
            var result = new NotificationResult();
            var item   = new ShoplistInfo(command);

            result.Add(item.GetNotificationResult());
            if (!result.IsValid)
            {
                return(result);
            }
            result.Add(await _shoplistRepository.InsertAsync(item));
            if (result.IsValid)
            {
                result.Data = item.Id;

                /*
                 * foreach (var shoplistItem in command.ShoplistsIngredients)
                 * {
                 *  shoplistItem.SetId(item.Id.Value);
                 *  await _shoplistIngredientRepository.InsertAsync(shoplistItem);
                 * }*/

                result.AddMessage(Shared.Domain.Resources.Handler.InsertSuccess_Message);
            }
            else
            {
                result.AddErrorOnTop(Shared.Domain.Resources.Handler.InsertError_Message);
            }
            return(result);
        }
        public virtual async Task <NotificationResult> DeleteByIdAsync(int id)
        {
            var result = new NotificationResult();

            result.Add(await _ingredientRepository.DeleteByIdAsync(id));
            if (result.IsValid)
            {
                result.AddMessage(Shared.Domain.Resources.Handler.DeleteSuccess_Message);
            }
            else
            {
                result.AddErrorOnTop(Shared.Domain.Resources.Handler.DeleteError_Message);
            }
            return(result);
        }
        public virtual async Task <NotificationResult> InsertAsync(InsertIngredientCommand command)
        {
            var result = new NotificationResult();
            var item   = new IngredientInfo(command);

            result.Add(item.GetNotificationResult());
            if (!result.IsValid)
            {
                return(result);
            }
            result.Add(await _ingredientRepository.InsertAsync(item));
            if (result.IsValid)
            {
                result.Data = item.Id;
                result.AddMessage(Shared.Domain.Resources.Handler.InsertSuccess_Message);
            }
            else
            {
                result.AddErrorOnTop(Shared.Domain.Resources.Handler.InsertError_Message);
            }
            return(result);
        }
Esempio n. 5
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);
        }