public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model.UserName, PhoneNumber = model.DienThoai, Email = model.Email, DiaChi = model.DiaChi, HoTen = model.HoTen, Avatar = "noavatar.jpg" }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddToRole(user.Id, "Khách hàng"); await SignInAsync(user, isPersistent : false); ManagerObiect.getIntance().userName = model.UserName; return(RedirectToAction("Index", "Home")); } else { AddErrors(result); } } return(RedirectToAction("Authentication", "Account")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model.UserName, PhoneNumber = model.DienThoai, Email = model.Email, DiaChi = model.DiaChi, HoTen = model.HoTen, Avatar = "noavatar.jpg" }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddToRole(user.Id, "Khách hàng"); //UserManager.AddToRole(user.Id, "Nhà cung cấp"); await SignInAsync(user, isPersistent : false); ManagerObiect.getIntance().userName = model.UserName; SendMailConfirm(user.Id); return(RedirectToAction("Index", "Home")); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> RegisterB2B(Register2B2ViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email, Avatar = "noavatar.jpg" }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddToRole(user.Id, "Nhà cung cấp"); NhaCungCapModel ncc = new NhaCungCapModel(); ncc.ThemNCC(model, user.Id); await SignInAsync(user, isPersistent : false); ManagerObiect.getIntance().userName = model.UserName; return(RedirectToLocal("/Auction/index")); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Addcart(string sp, int quantity) { try { var temp = db.SanPhams.Find(sp); int index = Kiemtratontai(sp); if (index == -1) { Chitietgiohang tam = new Chitietgiohang(); tam.sanPham = temp; tam.Soluong = quantity; if (temp.SoLuong > quantity) { ManagerObiect.getIntance().giohang.addCart(tam); } else { return(Json("faill")); } } else { ManagerObiect.getIntance().giohang.getGiohang()[index].Soluong += quantity; } return(PartialView("Addcart1", ManagerObiect.getIntance().giohang)); } catch (Exception e) { return(Json("faill")); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await UserManager.FindAsync(model.UserName, model.Password); System.Threading.Thread.Sleep(1000); if (user != null) { await SignInAsync(user, model.RememberMe); ManagerObiect.getIntance().userName = model.UserName; Entities db = new Entities(); avatar = (from p in db.AspNetUsers where p.UserName == model.UserName select p.Avatar).Single().ToString(); Session["Avatar"] = avatar; Session["Name"] = (from p in db.AspNetUsers where p.UserName == model.UserName select p.HoTen).Single().ToString(); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("", "Sai tên tài khoản hoặc mật khẩu"); } } // If we got this far, something failed, redisplay form TempData["ErrorLogin"] = "******"; return(RedirectToAction("Authentication", "Account")); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await UserManager.FindAsync(model.UserName, model.Password); if (user != null) { await SignInAsync(user, model.RememberMe); ManagerObiect.getIntance().userName = model.UserName; //if(UserManager.GetRoles(user.Id).FirstOrDefault() == "Nhà cung cấp") //{ // return RedirectToLocal("/Auction/index"); //} return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("", "Invalid username or password."); } } // If we got this far, something failed, redisplay form return(View(model)); }
public int Kiemtratontai(string id) { for (int i = 0; i < ManagerObiect.getIntance().giohang.getGiohang().Count; i++) { if (ManagerObiect.getIntance().giohang.getGiohang()[i].sanPham.MaSP == id) { return(i); } } return(-1); }
public int Kiemtratontai(int sanPhamId) { for (var i = 0; i < ManagerObiect.getIntance().giohang.getGiohang().Count; i++) { if (ManagerObiect.getIntance().giohang.getGiohang()[i].sanPham.Id == sanPhamId) { return(i); } } return(-1); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContext.ActionParameters.ContainsKey("id")) { string maSP = filterContext.ActionParameters["id"].ToString(); var temp = generateTracking(filterContext, maSP); // them san pham da xem SanPhamModel sp = new SanPhamModel(); ManagerObiect.getIntance().Themsanphammoixem(sp.getSanPham(maSP)); ManagerObiect.getIntance().SaveTrackingLog(temp); } }
public ActionResult Checkout(Donhangtongquan dh) { if (User.Identity.IsAuthenticated) { DonhangKHModel dhmodel = new DonhangKHModel(); dhmodel.Luudonhang(dh, User.Identity.GetUserId(), ManagerObiect.getIntance().giohang); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Checkout", "Home")); } }
private Trackingaction generateTracking(ActionExecutingContext filterContext, string maSP) { Trackingaction temp = new Trackingaction() { Username = (ManagerObiect.getIntance().userName ?? " "), MaSP = maSP, Ngaythuchien = DateTime.Now, Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, Action = filterContext.ActionDescriptor.ActionName }; return(temp); }
public ActionResult Checkout(Donhangtongquan dh) { if (User.Identity.IsAuthenticated) { DonhangKHModel dhmodel = new DonhangKHModel(); if (ManagerObiect.getIntance().giohang.getGiohang().Count() != 0) { dhmodel.Luudonhang(dh, User.Identity.GetUserId(), ManagerObiect.getIntance().giohang); } else { TempData["alert"] = "Bạn chưa có sản phẩm nào"; return(RedirectToAction("Checkout", "Home")); } ManagerObiect.getIntance().giohang.removerCarts(); return(RedirectToAction("Xemdonhang", "Home", new { maKH = User.Identity.GetUserId() })); } else { return(RedirectToAction("Checkout", "Home")); } }
public ActionResult UpdategiohangContent() { return(PartialView("Addcart1", ManagerObiect.getIntance().giohang)); }
// GET: Xuligiohang public ActionResult Xoagiohang(int index) { ManagerObiect.getIntance().giohang.removeCart(index); return(RedirectToAction("basicXuLiGiohang")); }
public ActionResult Thaydoisoluong(int index, string value) { ManagerObiect.getIntance().giohang.Changequanlity(index, value); return(RedirectToAction("basicXuLiGiohang")); }
public ActionResult Cart() { return(View(ManagerObiect.getIntance().giohang)); }
public ActionResult SPMoiXem() { return(PartialView("_RecentlyViewPartial", ManagerObiect.getIntance().Laydanhsachsanphammoixem())); }
public ActionResult Index() { ManagerObiect.getIntance(); return(View()); }
public ActionResult CartOrder() { return(PartialView("Ordercheckout", ManagerObiect.getIntance().giohang)); }
public ActionResult basicXuLiGiohang() { return(PartialView("basicXuLiGiohang", ManagerObiect.getIntance().giohang)); }
public ActionResult CartTitle() { return(PartialView("Addcart1", ManagerObiect.getIntance().giohang)); }
//public ActionResult Sort(string jsonsort) //{ // dynamic item = JObject.Parse(jsonsort); // var term = jsonsort.prop1; // return AdvancedSearchP(null, null, null, null); //} public ActionResult AdvancedSearchP(string term, string loai, string hangsx, string typeview, int?page, int?minprice, int?maxprice, int?typepagelist, int?typesearch, int?typesort) { ViewBag.Name = term; ViewBag.loai = loai; ViewBag.hangsx = hangsx; ViewBag.minprice = minprice; ViewBag.maxprice = maxprice; ViewBag.type = typeview; ViewBag.typesearch = typesearch; ViewBag.typesort = typesort; ViewBag.page = page; ViewBag.typepagelist = typepagelist; // Phân loại search và sort SanPhamModel sp = new SanPhamModel(); IQueryable <SanPham> lst; int loaisearch = (typesearch ?? 0);// kiểu search là null thì sẽ là 0 if (loaisearch == 0) { lst = sp.AdvancedSearch(term, loai, hangsx, minprice, maxprice); if (typesort == 1) { lst = lst.OrderBy(e => e.GiaTien); } else if (typesort == 2) { lst = lst.OrderByDescending(e => e.GiaTien); } else { lst = lst.OrderByDescending(m => m.MaSP); } } else if (loaisearch == 1) { lst = sp.SPKhuyenMai(); if (typesort == 1) { lst = lst.OrderBy(e => e.GiaTien); } else if (typesort == 2) { lst = lst.OrderByDescending(e => e.GiaTien); } else { lst = lst.OrderByDescending(m => m.MaSP); } } else if (loaisearch == 2) { lst = sp.SPBanChay(0); if (typesort == 1) { lst = lst.OrderBy(e => e.GiaTien); } else if (typesort == 2) { lst = lst.OrderByDescending(e => e.GiaTien); } else { lst = lst.OrderByDescending(m => m.MaSP); } } else if (loaisearch == 3) { lst = sp.SPHot(); if (typesort == 1) { lst = lst.OrderBy(e => e.GiaTien); } else if (typesort == 2) { lst = lst.OrderByDescending(e => e.GiaTien); } else { lst = lst.OrderByDescending(m => m.MaSP); } } else if (loaisearch == 4) { lst = sp.SPMoiNhap(); if (typesort == 1) { lst = lst.OrderBy(e => e.GiaTien); } else if (typesort == 2) { lst = lst.OrderByDescending(e => e.GiaTien); } else { lst = lst.OrderByDescending(m => m.MaSP); } } else { lst = ManagerObiect.getIntance().Laydanhsachsanphammoixem().AsQueryable(); if (typesort == 1) { lst = lst.OrderBy(e => e.GiaTien); } else if (typesort == 2) { lst = lst.OrderByDescending(e => e.GiaTien); } else { lst = lst.OrderByDescending(m => m.MaSP); } } // xét phân trang int typePT = (typepagelist ?? 0); if (typePT == 1) { return(PhanTrangAdvanced2(lst, page)); } else { return(PhanTrangAdvanced(lst, page)); } }