Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Diagnostics.CodeAnalysis;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Data.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Web.Mvc;
- using System.IO;
- using System.Data.Objects;
- using System.Data.Entity;
- using System.Data.Entity.Infrastructure;
- using System.Web.SessionState;
- using ASKPLDTCMS.Models;
- using ASKPLDTCMS.Helpers;
- /*
- *
- * @comment: this code looks funny and needs to be refactored
- * @date : 06/06/2011
- *
- *
- *
- */
- namespace ASKPLDTCMS.Controllers
- {
- public class HomeController : Controller
- {
- PLDT_CMS cms_dbconnect = new PLDT_CMS();
- SessionHelpers cms_session = new SessionHelpers();
- private readonly Random _rng = new Random();
- private const string _chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- // public int size = 23;
- public ActionResult Index()
- {
- string xxx = cms_session.HelloWorld();
- Response.Write(xxx);
- return View();
- }
- //LukeH
- private string RandomString(int size)
- {
- char[] buffer = new char[size];
- for (int i = 0; i < size; i++)
- {
- buffer[i] = _chars[_rng.Next(_chars.Length)];
- }
- return new string(buffer);
- }
- [HttpPost, ValidateInput(false)]
- public ActionResult Index(FormCollection login, Session session)
- {
- if ( login["username"] != null && login["password"] != null )
- {
- string username = login["username"].Trim();
- string password = login["password"].Trim();
- var credential = cms_dbconnect.AskUsers.
- Where( u => u.username == username ).
- Where( u => u.password == password ).SingleOrDefault();
- if ( credential != null )
- {
- //
- var session_state = cms_dbconnect.AskUsers.Find(credential.useridPK);
- string remote_address = Request.ServerVariables["REMOTE_ADDR"];
- string today = DateTime.Now.ToString("d/MM/yyyy");
- string complete_name = session_state.firstname + session_state.firstname;
- int size_name = Convert.ToInt32(complete_name.Length.ToString());
- session.session_name = session_state.firstname + ' ' + session_state.lastname;
- session.roleidFK = session_state.roleidFK;
- session.useridFK = session_state.useridPK;
- session.session_datecreated = today;
- // string token =
- session.session_token = RandomString(size_name);
- session.ipaddress = remote_address;
- cms_dbconnect.Sessions.Add(session);
- cms_dbconnect.SaveChanges();
- ViewBag.Title = true;
- return RedirectToAction("Dashboard", new { id = session.session_idPK });
- // return RedirectToAction("Dashboard", "Home");
- }
- else
- {
- ViewBag.Title = false;
- ViewBag.ErrorMessage = "Invalid Username / Password.";
- return View();
- }
- }
- else
- {
- return View();
- }
- //return View();
- }
- public ActionResult Login()
- {
- return View();
- }
- // [ControllerSessionState(SessionStateBehavior.Disabled)]
- public ActionResult Dashboard(int id)
- {
- //POST
- if (cms_session.GetSession(id))
- {
- Response.Write("ok" + id);
- Response.Write(cms_session.GetSessionUser());
- }
- else
- {
- Response.Write("false");
- }
- string posting = "posting";
- string review = "review";
- string draft = "draft";
- //total post
- var gg = (from p in cms_dbconnect.Posts.Where(p => p.routing_type == posting)
- select p).Count();
- ViewBag.posting = gg;
- //total review
- var ee = (from e in cms_dbconnect.Posts.Where(e => e.routing_type == review)
- select e).Count();
- ViewBag.review = ee;
- //total draft
- var aa = (from a in cms_dbconnect.Posts.Where(a => a.routing_type == draft)
- select a).Count();
- ViewBag.draft = aa;
- //suggestion: compare current date to dateFrom
- var date_context = new PLDT_CMS();
- string curren_date = "select * from ASKPLDTCMS_DB.dbo.Post where ASKPLDTCMS_DB.dbo.Post.datefrom=CONVERT(VARCHAR(10),GETDATE(),110)";
- IEnumerable<Post> get_current_date = date_context.Database.SqlQuery<Post>(curren_date).ToList();
- ViewBag.View = get_current_date.Count();
- // grand total of yesterday post
- var yesterday_context = new PLDT_CMS();
- string yesterday_date = "select * from ASKPLDTCMS_DB.dbo.Post where ASKPLDTCMS_DB.dbo.Post.datefrom=CONVERT(VARCHAR(10),DATEADD(dd,-1,GETDATE()),110)";
- IEnumerable<Post> get_yesterday_post = yesterday_context.Database.SqlQuery<Post>(yesterday_date).ToList();
- ViewBag.YesterdayPost = get_yesterday_post.Count();
- //IMAGE
- string standard = "standard";
- string movie = "movie";
- //total image in standard
- var ss = (from s in cms_dbconnect.Posts.Where(s => s.post_type == standard)
- select s.image).Count();
- ViewBag.standard = ss;
- //total image in movie
- var xx = (from x in cms_dbconnect.Posts.Where(x => x.post_type == movie)
- select x.image).Count();
- ViewBag.movie = xx;
- //CATEGORY
- //total child category
- var lll = (from l in cms_dbconnect.Categories
- join ll in cms_dbconnect.Taxonomies
- on l.catidPK equals ll.parentid
- select new CategoryTaxonomy
- {
- catidFK = ll.parentid
- }).Count();
- ViewBag.child = lll;
- //total parent category
- var ooo = (from o in cms_dbconnect.Taxonomies.Where(o =>
- o.taxidPK == o.parentid)
- select o).Count();
- ViewBag.parent = ooo;
- //total post for currendate
- /* var m_context = new PLDT_CMS();
- string current_date = "SELECT * FROM [ASKPLDTCMS_DB].[dbo].[Post] WHERE ASKPLDTCMS_DB.dbo.Post.datecreated=SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 103),2,20) ";
- IEnumerable<Post> sql_child = m_context.Database.SqlQuery<Post>(current_date).ToList();
- ViewBag.View = sql_child.Count();
- return View();*/
- // DIGITAL MAGAZINE
- //togal DMCategory
- var sar = (from sara in cms_dbconnect.DMCategories
- select sara.dmcatidPK).Count();
- ViewBag.dmcategory = sar;
- //total Publisher
- var rah = (from ha in cms_dbconnect.DMPublishers
- select ha.pubidPK).Count();
- ViewBag.publisher = rah;
- //total magazines
- var mags = (from mag in cms_dbconnect.DMMagazines
- select mag.magidPK).Count();
- ViewBag.magazine = mags;
- //total digitalmagazines
- var digmags = (from digimag in cms_dbconnect.DigitalMagazines
- select digimag.magtitleidPK).Count();
- ViewBag.digimags = digmags;
- return View();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement