コード例 #1
0
 public void PRecordsUpdate(PreferentialRecords instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("instance");
     }
     else
     {
         Db.Entry(instance).State = EntityState.Modified;
         this.SaveChanges();
     }
 }
コード例 #2
0
 public void PRecordsCreate(PreferentialRecords instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("instance");
     }
     else
     {
         Db.PreferentialRecords.Add(instance);
         this.SaveChanges();
     }
 }
コード例 #3
0
        public ActionResult Login(string returnUrl, string message, int?log)
        {
            if (string.IsNullOrEmpty(User.Identity.GetUserId()))
            {
                ViewBag.ReturnUrl = returnUrl;
                if (message != "")
                {
                    ViewData["Message"] = message;
                }

                if (log == 1)
                {
                    ViewBag.log = log;
                }
                return(View());
            }
            else
            {
                PreferentialRecords pr = new PreferentialRepository().getPRecordsType(User.Identity.GetUserId(), 100);
                if (log == 1)
                {
                    ViewBag.log = log;
                }

                if (pr == null && log == 1)
                {
                    var prm = new PreferentialRecords
                    {
                        UserId         = User.Identity.GetUserId(),
                        Count          = 0,
                        inpdate        = DateTime.Now,
                        PreferentialID = 100
                    };

                    new PreferentialRepository().PRecordsCreate(prm);
                    var ar = new AssetsRecord
                    {
                        UserId  = User.Identity.GetUserId(),
                        unitSn  = 1,
                        assets  = 5000,
                        type    = 2,
                        inpdate = DateTime.Now
                    };
                    new AssetsRepository().AddAssetsByAssets(ar);
                    return(RedirectToAction("Index", "Manage", new { Log = "已贈送5000魚骨幣至您的帳戶" }));
                }
                return(RedirectToAction("Index", "Manage"));
            }
        }
コード例 #4
0
        public ActionResult _FishPay(int id)
        {
            aJaxDto ajd = new aJaxDto();

            try
            {
                if (User.Identity.GetUserId() == null)
                {
                    ajd.ErrorMsg = "登入後才可以購買";
                    ajd.Title    = "未登入!";
                    ajd.isTrue   = true;
                    throw new Exception("error");
                }
                var user = UserManager.FindById(User.Identity.GetUserId());
                if (!user.EmailConfirmed)
                {
                    ajd.ErrorMsg = "請先至會員中心進行驗證,謝謝";
                    ajd.Title    = "Email尚未驗證!";
                    ajd.isTrue   = false;
                    throw new Exception("error");
                }
                if (!user.PhoneNumberConfirmed)
                {
                    ajd.ErrorMsg = "請先至會員中心進行驗證,謝謝";
                    ajd.Title    = "手機尚未驗證!";
                    ajd.isTrue   = false;
                    throw new Exception("error");
                }

                //var pr = new PreferentialRepository().getPRecords(User.Identity.GetUserId());

                //普通首儲

                /*if (pr == null)
                 * {
                 *  var prm = new PreferentialRecords {
                 *      UserId = User.Identity.GetUserId(),
                 *      Count = 1,
                 *      inpdate = DateTime.Now,
                 *      PreferentialID = 1
                 *  };
                 *
                 *  new PreferentialRepository().PRecordsCreate(prm);
                 *  pr = new PreferentialRepository().getPRecords(User.Identity.GetUserId());
                 * }*/
                var pr = new PreferentialRepository().getPRecordsAll(User.Identity.GetUserId()).Where(x => x.PreferentialID == 5);
                //2倍首儲
                if (pr.Count() == 0)
                {
                    var m = new MallRepository().getAll().Where(x => x.unitSn == 3 && x.type == 3).ToList();
                    foreach (var md in m)
                    {
                        var prm = new PreferentialRecords
                        {
                            UserId         = User.Identity.GetUserId(),
                            Count          = 1,
                            inpdate        = DateTime.Now,
                            PreferentialID = 5,
                            productID      = md.id
                        };

                        new PreferentialRepository().PRecordsCreate(prm);
                        //pr = new PreferentialRepository().getPRecords(User.Identity.GetUserId());
                    }
                }
                pr = new PreferentialRepository().getPRecordsAll(User.Identity.GetUserId()).Where(x => x.PreferentialID == 5);



                Product         product    = new MallRepository().Get(id);
                List <Product>  productAll = new MallRepository().getAll();
                cfgUnit         unit       = new UnitsRepository().getValid(product.unitSn);
                ProductApiModel pm         = new ProductApiModel();
                pm.unit       = unit;
                pm.product    = product;
                pm.producList = productAll.Where(x => x.unitSn == 3 && x.type == 3).ToList();

                List <int> fta = new List <int>();
                foreach (var p in pr)
                {
                    if (p.Count != 0)
                    {
                        fta.Add(1);
                    }
                    else
                    {
                        fta.Add(0);
                    }
                }
                pm.firstTypeArray = fta;
                if (pr.Where(x => x.Count != 0).Count() != 0)
                {
                    pm.firstType = 1;
                }
                else
                {
                    pm.firstType = 0;
                }
                //pm.firstType = (pr.Count != 0) ? 1 : 0;
                pm.preferential = new PreferentialRepository().getpreferential(1);
                return(View(pm));
            }
            catch
            {
                return(Json(ajd, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid && new reCAPTCHAHelper().Validate(Request["g-recaptcha-response"]))
            {
                var user = new ApplicationUser {
                    UserName = model.Name, Email = model.Email, Name = model.Name, RegistrationDate = DateTime.Now
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // 傳送包含此連結的電子郵件
                    //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, "熊i猜Email驗證信", "請按此連結確認您的帳戶 <a href=\"" + callbackUrl + "\">驗證</a>");
                    await new AccountModel().RegisterFinsh(user);

                    //寄送驗證信件
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var    callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    string emailBody   = EmailTemplatesService.GetVerifyEmailHTML(callbackUrl);
                    await UserManager.SendEmailAsync(user.Id, "熊i猜Email驗證信", emailBody);

                    if (model.Code != "")
                    {
                        var r = new UserRepository().getRecommend();
                        foreach (var re in r)
                        {
                            var v = new UserRepository().getRecommendStart((int)re.ReId);
                            if (v.edate > DateTime.Now)
                            {
                                if (model.Code == re.code)
                                {
                                    AssetsRecord ar = new AssetsRecord();
                                    ar.assets = (double)v.money;
                                    ar.unitSn = 1;
                                    ar.UserId = user.Id;
                                    new AssetsRepository().AddAssetsByAssets(ar);
                                }
                            }
                        }
                    }
                    if (model.Assets > 5000)
                    {
                        model.Assets = 5000;
                    }

                    if (model.Assets != 0)
                    {
                        AssetsRecord ar2 = new AssetsRecord();
                        ar2.assets = (double)model.Assets;
                        ar2.unitSn = 1;
                        ar2.UserId = user.Id;

                        new AssetsRepository().AddAssetsByAssets(ar2);
                    }
                    var prm = new PreferentialRecords
                    {
                        UserId         = user.Id,
                        Count          = 0,
                        inpdate        = DateTime.Now,
                        PreferentialID = 100
                    };

                    new PreferentialRepository().PRecordsCreate(prm);



                    return(RedirectToAction("Index", "Manage", new { RM = "溫馨提醒:Email以及手機驗證,才可以參與所有競猜活動!!" }));
                }

                AddErrors(result);
            }

            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            return(View(model));
        }
コード例 #6
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl, int?log)
        {
            if (!ModelState.IsValid || !new reCAPTCHAHelper().Validate(Request["g-recaptcha-response"]))
            {
                ViewData["Message"] = "驗證有誤,請重新登入";
                return(View(model));
            }

            // 這不會計算為帳戶鎖定的登入失敗
            // 若要啟用密碼失敗來觸發帳戶鎖定,請變更為 shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Name, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                var live = new UserRepository().getlive();
                var user = UserManager.FindByName(model.Name);

                foreach (var l in live)
                {
                    if (l.username == user.Id)
                    {
                        if (l.valid != 0)
                        {
                            ViewData["Message"] = "此為直播主帳號,無法登入。";
                            return(View(model));
                        }
                        else
                        {
                            ViewData["Message"] = "此帳號還在申請審核中。";
                            return(View(model));
                        }
                    }
                }
                string vClientIP = GetIPAddress();

                new UserRepository().CreateIP(user.Id, vClientIP);

                PreferentialRecords pr = new PreferentialRepository().getPRecordsType(user.Id, 100);



                Session["Assets"] = new AssetsRepository().getAssetsListByUserID(User.Identity.GetUserId());
                //Session["levelExp"] = new AssetsRepository().getExpByUserID(User.Identity.GetUserId());
                if (returnUrl != null)
                {
                    Response.Redirect(returnUrl);
                }

                if (pr == null && log == 1)
                {
                    var prm = new PreferentialRecords
                    {
                        UserId         = user.Id,
                        Count          = 0,
                        inpdate        = DateTime.Now,
                        PreferentialID = 100
                    };

                    new PreferentialRepository().PRecordsCreate(prm);
                    var ar = new AssetsRecord
                    {
                        UserId  = user.Id,
                        unitSn  = 1,
                        assets  = 5000,
                        type    = 2,
                        inpdate = DateTime.Now
                    };
                    new AssetsRepository().AddAssetsByAssets(ar);
                    return(RedirectToAction("Index", "Manage", new { Log = "已贈送5000魚骨幣至您的帳戶" }));
                }

                return(RedirectToAction("Index", "Home"));


            //return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                //ModelState.AddModelError("", "登入嘗試失試。");
                ViewData["Message"] = "登入嘗試失試。";
                return(View(model));
            }
        }