public async Task <IHttpActionResult> UpdateAsync(int luotTruyCapId, [FromBody] LuotTruyCap luotTruyCap) { if (luotTruyCap.LuotTruyCapId != luotTruyCapId) { return(BadRequest("Id mismatch")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var db = new ApplicationDbContext()) { bool exists = db.LuotTruyCap.Count(o => o.LuotTruyCapId == luotTruyCapId) > 0; if (!exists) { return(NotFound()); } db.Entry(luotTruyCap).State = EntityState.Modified; await db.SaveChangesAsync(); return(Ok(luotTruyCap)); } }
protected void Session_Start() { Application.Lock(); Application["VisitorOnline"] = (int)Application["VisitorOnline"] + 1; LuotTruyCap luotTruyCap = new LuotTruyCap(); luotTruyCap.IP = Request.UserHostAddress; luotTruyCap.ThietBi = Request.UserAgent; luotTruyCap.ThoiGian = DateTime.Now; luotTruyCap.TrangTruyCapDauTien = Request.Url.OriginalString.Length > 250? Request.Url.OriginalString.Substring(0, 250): Request.Url.OriginalString; luotTruyCapService.ThemLuotTruyCap(luotTruyCap); Application.UnLock(); }
public async Task <IHttpActionResult> InsertAsync([FromBody] LuotTruyCap luotTruyCap) { if (luotTruyCap.LuotTruyCapId != 0) { return(BadRequest("Invalid LuotTruyCapId")); } using (var db = new ApplicationDbContext()) { db.LuotTruyCap.Add(luotTruyCap); await db.SaveChangesAsync(); } return(Ok(luotTruyCap)); }
protected void Session_Start(object sender, EventArgs e) { thuctaptotnghiepDbContext db = new thuctaptotnghiepDbContext(); var allow = db.LuotTruyCaps.FirstOrDefault(); if (allow == null) { allow = new LuotTruyCap(); allow.today = 0; allow.total = 0; db.LuotTruyCaps.Add(allow); } if (allow.datetoday == null) { allow.datetoday = DateTime.Now; if (allow.today == null) { allow.today = 1; allow.total += 1; } else { allow.today += 1; allow.total += 1; } } else if (allow.datetoday.Value.Date == DateTime.Now.Date) { allow.today += 1; allow.total += 1; } else { allow.datetoday = DateTime.Now; allow.today = 1; allow.total += 1; } db.SaveChanges(); }
public void today() { var allow = db.LuotTruyCaps.FirstOrDefault(); if (allow == null) { allow = new LuotTruyCap(); allow.today = 0; allow.total = 0; db.LuotTruyCaps.Add(allow); } if (allow.datetoday == null) { allow.datetoday = DateTime.Now; if (allow.today == null) { allow.today = 1; allow.total += 1; } else { allow.today += 1; allow.total += 1; } } else if (allow.datetoday.Value.Date == DateTime.Now.Date) { allow.today += 1; allow.total += 1; } else { allow.datetoday = DateTime.Now; allow.today = 1; allow.total += 1; } db.SaveChanges(); }