Ejemplo n.º 1
0
        public IActionResult DeleteCountry(int stepId)
        {
            if (!_stepRepository.StepExists(stepId))
            {
                return(NotFound());
            }

            var stepToDelete = _stepRepository.GetStep(stepId);

            if (_stepRepository.GetRecipeOfAStep(stepId) != null)
            {
                ModelState.AddModelError("", $"Step cannot be deleted because there is a recipe linked to it");
                return(StatusCode(409, ModelState)); //409 = conflict
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_stepRepository.DeleteStep(stepToDelete))
            {
                ModelState.AddModelError("", $"Something went wrong deleting this step");
                return(StatusCode(500, ModelState));
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> DeleteInstr(string[] id)
        {
            await repositoryInstr.DeleteInstr(id);

            List <string> str = new List <string>();

            foreach (var item in id)
            {
                str.Add(repositoryStep.Steps.Where(x => x.InstructionId == item).First().StepId);
            }
            await repositoryStep.DeleteStep(str.ToArray());

            return(Redirect("instruction/myinstructions"));
        }