public FileResult Export() { int tong = int.Parse(Session["TongDG"].ToString()); string tong1 = string.Format("{0:0,0}", tong); string tong2 = tong1 + "đ"; CàPheEntities entities = new CàPheEntities(); DataTable dt = new DataTable("DoanhThu"); dt.Columns.AddRange(new DataColumn[6] { new DataColumn("Mã Đơn Hàng"), new DataColumn("Tên khách hàng"), new DataColumn("Ngày đặt hàng"), new DataColumn("Ngày giao hàng"), new DataColumn("Trị giá"), new DataColumn("Tình trạng giao hàng"), }); int i = int.Parse(Session["month"].ToString()); int i1 = int.Parse(Session["year"].ToString()); var customers = from customer in entities.DONDATHANGs.Where(n => n.NgayDH.Value.Month == i && n.NgayDH.Value.Year == i1 && n.TrangThai == "Đã giao") select customer; Session["excel"] = customers; foreach (var customer in customers) { if (customer.TrangThai == "Đã giao") { dt.Rows.Add(customer.SoDH, customer.TenNguoiNhan, customer.NgayDH, customer.Ngaygiaohang, customer.TriGia, customer.TrangThai); } else { } } dt.Rows.Add(""); dt.Rows.Add("Thống kê doanh thu tháng " + Session["month"] + " năm " + Session["year"] + ""); dt.Rows.Add("Tổng tiền:", tong2); using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(dt); using (MemoryStream stream = new MemoryStream()) { wb.SaveAs(stream); return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Doanh Thu Thang " + Session["month"] + "/" + Session["year"] + ".xlsx")); } } }
public ActionResult GoogleLoginCallback() { var claimsPrincipal = HttpContext.User.Identity as ClaimsIdentity; var loginInfo = SSO.GetLoginInfo(claimsPrincipal); if (loginInfo == null) { return(RedirectToAction("LoginSSO")); } CàPheEntities db = new CàPheEntities(); //DbContext var user = db.KHACHHANGs.FirstOrDefault(x => x.Email == loginInfo.emailaddress); if (user == null) { user = new KHACHHANG { Email = loginInfo.emailaddress, HoTenKH = loginInfo.name, DiaChiKH = loginInfo.nameidentifier, }; db.KHACHHANGs.Add(user); db.SaveChanges(); } Session["username"] = loginInfo.name; Session["makh"] = user.MaKH; var ident = new ClaimsIdentity( new[] { // adding following 2 claim just for supporting default antiforgery provider new Claim(ClaimTypes.NameIdentifier, user.Email), new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"), new Claim(ClaimTypes.Name, user.HoTenKH), new Claim(ClaimTypes.Email, user.Email), // optionally you could add roles if any new Claim(ClaimTypes.Role, "User") }, CookieAuthenticationDefaults.AuthenticationType); HttpContext.GetOwinContext().Authentication.SignIn( new AuthenticationProperties { IsPersistent = false }, ident); return(RedirectToAction("Index", "Home")); }