public ActionResult DangKyKhoaHoc() { int id = int.Parse(Request.QueryString["id"]); string MaGS = Request.QueryString["MaGS"]; ApplicationDbContext dbIdentity = new ApplicationDbContext(); string idAdmin = dbIdentity.Users.SingleOrDefault(x => x.UserName == "Admin").Id; string idIdentity = dbIdentity.Users.SingleOrDefault(x => x.UserName == User.Identity.Name).Id; db = new GiaSuOnlineDB(); User u = db.Users.SingleOrDefault(x => x.id == idIdentity); User admin = db.Users.SingleOrDefault(x => x.id == idAdmin); User GS = db.Users.SingleOrDefault(x => x.id == MaGS); LopHoc lh = db.LopHocs.SingleOrDefault(x => x.MaLH == id); if (u.balance < lh.Gia) { return(Json(new { result = "Không đủ số dư để đăng ký môn học" }, JsonRequestBehavior.AllowGet)); } else { double gia = lh.Gia + lh.Gia * feeService; u.balance -= gia; ThanhToan t = new ThanhToan() { SoTienTT = gia, MaLH = lh.MaLH, MaNH = u.id }; GS.balance += lh.Gia - lh.Gia * feeService; admin.balance += (lh.Gia * feeService) * 2; db.ThanhToans.Add(t); db.SaveChanges(); } return(PartialView("DangKyThanhCong")); }
public void Send(string name, long hash, string message, string sendTo) { Clients.All.addNewMessageToPage(name, message, sendTo); using (GiaSuOnlineDB db = new GiaSuOnlineDB()) { int chatid = db.Chats.SingleOrDefault(p => p.Hash == hash).ChatID; string content = StringCipher.Encrypt(message, name); db.ChatDetails.Add(new ChatDetail { ChatID = chatid, ChatDate = DateTime.Now, ChatUser = name, Content = content }); db.SaveChanges(); } }
public ActionResult XacNhanThanhToan(int id) { db = new GiaSuOnlineDB(); ApplicationDbContext dbIdentity = new ApplicationDbContext(); long hash = new Random().Next(); //MD5 md5 = MD5.Create(); //md5.Initialize(); //md5.ComputeHash(Encoding.UTF8.GetBytes(hash)); LopHoc lh = db.LopHocs.SingleOrDefault(x => x.MaLH == id); double hocPhi = lh.Gia; string idUser = dbIdentity.Users.Single(x => x.UserName == User.Identity.Name).Id; User u = db.Users.Single(x => x.id == idUser); if (checkExists(id, u.id) == true) { return(Json(new { result = "Bạn đã đăng ký khóa học này rồi" }, JsonRequestBehavior.AllowGet)); } if (hocPhi + hocPhi * 0.1 > u.balance) { return(Json(new { result = "Không đủ số dư để thanh toán" }, JsonRequestBehavior.AllowGet)); } else { User gsUser = db.Users.Single(x => x.id == lh.GiaSu.MaGS); User u1 = db.Users.Single(x => x.id == idUser); u1.balance = u.balance - (hocPhi + hocPhi * 0.1); gsUser.balance = gsUser.balance + (hocPhi - hocPhi * 0.1); Chat c = new Chat() { MaLH = id, MaNH = idUser, Hash = hash }; ThanhToan t = new ThanhToan() { MaLH = id, MaNH = u.id, SoTienTT = hocPhi + hocPhi * 0.1, }; db.ThanhToans.Add(t); db.Chats.Add(c); db.SaveChanges(); return(Json(new { hash = c.Hash }, JsonRequestBehavior.AllowGet)); //return Json(new { hash = Guid.NewGuid(), JsonRequestBehavior.AllowGet }); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { dbIdentity = new ApplicationDbContext(); dbGiaSu = new GiaSuOnlineDB(); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); string id = dbIdentity.Users.SingleOrDefault(x => x.UserName == model.Email).Id; User u = new Models.User() { id = id, balance = 0 }; dbGiaSu.Users.Add(u); NguoiHoc nh = new NguoiHoc() { MaNH = id, TenNH = model.Email, Email = model.Email }; dbGiaSu.NguoiHocs.Add(nh); dbGiaSu.SaveChanges(); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "GiaSuOnline")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }