Last active
January 2, 2016 12:58
-
-
Save kcuzner/8306451 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyMvcApplication | |
{ | |
class DbQueries : IDisposable | |
{ | |
protected TimeShedulerEntities Context { get; private set; } | |
public DbQueries() | |
{ | |
this.Context = new TimeShedulerEntities(); | |
} | |
public Branch[] LoadBranches(int companyId, int page, int limit, string search, string sort, string sortOrder) | |
{ | |
var _branches = (from ct in this.Context.Branches | |
where ct.Title.Contains(search) || ct.Code.Contains(search) | |
select ct).OrderBy(c => c.Title).Skip((page - 1) * limit).Take(limit); | |
return _branches.ToArray(); | |
} | |
public void SaveChanges() | |
{ | |
this.Context.SaveChanges(); | |
} | |
public void Dispose() | |
{ | |
this.Context.Dispose(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyMvcApplication | |
{ | |
public class MvcApplication : HttpApplication //this should already exist | |
{ | |
protected void Application_BeginRequest(object sender, EventArgs e) | |
{ | |
HttpContext.Current.Items["DbQueries"] = new DbQueries(); | |
} | |
protected void Application_EndRequest(object sender, EventArgs e) | |
{ | |
((DbQueries)HttpContext.Current.Items["DbQuerues"]).Dispose(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyMvcApplication | |
{ | |
public class HomeController : Controller | |
{ | |
public ActionResult Index() | |
{ | |
DbQueries dbQueries = (DbQueries)HttpContext.Current.Items["DbQueries"]; | |
ViewBag.Branches = dbQueries.LoadBranches(...); | |
return View(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment