Ejemplo n.º 1
0
        public IActionResult Put(int id, [FromBody] UpdateStageViewModel updateStageViewModel)
        {
            return(ApiAction(() =>
            {
                var contract = _mapper.Map <UpdateStageContract>(updateStageViewModel);
                contract.Id = id;

                _processStageService.Update(contract);

                return Accepted();
            }));
        }
Ejemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        public IActionResult EditBusinessFlow([FromBody] EditWorkFlowModel model)
        {
            string msg = string.Empty;

            if (model.StepData.IsEmpty())
            {
                ModelState.AddModelError("", T["workflow_step_empty"]);
            }
            model.StepData = model.StepData.UrlDecode();
            List <ProcessStage> steps = new List <ProcessStage>();

            steps = steps.DeserializeFromJson(model.StepData);
            if (steps.IsEmpty())
            {
                ModelState.AddModelError("", T["workflow_step_empty"]);
            }
            if (ModelState.IsValid)
            {
                var entity = _workFlowFinder.FindById(model.WorkFlowId);
                model.EntityId  = entity.EntityId;
                model.StateCode = entity.StateCode;
                model.CopyTo(entity);

                _workFlowUpdater.Update(entity);
                var orginalSteps = _processStageService.Query(n => n.Where(f => f.WorkFlowId == model.WorkFlowId).Sort(s => s.SortAscending(f => f.StageOrder)));
                foreach (var item in steps)
                {
                    item.WorkFlowId = entity.WorkFlowId;
                    var old = orginalSteps.Find(n => n.ProcessStageId == item.ProcessStageId);
                    if (old == null)
                    {
                        _processStageService.Create(item);
                    }
                    else
                    {
                        _processStageService.Update(item);
                        orginalSteps.Remove(old);
                    }
                }
                if (orginalSteps.NotEmpty())
                {
                    var lostid = orginalSteps.Select(n => n.ProcessStageId).ToArray();
                    _processStageService.DeleteById(lostid);
                }
                return(UpdateSuccess());
            }
            return(UpdateFailure(GetModelErrors()));
        }