Ejemplo n.º 1
0
        public IActionResult CreateStep([FromBody] Step stepToCreate)
        {
            if (stepToCreate == null)
            {
                return(BadRequest(ModelState));
            }



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

            if (!_stepRepository.CreateStep(stepToCreate))
            {
                ModelState.AddModelError("", $"Something went wrong saving this step");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetStep", new { countryId = stepToCreate.Id }, stepToCreate));
        }
Ejemplo n.º 2
0
        public ActionResult Create(string instrName, string instrDescription, string[] stepName, string[] stepDescription, string tags, string[] imageUrl)
        {
            repositoryInstr.CreateInstr(instrName, instrDescription, _userManager.FindByNameAsync(User.Identity.Name).Result.Id);
            var instruction = context.Instructions.Where(x => x.Name == instrName).FirstOrDefault();

            if (imageUrl.Length == 0)
            {
                imageUrl = new string[] { "", "", "", "" };
            }
            if (tags.Length == 0)
            {
                tags = "Инструкции";
            }
            foreach (var item in tags.Split(","))
            {
                repositoryTag.CreateTag(item, instruction.InstructionId);
            }
            for (int i = 0; i < stepName.Length; i++)
            {
                repositoryStep.CreateStep(stepName[i], stepDescription[i], i.ToString(), instruction.InstructionId, imageUrl[i]);
            }
            return(Redirect("home/index"));
        }