Beispiel #1
0
        public ActionResult Create(SupplierViewModels model)
        {
            var data = new ResponseModels();

            try
            {
                // TODO: Add insert logic here
                EasyBuyEntities db            = new EasyBuyEntities();
                var             checkSupplier = db.Suppliers.Where(p => p.Name == model.Name).FirstOrDefault();
                if (checkSupplier == null)
                {
                    Models.Supplier supplier = new Models.Supplier
                    {
                        Name    = model.Name,
                        Phone   = model.Phone,
                        City    = model.City,
                        Area    = model.Area,
                        Address = model.Address
                    };
                    db.Suppliers.Add(supplier);
                    db.SaveChanges();
                    data.result = 1;
                }
                else
                {
                    data.msg = "該廠商已存在,請重新建立。";
                }
            }
            catch (Exception e)
            {
                data.msg = e.Message;
            }
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            EasyBuyEntities db   = new EasyBuyEntities();
            var             user = db.Users
                                   .Where(p => p.Email == model.Email && p.Password == model.Password).FirstOrDefault();

            if (user != null)
            {
                SetSissionByUser(user);
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                ViewBag.result = 0;
                return(View(model));
            }
            // 這不會計算為帳戶鎖定的登入失敗
            // 若要啟用密碼失敗來觸發帳戶鎖定,請變更為 shouldLockout: true

            /*ApplicationUser signedUser = UserManager.FindByEmail(model.Email);
             * var result = await SignInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, shouldLockout: false);
             * switch (result)
             * {
             *  case SignInStatus.Success:
             *      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("", "登入嘗試失敗。");
             *      return View(model);
             * }*/
        }