public IHttpActionResult GetDashboard() { DateTime time = db.Logs.Where(c => c.UserType == "ADM" && c.UserId == "Admin" && c.Link == "http://localhost:42640/Admin/Logout").OrderByDescending(b => b.Time).Select(item => item.Time).FirstOrDefault(); int students = db.Students.Where(item => item.RegTime >= time).Count(); int companies = db.Companies.Where(item => item.RegTime >= time).Count(); int projects = db.Projects.Where(item => item.CreatedDate >= time).Count(); int internships = db.Internships.Where(item => item.CreatedDate >= time).Count(); ADashboard ad = new ADashboard(); ad.CountMsgs = db.Contacts.Where(item => item.Read == false).Count(); ad.CountUsers = students + companies; ad.CountPosts = projects + internships; return(Ok(ad)); }
private void loginLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (txtMail.Text == "" || txtPass.Text == "") { MessageBox.Show("Please provide UserName and Password"); return; } try { //Create SqlConnection SqlConnection con = new SqlConnection(cs); SqlCommand cmd = new SqlCommand("Select * from AdminDetails where a_mail=@a_mail and a_password=@a_password", con); cmd.Parameters.AddWithValue("@a_mail", txtMail.Text); cmd.Parameters.AddWithValue("@a_password", txtPass.Text); con.Open(); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapt.Fill(ds); con.Close(); int count = ds.Tables[0].Rows.Count; //If count is equal to 1, than show frmMain form if (count == 1) { MessageBox.Show("Login Successful!"); Form f1 = new ADashboard(); f1.Show(); loginLabel.LinkVisited = true; this.Hide(); f1.Closed += (s, args) => this.Close(); } else { MessageBox.Show("Login Failed!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async Task <ActionResult> Dashboard() { if (!Session["user_type"].Equals("ADM")) { return(RedirectToAction("../Home/Index")); } int CountSessions = ((int)HttpContext.Application["SessionsCount"]) - 1; ADashboard DashboardInfo = new ADashboard(); using (var client = new HttpClient()) { //Passing service base url client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); //Define request data format client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Sending request to find web api REST service resource GetAllEmployees using HttpClient HttpResponseMessage Res = await client.GetAsync("api/adminAPI/Dashboard"); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var DashboardResponse = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list DashboardInfo = JsonConvert.DeserializeObject <ADashboard>(DashboardResponse); } DashboardInfo.CountSessions = CountSessions; return(View(DashboardInfo)); } }
public async Task <ActionResult> DashboardPost() { if (!Session["user_type"].Equals("ADM")) { return(RedirectToAction("../Home/Index")); } int CountSessions = ((int)HttpContext.Application["SessionsCount"]) - 1; ADashboard DashboardInfo = new ADashboard(); using (var client = new HttpClient()) { //Passing service base url client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); //Define request data format client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Sending request to find web api REST service resource GetAllEmployees using HttpClient HttpResponseMessage Res = await client.GetAsync("api/adminAPI/Dashboard"); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var DashboardResponse = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list DashboardInfo = JsonConvert.DeserializeObject <ADashboard>(DashboardResponse); } DashboardInfo.CountSessions = CountSessions; } if (string.IsNullOrWhiteSpace(Request.Form["query"])) { DashboardInfo.Error = "Empty Query"; return(View(DashboardInfo)); } else { DashboardInfo.Query = Request.Form["query"]; } if (!DashboardInfo.Query.ToUpper().StartsWith(Request.Form["type"])) { DashboardInfo.Error = "QUERY NOT OF PROPER TYPE"; return(View(DashboardInfo)); } string constring = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(constring); SqlCommand cmd = new SqlCommand(DashboardInfo.Query, con); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); if (Request.Form["type"].Equals("SELECT")) { try { con.Open(); adapter.Fill(ds, "MyTable"); con.Close(); DashboardInfo.data = ds.Tables["MyTable"]; } catch (Exception e) { DashboardInfo.Error = e.Message; } } else { try { con.Open(); DashboardInfo.Msg = (cmd.ExecuteNonQuery()).ToString(); con.Close(); } catch (Exception e) { DashboardInfo.Error = e.Message; } } AdminQuery aq = new AdminQuery(); aq.Query = DashboardInfo.Query; aq.Time = System.DateTime.Now; db.AdminQueries.Add(aq); db.SaveChanges(); return(View(DashboardInfo)); }