Exemplo n.º 1
0
        public ActionResult Checkout(ShippingDetail detail)
        {
            var hoaDon = this.Session["HoaDon"] as HoaDon;

            if (hoaDon.ChiTietHoaDons.Count() == 0)
            {
                ModelState.AddModelError("", "Sorry, your cart isempty!");
            }
            if (ModelState.IsValid)
            {
                StringBuilder body = new StringBuilder().AppendLine("A new order has been submitted").AppendLine("---").AppendLine("Items:");
                foreach (var hoaDonChiTiet in hoaDon.ChiTietHoaDons)
                {
                    var subtotal = hoaDonChiTiet.MovieObj.Price * hoaDonChiTiet.SoLuong;
                    body.AppendFormat("{0} x {1} (subtotal: {2:c}", hoaDonChiTiet.SoLuong, hoaDonChiTiet.MovieObj.Title, subtotal);
                }
                body.AppendFormat("Total order value: {0:c}", hoaDon.TongTien).AppendLine("---").AppendLine("Ship to:").AppendLine(detail.Name).AppendLine(detail.Address).AppendLine(detail.Mobile.ToString());
                EmailServiceNew.SendEmail(new IdentityMessage()
                {
                    Destination = detail.Email,
                    Subject     = "New order submitted!",
                    Body        = body.ToString()
                });
                this.Session["HoaDon"] = null;
                return(View("CheckoutCompleted"));
            }
            else
            {
                return(View(new ShippingDetail()));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <BaseResponse> > ExportExcelFile(DeThiRequest request, int giangVienId = 0)
        {
            var list = await _context.LopHocPhans.Include(x => x.HocPhan)
                       .Include(x => x.HocPhan.DonViQuanLy)
                       .Include(x => x.HocPhan.DonViRaDe)
                       .Where(x => x.NgayGioBDThi >= request.NgayBatDau && x.NgayGioBDThi <= request.NgayKetThuc)
                       .Where(x => x.HocPhan.DonViRaDeId == request.DonViId)
                       .ToListAsync();

            using (var file = new OfficeOpenXml.ExcelPackage())
            {
                string path = _hostingEnvironment.WebRootPath + "\\Forms\\FormCungCapDeThi.xlsx";
                using (FileStream stream = new FileStream(path, FileMode.Open))
                {
                    file.Load(stream);
                }
                var worksheet = file.Workbook.Worksheets.First();
                worksheet.Cells[9, 5].Value = list[0].HocPhan.DonViQuanLy.TenDonVi;
                worksheet.Cells[7, 5].Value = request.NgayBatDau.ToString("dd-MM-yyyy");
                worksheet.Cells[7, 9].Value = request.NgayKetThuc.ToString("dd-MM-yyyy");
                for (int i = 0; i < list.Count - 1; i++)
                {
                    worksheet.InsertRow(i + 16, 1);
                    worksheet.Cells[15, 1, 15, worksheet.Dimension.End.Column].Copy(worksheet.Cells[i + 16, 1, i + 16, worksheet.Dimension.End.Column]);
                    worksheet.Row(i + 16).StyleID = worksheet.Row(15).StyleID;
                }
                string hoTen, email;
                if (giangVienId > 0)
                {
                    var giangVien = _context.GiangViens.Find(giangVienId);
                    hoTen = giangVien.HoGV + " " + giangVien.TenGV;
                    email = giangVien.Email;
                }
                else
                {
                    hoTen = list[0].HocPhan.DonViRaDe.TenDonVi;
                    email = list[0].HocPhan.DonViRaDe.Email;
                }
                for (int i = 0; i < list.Count; i++)
                {
                    var rowCells = worksheet.Cells[i + 15, 1, i + 15, worksheet.Dimension.End.Column];
                    var data     = list[i];
                    rowCells[i + 15, 1].Value  = i + 1;
                    rowCells[i + 15, 2].Value  = hoTen;
                    rowCells[i + 15, 5].Value  = data.HocPhan.TenHP;
                    rowCells[i + 15, 8].Value  = data.MaLopHP;
                    rowCells[i + 15, 10].Value = data.NgayGioBDThi.ToString("dd-MM-yyyy") + " " + data.NgayGioBDThi.ToString("HH:mm");
                }
                byte[] excelData    = file.GetAsByteArray();
                var    memoryStream = new MemoryStream(excelData);
                await EmailServiceNew.SendEmail(new IdentityMessage()
                {
                    Destination = "*****@*****.**", Subject = "Đề nghị gửi đề thi", Body = ""
                }, memoryStream);

                return(new BaseResponse
                {
                    Message = "Gửi mail thành công"
                });
            }
        }