private static void insertUserName(String name, string email, String contact, string query) { CustomerQuery customerQuery = new CustomerQuery() { CustomerName = name, Email = email, IsQueryResponded = "N", Message = query, MobileNumber = contact, QueryResponse = string.Empty, QueryResponseDate = null, ReceiveDate = DateTime.Now }; using (var dbContext = new SmarteezDatabaseEntities()) { dbContext.CustomerQueries.Add(customerQuery); dbContext.SaveChanges(); } }
void Session_Start(object sender, EventArgs e) { //Code that runs when a new session is started Application.Lock(); using (var dbContext = new SmarteezDatabaseEntities()) { WebSiteUser websiteUser = new WebSiteUser() { ClientBrowser = HttpContext.Current.Request.Browser.Browser, MachineIP = string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) ? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] : HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"], VisitDate = DateTime.Now }; int i = dbContext.Users.Count(); dbContext.WebSiteUsers.Add(websiteUser); dbContext.SaveChanges(); int userCount = dbContext.WebSiteUsers.Count<WebSiteUser>() + 1000; Application.Add("UserCount", userCount); } Application.UnLock(); }