Beispiel #1
0
        /// <summary>
        /// Method to add a cooking instruction to the database if valid
        /// </summary>
        /// <param name="name">The name of the instruction</param>
        /// <param name="instruction">The cooking instructions</param>
        /// <returns></returns>
        public async Task AddCookingInstructionAsync(TextBox name, TextBox instruction)
        {
            var isNameValid        = ValidationObject.ValidateInstructionName(name);
            var isInstructionValid = ValidationObject.ValidateInstruction(instruction);

            var added = true;

            if (isNameValid && isInstructionValid)
            {
                var cookingInstructionToAdd = new CookingInstructionDTO()
                {
                    Name        = name.Text,
                    Instruction = instruction.Text
                };

                added = await Task.Run(() => BusinessObject.AddCookingInstructionAsync(cookingInstructionToAdd));

                if (added)
                {
                    ShowMessage($"Cooking Instruction {cookingInstructionToAdd.Name} Added");
                    name.Clear();
                    instruction.Clear();
                }
                else
                {
                    ShowMessage($"Cooking Instruction {cookingInstructionToAdd.Name} Not Added");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Method to convert a cooking instruction to an entity class so it can be added to the database
        /// </summary>
        /// <param name="instruction">The instruction to be converted</param>
        /// <returns>An instance of the Cooking Instruction entity</returns>
        private Entities.CookingInstruction CreateInstructionEntity(CookingInstructionDTO instruction)
        {
            var instructionEntity = new Entities.CookingInstruction()
            {
                Name        = instruction.Name,
                Instruction = instruction.Instruction
            };

            return(instructionEntity);
        }
Beispiel #3
0
        /// <summary>
        /// Method to delete a cooking instruction from the database
        /// </summary>
        /// <param name="instructionid">The id of the cooking instruction to be deleted</param>
        /// <returns>True if the cooking instruction was deleted</returns>
        public async Task <bool> DeleteCookingInstructionAsync(CookingInstructionDTO instruction)
        {
            var deleted = true;

            try
            {
                await Task.Run(() => cookingInstructionRepository.DeleteCookingInstruction(instruction.CookingInstructionId));
            }
            catch (Exception ex)
            {
                deleted = false;
            }


            return(deleted);
        }
Beispiel #4
0
        /// <summary>
        /// Method to add a cooking instruction
        /// </summary>
        /// <param name="instruction">The recipe to be added</param>
        /// <returns>True if it was added</returns>
        public async Task <bool> AddCookingInstructionAsync(CookingInstructionDTO instruction)
        {
            var isAdded = true;

            try
            {
                var instructionToBeAdded = CreateInstructionEntity(instruction);
                await Task.Run(() => cookingInstructionRepository.Add(instructionToBeAdded));
            }
            catch (Exception ex)
            {
                isAdded = false;
                // TODO:Add logging
            }

            return(isAdded);
        }
Beispiel #5
0
        /// <summary>
        /// Method to add a cooking instruction to a recipe
        /// </summary>
        /// <param name="recipe">The recipe to add the cooking instruction to</param>
        /// <param name="instruction">The cooking instruction to add to the recipe</param>
        /// <returns></returns>
        public async Task <bool> AddCookingInstructionToRecipeAsync(RecipeDTO recipe, CookingInstructionDTO instruction)
        {
            var added = true;

            try
            {
                await Task.Run(() => cookingInstructionRepository.AssignCookingInstructionsToRecipe(recipe.RecipeId, instruction.CookingInstructionId));
            }
            catch (Exception ex)
            {
                added = false;
            }

            return(added);
        }