public IActionResult UpdateStep(int stepId, [FromBody] Step updatedStepInfo) { if (updatedStepInfo == null) { return(BadRequest(ModelState)); } if (stepId != updatedStepInfo.Id) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_stepRepository.UpdateStep(updatedStepInfo)) { ModelState.AddModelError("", $"Something went wrong updating this step"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public async Task <ActionResult> Update(string instrName, string instrDescription, string[] stepName, string[] stepDescription, string[] imageUrl, string instrId) { await repositoryInstr.UpdateInstr(instrName, instrDescription, _userManager.FindByNameAsync(User.Identity.Name).Id.ToString(), instrId); var instruction = context.Instructions.Where(x => x.Name == instrName).Single(); for (int i = 0; i < stepName.Length; i++) { await repositoryStep.UpdateStep(stepName[i], stepDescription[i], i.ToString(), instruction.InstructionId, imageUrl[i]); } return(Redirect("instruction/myinstructions")); }
public bool Process(StepContext stepContext, IStepRepository stepRepository) { bool success = true; StepContext ctx = StepContext.InitialRun(stepContext, _chunkSize); while (ctx.HasNext) { long newStepId = stepRepository.InsertStep(ctx.StepName, ctx.NextStepIndex); bool exceptionThrown = false; bool skip = false; bool error = false; List <TInput> items = Enumerable.Empty <TInput>().ToList(); TOutput[] processed = Enumerable.Empty <TOutput>().ToArray(); try { items = _reader.Read(ctx.StepIndex, _chunkSize).ToList(); processed = items.Select(item => _processor.Process(item)).ToArray(); if (processed.Any()) { success &= _writer.Write(processed); } } catch (Exception ex) { error = true; skip = _skipPolicy.IsSatisfiedBy(stepRepository, new SkipContext(ctx.StepName, ctx.NextStepIndex, ex)); if (!skip) { exceptionThrown = true; throw; } } finally { if (!exceptionThrown) { ctx = StepContext.Increment(ctx, items.Count, processed.Length, skip); } stepRepository.UpdateStep(newStepId, processed.Length, error, skip); } } return(success); }