Пример #1
0
        public ActionResult Edit(int? id)
        {
            User item = null;

            if (id.HasValue)
            {
                item = this.UserRepository.Get(id.Value);
            }

            if (item == null)
            {
                item = new User();
            }

            return View(item);
        }
Пример #2
0
        public void CreateUser()
        {
            for (int i = 0; i < 100; i++)
            {
                User user = new User();
                user.Note = "测试数据";
                user.RealName = String.Format("测试用户{0}", i);
                user.NickName = user.RealName;
                user.Gender = Gender.男;

               // MembershipUser membershipuser = Membership.CreateUser(String.Format("test{0}",i), "123456");
               //user.MemberShipId = (Guid) membershipuser.ProviderUserKey;
                user.MemberShipId = Guid.NewGuid();

                userRepository.SaveOrUpdate(user);
            }

            NHibernateSession.Current.Flush();
        }
Пример #3
0
        //[Test]
        //public Department CreateDepartment()
        //{
        //    IDepartmentRepository departmentRepository = new DepartmentRepository();
        //    var deppart = departmentRepository.SaveOrUpdate(new Department()
        //    {
        //        Name = "内分泌科"
        //    });
        //    departmentRepository.SaveOrUpdate(new Department()
        //    {
        //        Parent = deppart,
        //        Name = "内分泌一组"
        //    });
        //    return departmentRepository.SaveOrUpdate(new Department()
        //    {
        //        Parent = deppart,
        //        Name = "内分泌二组"
        //    });
        //}
        public void CreateUser()
        {
            IUserRepository userRepository = new UserRepository();

               User user = new User();
               user.LoginName = "houck";
               user.RealName = "程康";
               user.NickName = "康康";
               user.Gender = Gender.男;
               user.Mobile = "18653170063";
               user.Enabled = Enabled.启用;
               user.Note = "系统自动添加";
               user.CreateTime = DateTime.Now;

               MembershipUser membershipuser = Membership.CreateUser(user.LoginName, "123");

               user.MemberShipId = (Guid)membershipuser.ProviderUserKey;

               userRepository.SaveOrUpdate(user);
        }
Пример #4
0
        public ActionResult CreateOrUpdate(User user, string psw)
        {
            try
            {
                if (user.Id <= 0)
                {
                    string strUserName = user.CodeNo.Trim();

                    MembershipUser membershipuser = Membership.GetUser(strUserName);

                    if (membershipuser != null)
                    {
                        throw new Exception("工号[" + strUserName + "]已经存在!");
                    }

                    membershipuser = Membership.CreateUser(strUserName, psw);

                    user.MemberShipId = (Guid)membershipuser.ProviderUserKey;
                    user.CreateTime = membershipuser.CreationDate;
                    user.LoginName = user.CodeNo;
                }
                else
                {
                    user = this.UserRepository.Get(user.Id);

                    TryUpdateModel(user);
                }

                user = this.UserRepository.SaveOrUpdate(user);

                return JsonSuccess(user);
            }
            catch (Exception ex)
            {
                return JsonError(ex.Message);
            }
        }
Пример #5
0
        public ActionResult SaveOrUpdate(User user, string psw)
        {
            try
            {
                if (user.Id <= 0)
                {
                    string strUserName = user.LoginName.Trim();

                    MembershipUser membershipuser = Membership.GetUser(strUserName);

                    if (membershipuser != null)
                    {
                        throw new Exception("用户[" + strUserName +"]已经存在,请更换登录名!");
                    }

                    membershipuser = Membership.CreateUser(strUserName, psw);

                    user.MemberShipId = (Guid)membershipuser.ProviderUserKey;

                }
                else
                {
                    user = this.UserRepository.Get(user.Id);

                    TryUpdateModel(user);
                }

                if (user.Pinyin.IsNullOrEmpty() && !user.RealName.IsNullOrEmpty())
                {
                    user.Pinyin = ChineseToSpell.GetChineseSpell(user.RealName);
                }

                user = this.UserRepository.SaveOrUpdate(user);

                return JsonSuccess(user);

            }
            catch (Exception ex)
            {
                return JsonError(ex.Message);
            }
        }
Пример #6
0
 public static UserModel From(User user)
 {
     return new UserModel(user);
 }
Пример #7
0
 public UserModel(User user)
 {
     this.Id = user.Id;
     this.LoginName = user.LoginName;
     this.RealName = user.RealName;
     this.NickName = user.NickName;
     this.Gender = user.Gender.ToString();
     this.Mobile = user.Mobile;
     this.Level = user.Level;
     this.Points = user.Points;
     this.CallTimes = user.CallTimes;
     this.RespondTimes = user.RespondTimes;
     this.ReceiveTimes = user.ReceiveTimes;
     this.Intro = user.Intro;
     this.Note = user.Note;
     this.CreateTime = user.CreateTime.ToJsonString();
 }
Пример #8
0
        public ActionResult UpdateInfo(User user)
        {
            try
            {
                user = this.UserRepository.Get(user.Id);

                TryUpdateModel(user);

                user = this.UserRepository.SaveOrUpdate(user);

                return JsonSuccess(UserModel.From(user));
            }
            catch (Exception ex)
            {
                return JsonError(ex.Message);
            }
        }
Пример #9
0
        public ActionResult Register(string mobile, string psw)
        {
            try
            {
                string strUserName = mobile.Trim();

                MembershipUser membershipuser = Membership.GetUser(strUserName);

                if (membershipuser != null)
                {
                    throw new Exception("该手机号已经注册!");
                }

                membershipuser = Membership.CreateUser(strUserName, psw);

                User user = new User();
                user.LoginName = mobile;
                user.Mobile = mobile;
                user.MemberShipId = (Guid)membershipuser.ProviderUserKey;

                user = this.UserRepository.SaveOrUpdate(user);

                return JsonSuccess(UserModel.From(user));
            }
            catch (Exception ex)
            {
                return JsonError(ex.Message);
            }
        }
Пример #10
0
        public UserModel(User user)
        {
            this.Id = user.Id;

            this.LoginName = user.LoginName;
            this.RealName = user.RealName;
            this.NickName = user.NickName;
            this.GenderStr = user.Gender.ToString();
            this.Mobile = user.Mobile;
            this.EnabledStr = user.Enabled.ToString();
            this.Note = user.Note;

            this.CreateTime = user.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
        }