コード例 #1
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)));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(STProcessSchema model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            model.ModifiedBy = User.Identity.Name;
            model.Changed    = DateTime.Now;
            try
            {
                Context.ProcessSchemas.Update(model);
                await Context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(View(model));
            }

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