Ejemplo n.º 1
0
        public async Task <ActionResult> StartUpdate(LogUpdate updateChecklist)
        {
            var checklist = await _repo.UpdateExists(updateChecklist);

            if (checklist != null)
            {
                return(BadRequest($"{updateChecklist.Process} {updateChecklist.SiteKml} already exists. Please Try again"));
            }
            updateChecklist.StartTime = DateTime.Now;
            updateChecklist.Status    = "In Progress";
            _repo.Add(updateChecklist);
            var steps = await _repo.GetSteps(updateChecklist.Idchecklist, updateChecklist.Version);

            foreach (var s in steps)
            {
                var step = new LogUpdateSteps
                {
                    Step     = s.Step,
                    StepText = s.StepText,
                    Title    = s.Title,
                    Idupdate = updateChecklist.Idupdate
                };

                _repo.Add(step);
            }
            if (await _repo.SaveAll())
            {
                return(CreatedAtAction("GetUpdate", new { id = updateChecklist.Idupdate }, updateChecklist));
            }

            return(BadRequest("Failed to Create Update"));
        }