public LogSearchResult Logs([FromBody] SearchParameters searchData)
        {
            LogSearchResult objLogSearchResult = new LogSearchResult();

            objLogSearchResult.LogList = new List <DTOLog>();

            // Must be a Super Administrator to call this Method
            if (!UtilitySecurity.IsSuperUser(this.User.Identity.Name, GetConnectionString()))
            {
                objLogSearchResult.errorMessage = "Must be a Super Administrator to call this Method";
                return(objLogSearchResult);
            }

            var optionsBuilder = new DbContextOptionsBuilder <ADefHelpDeskContext>();

            optionsBuilder.UseSqlServer(GetConnectionString());

            using (var context = new ADefHelpDeskContext(optionsBuilder.Options))
            {
                int intTaskId = Convert.ToInt32(searchData.searchString);

                var QueryResult = (from Log in context.AdefHelpDeskLog
                                   where Log.TaskId == intTaskId
                                   select Log).OrderByDescending(l => l.LogId)
                                  .Skip(searchData.rowsPerPage * (searchData.pageNumber - 1))
                                  .Take(searchData.rowsPerPage).ToList();

                List <DTOLog> colDTOLog = new List <DTOLog>();

                foreach (var item in QueryResult)
                {
                    // Get user
                    DTOUser objDTOUSer = UtilitySecurity.UserFromUserId(item.UserId, GetConnectionString());

                    // Create Log
                    DTOLog objDTOLog = new DTOLog();

                    objDTOLog.LogID          = item.LogId;
                    objDTOLog.TaskID         = item.TaskId;
                    objDTOLog.LogDescription = item.LogDescription;
                    objDTOLog.UserName       = (objDTOUSer != null) ? objDTOUSer.userName : "******";
                    objDTOLog.DateCreated    = item.DateCreated.ToShortDateString() + ' ' + item.DateCreated.ToShortTimeString();

                    colDTOLog.Add(objDTOLog);
                }

                objLogSearchResult.LogList      = colDTOLog;
                objLogSearchResult.totalRows    = context.AdefHelpDeskLog.Where(x => x.TaskId == intTaskId).Count();
                objLogSearchResult.errorMessage = string.Empty;
            }

            return(objLogSearchResult);
        }
예제 #2
0
        private void Loga()
        {
            this.BloqueioTela(Convert.ToInt32(0));
            frmLogin log = new frmLogin();

            log.ShowDialog();
            log.Dispose();


            int idusuario = 0;
            int idunidade = 0;
            int nvusuario = 0;

            try
            {
                idusuario = Convert.ToInt32(log.IdUsuarioLogado);
            }
            catch { }

            try
            {
                idunidade = Convert.ToInt32(log.UnidadeUsuarioLogado);
            }
            catch { }

            try
            {
                nvusuario = Convert.ToInt32(log.NvUsuarioLogado);
            }
            catch { }

            if (idusuario.ToString() != "")
            {
                #region Se Login Adm
                if (log.IdUsuarioLogado == -1)
                {
                    txtId.Text          = idusuario.ToString();
                    txtUsuario.Text     = "Administrador";
                    txtLogin.Text       = "Admin";
                    txtSenha.Text       = "";
                    txtIniciais.Text    = "Adm";
                    txtUnidade.Text     = "99";
                    txtPermissao.Text   = "4";
                    txtEmail.Text       = "";
                    txtNomeUnidade.Text = "Admin";

                    this.PreencheCampos();
                }

                #endregion

                #region Se login normal

                else
                {
                    txtId.Text          = idusuario.ToString();
                    txtUsuario.Text     = log.NomeUsuarioLogado.ToString();
                    txtLogin.Text       = log.LoginUsuarioLogado.ToString();
                    txtSenha.Text       = log.SenhaUsuarioLogado.ToString();
                    txtIniciais.Text    = log.IniciaisUsuarioLogado.ToString();
                    txtUnidade.Text     = idunidade.ToString();
                    txtPermissao.Text   = nvusuario.ToString();
                    txtEmail.Text       = log.EmailUsuarioLogado.ToString();
                    txtNomeUnidade.Text = log.NomeUnidade.ToString();

                    this.PreencheCampos();

                    //Se login automático salva ip
                    DTOLog     dtolog = new DTOLog();
                    DALConexao cx     = new DALConexao(DadosDaConexao.StringDaConexao);
                    BLLLog     blllog = new BLLLog(cx);

                    if (log.LembrarSenha != "")
                    {
                        try
                        {
                            try
                            {
                                blllog.Excluir(Convert.ToInt32(txtId.Text), log.LembrarSenha);
                            }
                            catch
                            {}
                            finally
                            {
                                dtolog.IdUsuario = Convert.ToInt32(txtId.Text);
                                dtolog.CodLog    = log.LembrarSenha;
                                blllog.Incluir(dtolog);
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Erro ao salvar suas credenciais.");
                        }
                    }
                }
                #endregion

                log = null;
            }
        }