public ActionResult ThemHopDong(HopDongChiNhanh hopdong) { ThongBaoMvc thongbao; var HopDong = new HopDongChiNhanh(); HopDong.MaCN = hopdong.MaCN; HopDong.MaLoaiGianHang = hopdong.MaLoaiGianHang; HopDong.BeginDate = DateTime.Now; HopDong.EndDate = DateTime.Now.AddDays(db.LoaiGianHangs.Find(hopdong.MaLoaiGianHang).TimeUsing); db.HopDongChiNhanhs.Add(hopdong); try { thongbao = new ThongBaoMvc { CssClassName = "success", Message = "Thêm thành công" }; TempData["ResultAction"] = thongbao; db.SaveChanges(); } catch (Exception e) { thongbao = new ThongBaoMvc { CssClassName = "danger", Message = "Lỗi" }; TempData["ResultAction"] = thongbao; log.Error("Lỗi thêm hợp đồng: ", e); } return(View(hopdong)); }
public ActionResult DangKyBaoKimThanhCong(int madangky, string username) { var user = kiemtra.getUser(User.Identity.Name); if (username.Equals(user.UserName)) { int LoaiGianHangId = madangky; var loai = db.LoaiGianHangs.Find(LoaiGianHangId); var hopdong = new HopDongChiNhanh { MaCN = "GianHang-" + username, MaLoaiGianHang = 1, BeginDate = DateTime.Now, EndDate = DateTime.Now.AddDays(30) }; db.HopDongChiNhanhs.Add(hopdong); db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public ActionResult ChinhSuaHopDong(HopDongChiNhanh hopdong) { ThongBaoMvc thongbao; db.Entry(hopdong).State = EntityState.Modified; try { db.SaveChanges(); thongbao = new ThongBaoMvc { CssClassName = "success", Message = "Thay đổi thông tin thành công" }; TempData["ResultAction"] = thongbao; } catch (Exception e) { thongbao = new ThongBaoMvc { CssClassName = "danger", Message = "Lỗi" }; TempData["ResultAction"] = thongbao; log.Error("Lỗi thay đổi thông tin hợp đồng chi nhánh: ", e); } return(View(hopdong)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { int madangky = model.madangky.HasValue ? model.madangky.Value : 1; //Chi nhánh var chinhanh = new ChiNhanh { MaCN = "GianHang-" + model.UserName, Name = "GianHang-" + model.UserName, DiaChi = model.Address, Email = model.Email, SDT = model.SDT, Date = DateTime.Now }; db.ChiNhanhs.Add(chinhanh); //Hợp đồng var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, Address = model.Address, Birthday = model.Birthday, FullName = model.FullName, PhoneNumber = model.SDT, Active = true, Experience = 0, NgayDangKy = DateTime.Now }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { db.SaveChanges(); user.MaCN = chinhanh.MaCN; UserManager.AddToRole(user.Id, "Admin"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); var cn = new ChiNhanh { MaCN = "GianHang-" + model.UserName, Name = "GianHang-" + model.UserName, DiaChi = model.Address, Email = model.Email, SDT = model.SDT, Date = DateTime.Now }; var user1 = new ApplicationUser { UserName = model.UserName, Email = model.Email, Address = model.Address, Birthday = model.Birthday, FullName = model.FullName, PhoneNumber = model.SDT, MaCN = "GianHang-" + model.UserName, Active = true, Experience = 0, NgayDangKy = DateTime.Now }; Configuration.ThemCuaHang(user1, cn); var hopdong = new HopDongChiNhanh { MaCN = chinhanh.MaCN, MaLoaiGianHang = 1, BeginDate = DateTime.Now, EndDate = DateTime.Now.AddDays(7) }; db.HopDongChiNhanhs.Add(hopdong); db.SaveChanges(); if (madangky != 1) { DangKyBaoKim(madangky); } // 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", "Home")); } AddErrors(result); db.ChiNhanhs.Remove(chinhanh); db.SaveChanges(); } // If we got this far, something failed, redisplay form return(View(model)); }