public HttpResponseMessage Deletar(HttpRequestMessage request, StatusSistemaViewModel StatusSistemaVM)
        {
            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
                {
                    StatusSistema novoStatus = _statusSistema.GetSingle(StatusSistemaVM.Id);

                    Usuario usuario = _usuarioRep.GetSingle(int.Parse(HttpContext.Current.User.Identity.GetUserId()));
                    _statusSistema.Delete(novoStatus);

                    _unitOfWork.Commit();

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

                return response;
            }));
        }
 public static void AtualizarStatusSistema(this StatusSistema Status, StatusSistemaViewModel StatusVM, Usuario usuario)
 {
     Status.UsuarioAlteracao = usuario;
     Status.Ativo            = StatusVM.Ativo;
     Status.DescStatus       = StatusVM.DescStatus;
     Status.Ordem            = StatusVM.Ordem;
     Status.WorkflowStatusId = StatusVM.WorkflowStatusId;
     Status.DtAlteracao      = DateTime.Now;
 }
        public HttpResponseMessage Inserir(HttpRequestMessage request, StatusSistemaViewModel statusSistemaViewModel)
        {
            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()));

                    StatusSistema novoStatusSistema = new StatusSistema()
                    {
                        UsuarioCriacao = usuario,
                        DtCriacao = DateTime.Now,
                        Ativo = statusSistemaViewModel.Ativo,
                        DescStatus = statusSistemaViewModel.DescStatus,
                        Ordem = statusSistemaViewModel.Ordem,
                        WorkflowStatusId = statusSistemaViewModel.WorkflowStatusId
                    };
                    _statusSistema.Add(novoStatusSistema);

                    _unitOfWork.Commit();

                    // Update view model
                    statusSistemaViewModel = Mapper.Map <StatusSistema, StatusSistemaViewModel>(novoStatusSistema);
                    response = request.CreateResponse(HttpStatusCode.Created, statusSistemaViewModel);
                }

                return response;
            }));
        }