コード例 #1
0
        public static string Create(ApplicationUserModel userModel)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                ApplicationUserManager userManager = GetUserManager();

                ApplicationUser newUser = new ApplicationUser()
                {
                    UserName = userModel.UserName,
                    Email = userModel.Email,
                    CreateTime = DateTime.Now,
                    CreatorUserName = userModel.CreatorUserName,
                    CreatorId = userModel.CreatorId,
                    UpdateTime = DateTime.Now,
                    UpdaterUserName = userModel.UpdaterUserName,
                    UpdaterId = userModel.UpdaterId
                };

                var userPassword = String.IsNullOrEmpty(userModel.Password) ? "abc123" : userModel.Password;
                var result = userManager.Create(newUser, userPassword);
                if (result.Succeeded)
                {
                    return newUser.Id;
                }
                else
                {
                    return "";
                }

            }
        }
コード例 #2
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // 從外部登入提供者處取得使用者資訊
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
コード例 #3
0
ファイル: CustomerProfile.cs プロジェクト: icdt/ChungSinDrug
        public static string CreateCustomer(CustomerUserModel userModel)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                ApplicationUserManager userManager = GetUserManager();

                var creatorUserAccount = db.Users.FirstOrDefault(a => a.UserName == userModel.CreatorUserName);
                var updaterUserAccount = db.Users.FirstOrDefault(a => a.UserName == userModel.UpdaterUserName);

                ApplicationUser newUser = new ApplicationUser()
                {
                    UserName = userModel.UserName,
                    Email = userModel.Email,
                    CreateTime = DateTime.Now,
                    CreatorUserName = userModel.CreatorUserName,
                    CreatorId = creatorUserAccount == null ? "" : creatorUserAccount.Id,
                    UpdateTime = DateTime.Now,
                    UpdaterUserName = userModel.UpdaterUserName,
                    UpdaterId = updaterUserAccount == null ? "" : updaterUserAccount.Id,
                    UserProfile = new CustomerProfile()
                    {
                        Profile_Id = Guid.NewGuid().ToString(),
                        CustomerProfile_Name = userModel.CustomerProfile_Name
                    }
                };

                var userPassword = String.IsNullOrEmpty(userModel.Password) ? "abc123" : userModel.Password;
                var result = userManager.Create(newUser, userPassword);
                if (result.Succeeded)
                {
                    return newUser.Id;
                }
                else
                {
                    return "";
                }

            }
        }
コード例 #4
0
        public static void InsertOrUpdateAuthOption(ApplicationUser user, AuthOption authOption)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var userInDB = db.Users.FirstOrDefault(a => a.Id == user.Id);
                var authOptionInDB = db.AuthOptions.FirstOrDefault(a => a.AuthOption_Id == userInDB.IdFK_AuthOptions);

                // create
                if (authOptionInDB == null)
                {
                    userInDB.AuthOptions = authOption;
                    db.SaveChanges();
                    return;
                }

                authOptionInDB.AuthOption_Admin = authOption.AuthOption_Admin;
                //authOptionInDB.Taipei = authOption.Taipei;
                //authOptionInDB.Taoyuan = authOption.Taoyuan;
                //authOptionInDB.OrderTrucks = authOption.OrderTrucks;
                //authOptionInDB.OrderAirDoc = authOption.OrderAirDoc;
                //authOptionInDB.OrderInCityDoc = authOption.OrderInCityDoc;
                //authOptionInDB.Bills = authOption.Bills;
                //authOptionInDB.Drivers = authOption.Drivers;
                //authOptionInDB.Sales = authOption.Sales;
                //authOptionInDB.Customers = authOption.Customers;
                //authOptionInDB.PriceTemplate = authOption.PriceTemplate;
                //authOptionInDB.Employee = authOption.Employee;

                db.SaveChanges();
            }
        }