Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Linq.Expressions;
  7. using System.Data.Linq;
  8. using System.Web;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Text;
  14. using System.Web.Mvc;
  15. using System.IO;
  16. using System.Data.Objects;
  17. using System.Data.Entity;
  18. using System.Data.Entity.Infrastructure;
  19. using System.Web.SessionState;
  20. using ASKPLDTCMS.Models;
  21. using ASKPLDTCMS.Helpers;
  22. /*
  23. *
  24. * @comment: this code looks funny and needs to be refactored
  25. * @date : 06/06/2011
  26. *
  27. *
  28. *
  29. */
  30. namespace ASKPLDTCMS.Controllers
  31. {
  32.  
  33.  
  34. public class HomeController : Controller
  35. {
  36. PLDT_CMS cms_dbconnect = new PLDT_CMS();
  37.  
  38. SessionHelpers cms_session = new SessionHelpers();
  39. private readonly Random _rng = new Random();
  40. private const string _chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  41. // public int size = 23;
  42.  
  43. public ActionResult Index()
  44. {
  45. string xxx = cms_session.HelloWorld();
  46. Response.Write(xxx);
  47. return View();
  48. }
  49.  
  50. //LukeH
  51. private string RandomString(int size)
  52. {
  53. char[] buffer = new char[size];
  54.  
  55. for (int i = 0; i < size; i++)
  56. {
  57. buffer[i] = _chars[_rng.Next(_chars.Length)];
  58. }
  59. return new string(buffer);
  60. }
  61.  
  62.  
  63. [HttpPost, ValidateInput(false)]
  64. public ActionResult Index(FormCollection login, Session session)
  65. {
  66. if ( login["username"] != null && login["password"] != null )
  67. {
  68. string username = login["username"].Trim();
  69. string password = login["password"].Trim();
  70.  
  71. var credential = cms_dbconnect.AskUsers.
  72. Where( u => u.username == username ).
  73. Where( u => u.password == password ).SingleOrDefault();
  74.  
  75. if ( credential != null )
  76. {
  77. //
  78. var session_state = cms_dbconnect.AskUsers.Find(credential.useridPK);
  79. string remote_address = Request.ServerVariables["REMOTE_ADDR"];
  80. string today = DateTime.Now.ToString("d/MM/yyyy");
  81.  
  82. string complete_name = session_state.firstname + session_state.firstname;
  83. int size_name = Convert.ToInt32(complete_name.Length.ToString());
  84.  
  85. session.session_name = session_state.firstname + ' ' + session_state.lastname;
  86. session.roleidFK = session_state.roleidFK;
  87. session.useridFK = session_state.useridPK;
  88. session.session_datecreated = today;
  89. // string token =
  90. session.session_token = RandomString(size_name);
  91. session.ipaddress = remote_address;
  92. cms_dbconnect.Sessions.Add(session);
  93. cms_dbconnect.SaveChanges();
  94. ViewBag.Title = true;
  95. return RedirectToAction("Dashboard", new { id = session.session_idPK });
  96. // return RedirectToAction("Dashboard", "Home");
  97. }
  98. else
  99. {
  100. ViewBag.Title = false;
  101. ViewBag.ErrorMessage = "Invalid Username / Password.";
  102. return View();
  103. }
  104.  
  105. }
  106. else
  107. {
  108. return View();
  109. }
  110. //return View();
  111. }
  112.  
  113. public ActionResult Login()
  114. {
  115.  
  116. return View();
  117. }
  118.  
  119. // [ControllerSessionState(SessionStateBehavior.Disabled)]
  120. public ActionResult Dashboard(int id)
  121. {
  122.  
  123. //POST
  124. if (cms_session.GetSession(id))
  125. {
  126. Response.Write("ok" + id);
  127. Response.Write(cms_session.GetSessionUser());
  128. }
  129. else
  130. {
  131. Response.Write("false");
  132. }
  133. string posting = "posting";
  134. string review = "review";
  135. string draft = "draft";
  136.  
  137. //total post
  138. var gg = (from p in cms_dbconnect.Posts.Where(p => p.routing_type == posting)
  139. select p).Count();
  140. ViewBag.posting = gg;
  141. //total review
  142. var ee = (from e in cms_dbconnect.Posts.Where(e => e.routing_type == review)
  143. select e).Count();
  144. ViewBag.review = ee;
  145. //total draft
  146. var aa = (from a in cms_dbconnect.Posts.Where(a => a.routing_type == draft)
  147. select a).Count();
  148. ViewBag.draft = aa;
  149.  
  150. //suggestion: compare current date to dateFrom
  151. var date_context = new PLDT_CMS();
  152. string curren_date = "select * from ASKPLDTCMS_DB.dbo.Post where ASKPLDTCMS_DB.dbo.Post.datefrom=CONVERT(VARCHAR(10),GETDATE(),110)";
  153. IEnumerable<Post> get_current_date = date_context.Database.SqlQuery<Post>(curren_date).ToList();
  154. ViewBag.View = get_current_date.Count();
  155.  
  156. // grand total of yesterday post
  157. var yesterday_context = new PLDT_CMS();
  158. string yesterday_date = "select * from ASKPLDTCMS_DB.dbo.Post where ASKPLDTCMS_DB.dbo.Post.datefrom=CONVERT(VARCHAR(10),DATEADD(dd,-1,GETDATE()),110)";
  159. IEnumerable<Post> get_yesterday_post = yesterday_context.Database.SqlQuery<Post>(yesterday_date).ToList();
  160. ViewBag.YesterdayPost = get_yesterday_post.Count();
  161. //IMAGE
  162. string standard = "standard";
  163. string movie = "movie";
  164. //total image in standard
  165. var ss = (from s in cms_dbconnect.Posts.Where(s => s.post_type == standard)
  166. select s.image).Count();
  167. ViewBag.standard = ss;
  168.  
  169. //total image in movie
  170. var xx = (from x in cms_dbconnect.Posts.Where(x => x.post_type == movie)
  171. select x.image).Count();
  172. ViewBag.movie = xx;
  173.  
  174. //CATEGORY
  175.  
  176. //total child category
  177. var lll = (from l in cms_dbconnect.Categories
  178. join ll in cms_dbconnect.Taxonomies
  179. on l.catidPK equals ll.parentid
  180. select new CategoryTaxonomy
  181. {
  182. catidFK = ll.parentid
  183. }).Count();
  184. ViewBag.child = lll;
  185.  
  186. //total parent category
  187. var ooo = (from o in cms_dbconnect.Taxonomies.Where(o =>
  188. o.taxidPK == o.parentid)
  189. select o).Count();
  190. ViewBag.parent = ooo;
  191.  
  192. //total post for currendate
  193. /* var m_context = new PLDT_CMS();
  194. string current_date = "SELECT * FROM [ASKPLDTCMS_DB].[dbo].[Post] WHERE ASKPLDTCMS_DB.dbo.Post.datecreated=SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 103),2,20) ";
  195.  
  196. IEnumerable<Post> sql_child = m_context.Database.SqlQuery<Post>(current_date).ToList();
  197. ViewBag.View = sql_child.Count();
  198.  
  199. return View();*/
  200.  
  201. // DIGITAL MAGAZINE
  202.  
  203. //togal DMCategory
  204. var sar = (from sara in cms_dbconnect.DMCategories
  205. select sara.dmcatidPK).Count();
  206. ViewBag.dmcategory = sar;
  207.  
  208. //total Publisher
  209. var rah = (from ha in cms_dbconnect.DMPublishers
  210. select ha.pubidPK).Count();
  211. ViewBag.publisher = rah;
  212.  
  213. //total magazines
  214. var mags = (from mag in cms_dbconnect.DMMagazines
  215. select mag.magidPK).Count();
  216. ViewBag.magazine = mags;
  217.  
  218. //total digitalmagazines
  219. var digmags = (from digimag in cms_dbconnect.DigitalMagazines
  220. select digimag.magtitleidPK).Count();
  221. ViewBag.digimags = digmags;
  222. return View();
  223. }
  224. }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement