コード例 #1
0
ファイル: DbSeed.cs プロジェクト: icdt/ChungSinDrug
        public void SeedManagerAccout()
        {
            ApplicationUserModel user1 = new ApplicationUserModel();
            user1.Id = Guid.NewGuid().ToString();
            user1.UserName = "******";
            user1.Password = "******";

            var userId = UserAccountManager.Create(user1);
            if (!String.IsNullOrWhiteSpace(userId))
            {
                AuthOption aa = new AuthOption();
                aa.AuthOption_Admin = true;

                using (ApplicationDbContext db=new ApplicationDbContext())
                {
                    var theUser = db.Users.FirstOrDefault(a => a.Id == userId);
                    UserAccountManager.InsertOrUpdateAuthOption(theUser, aa);
                }
            }

            EmployeeUserModel emp1 = new EmployeeUserModel();
            emp1.Id = Guid.NewGuid().ToString();
            emp1.UserName = "******";
            emp1.Password = "******";
            emp1.EmployeeProfile_Name = "M";

            var empId = UserAccountManager.CreateEmployee(emp1);
            if (!String.IsNullOrWhiteSpace(empId))
            {
                AuthOption aa = new AuthOption();
                aa.AuthOption_Admin = true;

                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    var theUser = db.Users.FirstOrDefault(a => a.Id == empId);
                    UserAccountManager.InsertOrUpdateAuthOption(theUser, aa);
                }
            }
        }
コード例 #2
0
ファイル: EmployeeProfile.cs プロジェクト: icdt/ChungSinDrug
        public static string CreateEmployee(EmployeeUserModel 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 EmployeeProfile()
                    {
                        Profile_Id = Guid.NewGuid().ToString(),
                        EmployeeProfile_Name = userModel.EmployeeProfile_Name
                    }
                };

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

            }
        }
コード例 #3
0
ファイル: EmployeeProfile.cs プロジェクト: icdt/ChungSinDrug
        public static List<EmployeeUserModel> GetAllEmployees()
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                List<EmployeeUserModel> returnList = new List<EmployeeUserModel>();

                var empolyeeProfiles = db.MemberProfiles.OfType<EmployeeProfile>().AsQueryable();
                var userAccounts = db.Users.ToList();
                foreach (EmployeeProfile item in empolyeeProfiles)
                {
                    var theUserAccount = userAccounts.FirstOrDefault(a => a.IdFK_UserProfile == item.Profile_Id);

                    EmployeeUserModel aa = new EmployeeUserModel();

                    // 帳號資訊
                    aa.Id = theUserAccount.Id;
                    aa.UserName = theUserAccount.UserName;
                    aa.Email = theUserAccount.Email;
                    aa.DelLock = theUserAccount.DelLock;

                    // 基本資料資訊
                    aa.EmployeeProfile_Name = item.EmployeeProfile_Name;

                    // 其他資訊
                    aa.CreateTime = theUserAccount.CreateTime;
                    aa.CreatorId = theUserAccount.CreatorId;
                    aa.CreatorUserName = theUserAccount.CreatorUserName;
                    aa.UpdateTime = theUserAccount.UpdateTime;
                    aa.UpdaterId = theUserAccount.UpdaterId;
                    aa.UpdaterUserName = theUserAccount.UpdaterUserName;

                    returnList.Add(aa);
                }

                return returnList;
            }
        }
コード例 #4
0
ファイル: EmployeeProfile.cs プロジェクト: icdt/ChungSinDrug
        public static void UpdateEmployee(EmployeeUserModel userModel)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var user = db.Users.FirstOrDefault(a => a.Id == userModel.Id);
                var updaterUserAccount = db.Users.FirstOrDefault(a => a.UserName == userModel.UpdaterUserName);

                user.UserName = userModel.UserName;
                user.Email = userModel.Email;
                ((EmployeeProfile)user.UserProfile).EmployeeProfile_Name = userModel.EmployeeProfile_Name;

                user.UpdateTime = DateTime.Now;
                user.UpdaterUserName = userModel.UpdaterUserName;
                user.UpdaterId = updaterUserAccount == null ? "" : updaterUserAccount.Id;

                db.SaveChanges();
            }
        }