Ejemplo n.º 1
0
        public IActionResult Post([FromBody] CreateProcessViewModel createProcessViewModel)
        {
            return(ApiAction(() =>
            {
                var contract = _mapper.Map <CreateProcessContract>(createProcessViewModel);
                var returnContract = _processService.Create(contract);

                return Created("Get", _mapper.Map <CreatedProcessViewModel>(returnContract));
            }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(CreateProcessViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var settings = JsonConvert.DeserializeObject <IEnumerable <Dictionary <string, string> > >(model.DiagramSettings);

            _processParser.Init(model.Diagram, settings);
            var processes = _processParser.GetProcesses().ToList();

            if (!processes.Any())
            {
                ModelState.AddModelError(string.Empty, "No identified processes in your diagram, try to modify as system standard");
                return(View(model));
            }

            var newProcessDiagram = new STProcessSchema
            {
                Changed    = DateTime.Now,
                Created    = DateTime.Now,
                ModifiedBy = User.Identity.Name,
                Title      = model.Title,
                Diagram    = model.Diagram.Replace("'+'", string.Empty),
                Author     = _applicationDbContext.Users.Single(x => x.UserName.Equals(User.Identity.Name)).UserName
            };

            try
            {
                await Context.ProcessSchemas.AddAsync(newProcessDiagram);

                foreach (var process in processes)
                {
                    process.ProcessSchema = newProcessDiagram;
                }
                await Context.Processes.AddRangeAsync(processes);

                await Context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(View(model));
            }

            return(RedirectToAction(nameof(Index)));
        }