public async Task <IHttpActionResult> GetActionLogDetails(AuthBaseModel authBaseModel) { if (authBaseModel == null) { return(BadRequest("Please provide valid inputs!")); } if (string.IsNullOrEmpty(authBaseModel.Location)) { return(BadRequest("Please provide valid location!")); } if (await AuthService.ValidateUserAndToken(authBaseModel.Token, authBaseModel.UserID, authBaseModel.Email, authBaseModel.Location)) { var actionLogs = await AdminService.GetActionLogDetails(authBaseModel); if (actionLogs.Count > 0) { return(Ok(actionLogs)); } else { return(BadRequest("No ActionLogs Available!")); } } else { return(Unauthorized()); } }
public IHttpActionResult ConsolidateVotes(AuthBaseModel loggedInUser) { if (loggedInUser == null) { return(BadRequest("Please provide valid inputs!")); } if (string.IsNullOrEmpty(loggedInUser.Location)) { return(BadRequest("Please provide valid location!")); } var finalCount = AdminService.ConsolidateVotes(loggedInUser); CommonResponse response = AdminService.RecordConsolidatedVotes(loggedInUser, finalCount); if (!response.IsError) { return(Ok("Consolidated All The Votes")); } else { return(BadRequest("Something Went Wrong! Failed To Consolidate All The Votes!")); } }
public async Task <IHttpActionResult> GetTotalBallotCount(AuthBaseModel authBaseModel) { if (authBaseModel == null) { return(BadRequest("Please provide valid inputs!")); } if (string.IsNullOrEmpty(authBaseModel.Location)) { return(BadRequest("Please provide valid location!")); } if (await AuthService.ValidateUserAndToken(authBaseModel.Token, authBaseModel.UserID, authBaseModel.Email, authBaseModel.Location)) { var ballots = await AdminService.GetTotalBallotCount(authBaseModel); if (ballots.Count > 0) { return(Ok(ballots)); } else { return(BadRequest("No Candidates Exists!")); } } else { return(Unauthorized()); } }
// public static string conString = selectConnection("colombo"); /// <summary> /// Service Method To Get The Total Ballot Count /// </summary> /// <param name="authBaseModel"></param> /// <returns></returns> public static async Task <List <TotalBallotModel> > GetTotalBallotCount(AuthBaseModel authBaseModel) { List <TotalBallotModel> TotalBallots = new List <TotalBallotModel>(); using (SqlConnection dbConn = new SqlConnection(selectConnection(authBaseModel.Location))) { var Query = "SELECT CandidateID, COUNT(Voted) AS TotalNoOfVotes FROM Ballot WHERE Voted = 1 GROUP BY CandidateID ORDER BY TotalNoOfVotes DESC"; SqlDataReader reader; try { dbConn.Open(); SqlCommand cmd = new SqlCommand(Query, dbConn); reader = await cmd.ExecuteReaderAsync(); if (reader.HasRows) { while (reader.Read()) { TotalBallotModel Ballots = new TotalBallotModel(); Ballots.CandidateID = reader.GetInt32(0); Ballots.TotalNoOfVotes = reader.GetInt32(1); Ballots.DateTallied = DateTime.Now; TotalBallots.Add(Ballots); } } } catch (Exception ex) { reader = null; ActionLogService.LogAction(new ActionLogModel() { UserID = authBaseModel.UserID, ActionPerformed = "Get Total Ballot Count Error : " + ex.Message, MethodName = "GetTotalBallotCount", IsError = true }, authBaseModel.Location); } finally { dbConn.Close(); ActionLogService.LogAction(new ActionLogModel() { UserID = authBaseModel.UserID, ActionPerformed = "Get Total Ballot Count For All Candidates", MethodName = "GetTotalBallotCount", IsError = false }, authBaseModel.Location); } return(TotalBallots); } }
/// <summary> /// Service Method To Record All The Consolidated Votes In The Main Database /// </summary> /// <param name="loggedInUser"></param> /// <param name="candidates"></param> /// <returns></returns> public static CommonResponse RecordConsolidatedVotes(AuthBaseModel loggedInUser, List <CandidateModel> candidates) { CommonResponse commonResponse = new CommonResponse(); using (SqlConnection dbConn = new SqlConnection(selectConnection("main"))) { try { foreach (var candidate in candidates) { String SQL = @"INSERT INTO ConsolidatedVotes(CandidateID, CandidateName, TotalNoOfVotes, Year, DateAdded)" + "VALUES('" + candidate.ID + "','" + candidate.Name + "','" + candidate.Votes + "', GetDate(), GetDate())"; dbConn.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = SQL; cmd.Connection = dbConn; cmd.ExecuteNonQuery(); dbConn.Close(); } } catch (Exception ex) { ActionLogService.LogAction(new ActionLogModel() { UserID = loggedInUser.UserID, ActionPerformed = "Error In Recording Consolidated Votes : " + ex.Message, MethodName = "RecordConsolidatedVotes", IsError = true }, loggedInUser.Location); commonResponse.IsError = true; } finally { dbConn.Close(); ActionLogService.LogAction(new ActionLogModel() { UserID = loggedInUser.UserID, ActionPerformed = "Record Consolidated Votes Completed!", MethodName = "RecordConsolidatedVotes", IsError = false }, loggedInUser.Location); } } return(commonResponse); }
/// <summary> /// Service Method To Get ActionLog Details /// </summary> /// <param name="authBaseModel"></param> /// <returns></returns> public static async Task <List <ActionLogModel> > GetActionLogDetails(AuthBaseModel authBaseModel) { List <ActionLogModel> actionLogs = new List <ActionLogModel>(); using (SqlConnection dbConn = new SqlConnection(selectConnection(authBaseModel.Location))) { var Query = "SELECT * FROM ActionLog ORDER BY ID DESC"; SqlDataReader reader; try { dbConn.Open(); SqlCommand cmd = new SqlCommand(Query, dbConn); reader = await cmd.ExecuteReaderAsync(); if (reader.HasRows) { while (reader.Read()) { ActionLogModel actionLog = new ActionLogModel(); actionLog.ID = reader.GetInt32(0); actionLog.DateCreated = reader.GetDateTime(1); actionLog.UserID = reader.GetInt32(2); actionLog.ActionPerformed = reader.GetString(3); actionLog.MethodName = reader.GetString(4); actionLog.IsError = reader.GetBoolean(5); actionLogs.Add(actionLog); } } dbConn.Close(); } catch { reader = null; } finally { dbConn.Close(); } return(actionLogs); } }
public ActionResult Auth() { try { string code = Request["code"]; if (Request.Url.Host.Equals("localhost")) { code = "sdfafasdf"; } if (String.IsNullOrEmpty(code)) { var url = EncodeUrl(Request.Url.AbsoluteUri); string redirect_uri = Server.UrlEncode(String.Format("{0}", new string[] { url })); string authorize_url = Getauthorize(BaseConfig.Wechatappid, redirect_uri, Scope.snsapi_base, "state", BaseConfig.WechatAuth); return(Redirect(authorize_url)); } else { string oauthUrl = BaseConfig.WechatAuth_access_token.Replace("{appid}", BaseConfig.Wechatappid).Replace("{secret}", BaseConfig.Wechatappsecret).Replace("{code}", code); AuthBaseModel MA = new AuthBaseModel(); if (Request.Url.Host.Equals("localhost")) //判断是否是本地调试连接 { MA.openid = "oqjP8wOL-kUnc7VfIHLlfUyv0Nm5"; } else { string returnString = LP_Common.HttpUtil.Get(oauthUrl); MA = Newtonsoft.Json.JsonConvert.DeserializeObject <AuthBaseModel>(returnString); } if (MA.errcode == null || MA.errcode == "0") { WechatCookieModel cmodel = new WechatCookieModel(); //验证paycode lp_userinfo umodel = uudal.SingleOrDefault((object)MA.openid); if (umodel == null) { cmodel.issystem = 2; cmodel.openid = MA.openid; cmodel.cookietime = DateTime.Now; } else { if (umodel.ustatus == 1) { return(Redirect("/Error/Index?errormsg=您的帐号已被管理员禁用.")); } else { cmodel.uname = umodel.uname; cmodel.uphone = umodel.uphone; cmodel.ustatus = umodel.ustatus; cmodel.issystem = umodel.issystem; cmodel.openid = MA.openid; cmodel.cookietime = DateTime.Now; } } CommonMethod.CommonMethod.SetWLoginData(HttpContext, cmodel);//设置cookie return(Redirect("/V_Main/Index")); } else { return(Redirect("/Error/Index?errormsg=" + MA.errmsg.ToString())); } } } catch (Exception ex) { return(Redirect("/Error/Index?errormsg=" + ex.ToString())); } }
/// <summary> /// Service Method To Get Consolidated Votes /// </summary> /// <param name="loggedInUser"></param> /// <returns></returns> public static List <CandidateModel> ConsolidateVotes(AuthBaseModel loggedInUser) { List <CandidateModel> Candidates = GetCandidates(loggedInUser.Location, loggedInUser.UserID); foreach (ConnectionStringSettings c in System.Configuration.ConfigurationManager.ConnectionStrings) { //use c.Name if (c.Name != "LocalSqlServer" && c.Name != "main") { using (SqlConnection dbConn = new SqlConnection(selectConnection(c.Name))) { var Query = "SELECT CandidateID, COUNT(Voted) AS TotalNoOfVotes FROM Ballot WHERE Voted = 1 GROUP BY CandidateID ORDER BY CandidateID"; SqlDataReader reader; try { dbConn.Open(); SqlCommand cmd = new SqlCommand(Query, dbConn); reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { TotalBallotModel votedCandidate = new TotalBallotModel(); votedCandidate.CandidateID = reader.GetInt32(0); votedCandidate.TotalNoOfVotes = reader.GetInt32(1); votedCandidate.DateTallied = DateTime.Now; foreach (var candidate in Candidates) { if (candidate.ID == votedCandidate.CandidateID) { candidate.Votes = votedCandidate.TotalNoOfVotes; } } } } } catch (Exception ex) { reader = null; ActionLogService.LogAction(new ActionLogModel() { UserID = loggedInUser.UserID, ActionPerformed = " Error In Consolidating Votes : " + ex.Message, MethodName = "ConsolidateVotes", IsError = true }, loggedInUser.Location); } finally { dbConn.Close(); ActionLogService.LogAction(new ActionLogModel() { UserID = loggedInUser.UserID, ActionPerformed = "Consolidate Votes", MethodName = "ConsolidateVotes", IsError = false }, loggedInUser.Location); } } } } return(Candidates); }