Ejemplo n.º 1
0
        // GET: User
        public ActionResult Index()
        {
            db         = new GiaSuOnlineDB();
            dbIdentity = new ApplicationDbContext();
            string id = dbIdentity.Users.SingleOrDefault(x => x.Email == User.Identity.Name).Id;

            if (id != null)
            {
                double balance = db.Users.SingleOrDefault(x => x.id == id).balance;
                if (CheckUser(id))
                {
                    GiaSu gs = db.GiaSus.SingleOrDefault(x => x.MaGS == id);
                    IEnumerable <ThanhToan> listThanhToan = db.ThanhToans.Where(x => x.MaNH == id);
                    List <LopHoc>           LopHocDaMua   = new List <LopHoc>();
                    foreach (var i in listThanhToan)
                    {
                        LopHocDaMua.Add(i.LopHoc);
                    }
                    UserDetail user = new UserDetail()
                    {
                        ID            = gs.MaGS,
                        Email         = gs.Email,
                        Phone         = gs.SDT,
                        Balance       = balance,
                        Name          = gs.TenGS,
                        LopHocDaMua   = LopHocDaMua,
                        LopHocDangDay = gs.LopHocs
                    };
                    return(View(user));
                }
                else
                {
                    NguoiHoc nh = db.NguoiHocs.SingleOrDefault(x => x.MaNH == id);
                    IEnumerable <ThanhToan> listThanhToan = db.ThanhToans.Where(x => x.MaNH == id);
                    List <LopHoc>           LopHocDaMua   = new List <LopHoc>();
                    foreach (var i in listThanhToan)
                    {
                        LopHocDaMua.Add(i.LopHoc);
                    }
                    UserDetail user = new UserDetail()
                    {
                        ID            = nh.MaNH,
                        Email         = nh.Email,
                        Phone         = nh.SDT,
                        Balance       = balance,
                        Name          = nh.TenNH,
                        LopHocDaMua   = LopHocDaMua,
                        LopHocDangDay = new List <LopHoc>()
                    };
                    return(View(user));
                }
            }
            return(Json(new { status = "404" }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        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));
        }