Skip to content

Instantly share code, notes, and snippets.

@umayr
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umayr/ae385bb6abcaaf6c3cd1 to your computer and use it in GitHub Desktop.
Save umayr/ae385bb6abcaaf6c3cd1 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Eventizer Document</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<style>
ul > li {
padding: 5px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>Eventizer Docs.</h1>
<p>MVC based online event management system</p>
<br />
<h2>MVC - 101</h2>
<section id="mvc-101">
<h3>MVC (Model-View-Controller) in general?</h3>
<p>MVC (Model-View-Controller) is an architectural software pattern that basically decouples various components of a web application. By using MVC pattern, we can develop applications that are more flexible to changes without affecting the other components of our application.</p>
<ul>
<li>"Model" is basically domain data.</li>
<li>"View" is user interface to render domain data.</li>
<li>"Controller" translates user actions into appropriate operations performed on model.</li>
</ul>
<h3>What is ASP.NET MVC?</h3>
<p>ASP.NET MVC is a web development framework from Microsoft that is based on MVC (Model-View-Controller) architectural design pattern. Microsoft has streamlined the development of MVC based applications using ASP.NET MVC framework.</p>
<h3>What are the Core features of ASP.NET MVC?</h3>
<p>Core features of ASP.NET MVC framework are:</p>
<ul>
<li>Clear separation of application concerns (Presentation and Business Logic)</li>
<li>An extensible and pluggable framework</li>
<li>Extensive support for ASP.NET Routing</li>
<li>Support for existing ASP.NET features</li>
</ul>
<h3>Request flow in ASP.NET MVC framework?</h3>
<p>Request flow for ASP.NET MVC framework is as follows:</p>
<p>Request hits the controller coming from client. Controller plays its role and decides which model to use in order to serve the request further passing that model to view which then transforms the model and generates an appropriate response that is rendered to the client.</p>
<h3>Routing in ASP.NET MVC?</h3>
<p>In case of a typical ASP.NET application, incoming requests are mapped to physical files such as
<em>.aspx</em>file. ASP.NET MVC framework uses friendly URLs that more easily describe user's action but are not mapped to physical files.
<br />ASP.NET MVC framework uses a routing engine, that maps URLs to controller classes. We can define routing rules for the engine, so that it can map incoming request URLs to appropriate controller.
<br />Practically, when a user types a URL in a browser window for an ASP.NET MVC application and presses "go" button, routing engine uses routing rules that are defined in
<em>Global.asax</em>file in order to parse the URL and find out the path of corresponding controller.
</p>
<h3>Role of Model in ASP.NET MVC?</h3>
<p>One of the core features of ASP.NET MVC is that it separates the input and UI logic from business logic. Role of Model in ASP.NET MVC is to contain all application logic including validation, business and data access logic except view, i.e., input and controller, i.e., UI logic.</p>
<p>Model is normally responsible for accessing data from some persistent medium like database and manipulate it.</p>
<h3>Why MVC?</h3>
<ul>
<li>
<strong>Improved Seperation of Concerns</strong>- The MVC Paradigm of Model-View-Controller allows you to more easily seperate all of your concerns within your application. This can lead to improved scalability within applications.</li>
<li>
<strong>Testing</strong>- MVC is designed and built for Testing-Driven Development and allows for applications to be very easily tested to help secure against error and unexpected behavior.
</li>
<li>
<strong>Integration with Client-Side Tools</strong>- The MVC pattern easily allows client-side tools such as jQuery to be seamlessly integrated. This can allow you to create very rich user interfaces for your applications.
</li>
<li>
<strong>Statelessness</strong>- Although one of the main advantages of Web Forms, this allows you to adhere to a more stateless format consistant with the rest of the web.
</li>
<li>
<strong>Control and Flexibility</strong>- MVC allows developers to have complete control over their applications as the developer doesn't rely on Controls to automatically generate the appropriate HTML, which after switching to MVC can often be seen as "bloated". The developer will write their own HTML instead of having it generated for them.
</li>
<li>
<strong>Search Engine Optimization</strong>- The use of RESTful URLs within MVC makes it more friendly for being accessed through search engines.
</li>
</ul>
<h3>What are controllers?</h3>
<p>
The ASP.NET MVC framework maps URLs to classes that are referred to as controllers. Controllers process incoming requests, handle user input and interactions, and execute appropriate application logic. A controller class typically calls a separate view component to generate the HTML markup for the request.
</p>
</section>
<br />
<section id="app-struct">
<h2>Application Structure</h2>
<p>Directory Structure of the application.</p>
<pre>
<code>
bootstrap/
├── css/
│ ├── bootstrap.css
│ ├── bootstrap.min.css
│ ├── bootstrap-theme.css
│ &#x2514; bootstrap-theme.min.css
├── js/
│ ├── bootstrap.js
│ └── bootstrap.min.js
└── fonts/
├── glyphicons-halflings-regular.eot
├── glyphicons-halflings-regular.svg
├── glyphicons-halflings-regular.ttf
└── glyphicons-halflings-regular.woff
</code>
Eventizer/
|--- Controllers/
|--- Helpers/
|--- Models/
|--- Static/
|--- js/
|--- fonts/
|--- css/
|--- Views/
|--- Web.Config
|--- Global.asax
</pre>
<br />
<h3>Controllers used in the application:</h3>
<ul>
<!-- TODO: Replace code tags for routes. Use <samp> instead. -->
<li>
<p>
<strong>Ajax Controller</strong>- deals with all the ajax requests sent to the server that includes login, registers, mark an event (and/or tast, subtask) complete et cetera.</p>
<p>
<strong>
<em>Included Methods:</em>
</strong>
</p>
<ul>
<li>
<code>public int Login(string email, string password)</code>- handles login ajax request, return 1 if successful; 0 if failed or -1 if something goes wrong.
<br />
<em>Assigned Route:</em>
<code>/Ajax/Login</code>
</li>
<li>
<code>public int Register(string name, string email, string password, string designation, string phone, int manager_id = 0)</code>- handles register requests, returns values as
<em>login</em>method
<br />
<em>Assigned Route:</em>
<code>/Ajax/Register</code>
</li>
<li>
<code>public int CreateEvent(string name, string description, string deadline)</code>- creates an event with ajax, returns same values as above.
<br />
<em>Assigned Route:</em>
<code>/Ajax/CreateEvent</code>
</li>
<li>
<code>public int CreateTask(string name, string description, string deadline, int event_id_for_task = 0, int assigned_to = 0)</code>- creates a task with ajax and adds it to the event present in the instance of
<em>Current Class</em>, returns same values as above.
<br />
<em>Assigned Route:</em>
<code>/Ajax/CreateTask</code>
</li>
<li>
<code>public int CreateSubtask(string name, string description, string deadline, int task_id_for_subtask = 0, int assigned_to = 0, int labours_required = 0, int asset_id = 0, int asset_quantity = 0)</code>- creates a subtask with ajax and attached it to the task present in the instance of
<em>Current Class</em>, returns same values as above.
<br />
<em>Assigned Route:</em>
<code>/Ajax/CreateSubtask</code>
</li>
<li>
<code>public int AddAsset(string name, string type)</code>- adds a new asset with ajax, returns same values as above.
<br />
<em>Assigned Route:</em>
<code>/Ajax/AddAsset</code>
</li>
<li>
<code>public bool MarkComplete(int ID = -1, int type = -1)</code>- marks any event, task or subtask complete, returns true if success and false if failure.
<br />
<em>Assigned Route:</em>
<code>/Ajax/MarkComplete</code>
</li>
<li>
<code>private bool AddAssetToSubtask(int subtask_id, int asset_id = 0, int asset_quantity = 0)</code>- adds an asset to the subtask, returns same values as above.
<br />
<em>Assigned Route:</em>
<code>/Ajax/AddAssetToSubtask</code>
</li>
</ul>
</p>
</li>
<li>
<p>
<strong>Assets Controller</strong>- manage all the
<em>Assets</em>views.</p>
<p>
<strong>
<em>Included Methods:</em>
</strong>
</p>
<ul>
<li>
<code>public ActionResult Index()</code>- renders main Asset View.
<br />
<em>Assigned Route:</em>
<code>Dashboard/assets/</code>
</li>
<li>
<code>private void InjectEmployeeDetails()</code>- injects
<em>Employee Details</em>into Viewbag for Assignation.
</li>
</ul>
</li>
<li>
<p>
<strong>Dashboard Controller</strong>- deals with all the ajax requests sent to the server that includes login, registers, mark an event (and/or tast, subtask) complete et cetera.</p>
<p>
<strong>
<em>Included Methods:</em>
</strong>
</p>
<ul>
<li>
<code>public ActionResult Index()</code>- renders main Dashboard View.
<br />
<em>Assigned Route:</em>
<code>/Dashboard</code>
</li>
</ul>
</li>
<li>
<p>
<strong>Employee Controller</strong>- deals with all the ajax requests sent to the server that includes login, registers, mark an event (and/or tast, subtask) complete et cetera.
</p>
<p>
<strong>
<em>Included Methods:</em>
</strong>
</p>
<ul>
<li>
<code>public ActionResult Index()</code>- renders main Employees View.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/employees</code>
</li>
<li>
<code>public ActionResult Add()</code>- renders Add an Employees View.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/employee/add</code>
</li>
</ul>
</li>
<li>
<p>
<strong>Error Controller</strong>- handles all the http errors.
</p>
<strong>
<em>Included Methods:</em>
</strong>
<ul>
<li>
<code>public ActionResult Index(int status, Exception error)</code>- renders all http errors views.
</li>
</ul>
</li>
<li>
<p>
<strong>Events Controller</strong>- handles all the event requests and renders views related to it.
</p>
<strong>
<em>Included Methods:</em>
</strong>
<ul>
<li>
<code>public ActionResult View(int id)</code>- renders an event view of provided
<em>id</em>.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/events/view/{id}</code>
</li>
<li>
<code>public ActionResult Index()</code>- renders all events view.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/events/</code>
</li>
<li>
<code>public ActionResult CreatedBy(int id)</code>- displays all events created by provided
<em>user id</em>.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/events/by/{id}</code>
</li>
<li>
<code>public ActionResult Me()</code>- displays all events created by current logged in user.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/events/by/me</code>
</li>
</ul>
</li>
<li>
<p>
<strong>Home Controller</strong>- handles request to route
<code>/</code>.
</p>
<ul>
<li>
<code>public ActionResult Index()</code>- renders home view (landing page).
<br />
<em>Assigned Route:</em>
<code>/</code>
</li>
</ul>
</li>
<li>
<p>
<strong>Subtasks Controller</strong>- handles all the subtasks requests and renders views related to it.
</p>
<strong>
<em>Included Methods:</em>
</strong>
<ul>
<li>
<code>public ActionResult View(int id)</code>- renders a subtask view of provided
<em>id</em>.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/subtasks/view/{id}</code>
</li>
<li>
<code>public ActionResult Index()</code>- renders all subtasks view.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/subtasks/</code>
</li>
<li>
<code>public ActionResult CreatedBy(int id)</code>- displays all subtasks created by provided
<em>user id</em>.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/subtasks/by/{id}</code>
</li>
<li>
<code>public ActionResult Me()</code>- displays all subtasks created by current logged in user.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/subtasks/by/me</code>
</li>
</ul>
</li>
<li>
<p>
<strong>Tasks Controller</strong>- handles all the tasks requests and renders views related to it.
</p>
<strong>
<em>Included Methods:</em>
</strong>
<ul>
<li>
<code>public ActionResult View(int id)</code>- renders a task view of provided
<em>id</em>.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/tasks/view/{id}</code>
</li>
<li>
<code>public ActionResult Index()</code>- renders all tasks view.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/tasks/</code>
</li>
<li>
<code>public ActionResult CreatedBy(int id)</code>- displays all tasks created by provided
<em>user id</em>.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/tasks/by/{id}</code>
</li>
<li>
<code>public ActionResult Me()</code>- displays all tasks created by current logged in user.
<br />
<em>Assigned Route:</em>
<code>/Dashboard/tasks/by/me</code>
</li>
</ul>
</li>
</ul>
<h3>Helper Classes:</h3>
<p>Helper Class is a programming technique in object-oriented programming. Helper classes are a term given to classes that are used to assist in providing some functionality, though that functionality isn't the main goal of the application. A helper class is a class filled with static methods. It is usually used to isolate a "useful" algorithm.
<strong>P.S. Helper classes in OO is an antipattern, actually. Only naive and/or n00b developers use them, I wrote them in this project because I used to create helpers in my university days.</strong>
</p>
<br />
<h4>Essentials Class</h4>
<p>This class contains static methods that are either being called directly from view, model or controller depending on the need.</p>
<p>
<strong>
<em>Included Methods</em>
</strong>
</p>
<ul>
<li>
<p>
<code>public static string CalculateSHA1(string value)</code>- calculates SHA1 hash of the string value provided,
<em>Eventizer</em>uses SHA1 for storing passwords into the database. And that is done by this method.
</p>
</li>
<li>
<p>
<code>public static string HexStringFromBytes(byte[] bytes)</code>- converts a byte array into a string, used in calculating hash for passwords.
</p>
</li>
<li>
<p>
<code>public static bool CheckIfAuthenticated()</code>- returns true if user is authenticated and false if opposite, used for authentication purposes.
</p>
</li>
<li>
<p>
<code>public static string TrimLongText(string Text, int TrimTo = 100)</code>- trims a long text to string of provided length of characters, used to trim event, tasks and subtasks description while displaying in tabular form.
</p>
</li>
<li>
<p>
<code>private static int CalculatePriority(DateTime Deadline, bool Status)</code>- calulates priority based on the deadline of either event, task or a subtask, used within the class.
</p>
</li>
<li>
<p>
<code>public static string CalculatePriorityColor(DateTime Deadline, bool Status)</code>- returns a colour code based on the deadline of either event, task or subtask. It has been used while displaying event, task and subtask views.
</p>
</li>
<li>
<p>
<code>public static string CalculatePriorityClass(DateTime Deadline, bool Status)</code>- does the same function as above but instead of returning a colour code, it returns the name of bootstrap class.
</p>
</li>
<li>
<p>
<code>public static bool IfDeadlineHasPassed(DateTime Deadline, bool Status)</code>- checks if deadline of a particular event, task or subtask has been passed.
</p>
</li>
<li>
<p>
<code>public static int GetFeedType(string Type)</code>- returns the type of a feed, used in dashboard view.
</p>
</li>
</ul>
<h4>Database Class</h4>
<p>This isn't a static class, but it has all the methods to access database. Helper classes like this, also called Database Access Layer (DAL)</p>
<p>
<strong>
<em>Included Methods</em>
</strong>
</p>
<ul>
<li>
<p>
<code>public SqlDataReader SelectAllFromView(string viewName)</code>- executes
<code>SELECT * FROM &lt;view_name&gt;</code>query on the view provided in
<code>viewName</code>param and returns dataset.
</p>
</li>
<li>
<p>
<code>public SqlDataReader SelectFromViewWithWhere(string viewName, string whereClause)</code>- does exactly as above method and provides
<code>where</code>clause functionality.
</p>
</li>
<li>
<p>
<code>public bool ExecuteProcedure(string ProcedureName, List
<SqlParameter>Params)</code>- executes a stored procedure with given
<code>ProcedureName</code>and
<code>Params</code>, returns true if executed without any errors.
</p>
</li>
<li>
<p>
<code>public int ExecuteProcedureWithScopeID(string ProcedureName, List
<SqlParameter>Params)</code>- does the same functionality as above, but as the procedure itself return a scope id
<a href="http://msdn.microsoft.com/en-us/library/ms190315.aspx" target="_blank">
<em>(read more)</em>
</a>, the methods returns it back to callee.
</p>
</li>
<li>
<p>
<code>public object ExecProcedureWithReturnValue(string ProcedureName)</code>- does the same basic functionality as
<code>
ExecuteProcedure(..)</code>but used for those stored procedures that returns any object/row from a database.
</p>
</li>
<li>
<p>
<code>public object ExecProcedureWithReturnValue(string ProcedureName, List
<SqlParameter>Params)</code>- another variation of
<code>ExecProcedureWithReturnValue(..)</code>, only difference being; it executes a parameterized stored procedure.
</p>
</li>
<li>
<p>
<code>public SqlDataReader ExecProcedureWithResult(string ProcedureName, List
<SqlParameter>Params)</code>- used to call procedures that executes any
<code>select</code>queries within their scope and returns the results.
</p>
</li>
<li>
<p>
<code>public IEnumerable
<Dictionary<string, object>> Serialize(SqlDataReader reader)</code>- converts all rows
<code>SqlDataReader</code>into an iteratable
<code>IEnumerable&lt;Dictionary&lt;T,T&gt;&gt;</code>instance.
</p>
</li>
<li>
<p>
<code>private Dictionary
<string, object>SerializeRow(IEnumerable
<string>cols, SqlDataReader reader)</code>- private method used to serialize a single row.
</p>
</li>
</ul>
<h3>Models used in the application:</h3>
<ul>
<li>
<p>
<strong>Asset Model</strong>- model class for Assets.
</p>
<strong>
<em>Static Methods attached:</em>
</strong>
<ul>
<li>
<code>public static Asset FetchAssetByID(int ID)</code>- fetches asset by provided ID.
</li>
<li>
<code>public static List<Asset> FetchAllAssets(SqlDataReader reader)</code>- fetches all assets from <code>SqlDataReader</code> object.
</li>
<li>
<code>public static List<AssetName> FetchAllAssetNames()</code>- returns all the names of assets in the database. Used in adding assets to subtask in Create Subtask Model.
</li>
</ul>
</li>
<li>
<p>
<strong>Current Model</strong>- this is an especial model, it wraps objects of <code>Event</code>, <code>Task</code>,<code>Subtask</code> and <code>Employee</code>. It doesn't have any methods because it is just a placeholder. The main use of this model is to keep track of the current object that is being used in the system, for example: if an event is being created the <code>Current</code> tells the system <em>Who is created event?</em> same as if a task is being created then it tells <em>Which event this task belongs to?</em> <em><strong>Tl;dr: very important model that tells current instances of other models.</strong></em>
</p>
</li>
<li>
<p>
<strong>Employee Model</strong>- model class for Employees.
</p>
<strong>
<em>Static Methods attached:</em>
</strong>
<ul>
<li>
<code>public static Employee FetchEmployeeByID(int ID)</code>- fetches employee by provided ID.
</li>
<li>
<code>public static Employee FetchEmployeeByEmail(string Email)</code>- fetches employee by provided Email address, used for login.
</li>
<li>
<code>public static List<Employee> FetchAllEmployees()</code>- fetches all employess.
</li>
</ul>
</li>
<li>
<p>
<strong>Employee Model</strong>- model class for Employees.
</p>
<strong>
<em>Static Methods attached:</em>
</strong>
<ul>
<li>
<code>public static Employee FetchEmployeeByID(int ID)</code>- fetches employee by provided ID.
</li>
<li>
<code>public static Employee FetchEmployeeByEmail(string Email)</code>- fetches employee by provided Email address, used for login.
</li>
<li>
<code>public static List<Employee> FetchAllEmployees()</code>- fetches all employess.
</li>
</ul>
</li>
</ul>
</section>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment