コード例 #1
0
        public HttpResponseMessage Inserir(HttpRequestMessage request, workflowStatusViewModel workflowStatusViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                                      .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    Usuario usuario = _usuarioRep.GetSingle(int.Parse(HttpContext.Current.User.Identity.GetUserId()));

                    WorkflowStatus novoStatus = new WorkflowStatus()
                    {
                        UsuarioCriacao = usuario,
                        DtCriacao = DateTime.Now,
                        DescWorkslowStatus = workflowStatusViewModel.DescWorkslowStatus,
                        Ativo = workflowStatusViewModel.Ativo
                    };
                    _workflowStatus.Add(novoStatus);

                    _unitOfWork.Commit();

                    // Update view model
                    workflowStatusViewModel = Mapper.Map <WorkflowStatus, workflowStatusViewModel>(novoStatus);
                    response = request.CreateResponse(HttpStatusCode.Created, workflowStatusViewModel);
                }

                return response;
            }));
        }
コード例 #2
0
        public HttpResponseMessage Atualizar(HttpRequestMessage request, workflowStatusViewModel workflowStatusViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                                      .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    WorkflowStatus novoStatus = _workflowStatus.GetSingle(workflowStatusViewModel.Id);

                    Usuario usuario = _usuarioRep.GetSingle(int.Parse(HttpContext.Current.User.Identity.GetUserId()));
                    if (novoStatus.StatusSistemas.Count > 0 && workflowStatusViewModel.Ativo == false)
                    {
                        return request.CreateErrorResponse(HttpStatusCode.PreconditionFailed, "Workflow utilizado em algum status, não é possível ser desativado");
                    }
                    else
                    {
                        novoStatus.AtualizarWorkflowStatus(workflowStatusViewModel, usuario);
                    }

                    _unitOfWork.Commit();

                    // Update view model
                    workflowStatusViewModel = Mapper.Map <WorkflowStatus, workflowStatusViewModel>(novoStatus);
                    response = request.CreateResponse(HttpStatusCode.OK, workflowStatusViewModel);
                }

                return response;
            }));
        }
コード例 #3
0
 public static void AtualizarWorkflowStatus(this WorkflowStatus workflowStatus, workflowStatusViewModel workflowStatusVM, Usuario usuario)
 {
     workflowStatus.UsuarioAlteracao   = usuario;
     workflowStatus.Ativo              = workflowStatusVM.Ativo;
     workflowStatus.DescWorkslowStatus = workflowStatusVM.DescWorkslowStatus;
     workflowStatus.DtAlteracao        = DateTime.Now;
 }