Пример #1
0
        private UserView Add()
        {
            var user = new UserView
            {
                Account = "user" + _time,
                Name = "新用户" + _time,
                OrganizationIds = "3,2"

            };
            _app.AddOrUpdate(user);
            Console.WriteLine(user.Name + " \t用户ID:" + user.Id);
            return user;
        }
Пример #2
0
 public string Add(UserView view)
 {
     try
     {
         _app.AddOrUpdate(view);
         
     }
     catch (Exception ex)
     {
         BjuiResponse.statusCode = "300";
         BjuiResponse.message = ex.Message;
     }
     return JsonHelper.Instance.Serialize(BjuiResponse);
 }
Пример #3
0
        public void TestDel()
        {
            var user = new UserView
            {
                Account = "user" + _time,
                Name = "即将被删除的账号" + _time,
                OrganizationIds = "3,2"

            };
            _app.AddOrUpdate(user);
            Console.WriteLine("new user:" + user.Id);
            _app.Delete(user.Id);
            
        }
Пример #4
0
        public void AddOrUpdate(UserView view)
        {
            User user = view;
            if (user.Id == 0)
            {
                user.CreateTime = DateTime.Now;
                user.Password = user.Account; //初始密码与账号相同
                _repository.Add(user);
                view.Id = user.Id;   //要把保存后的ID存入view
            }
            else
            {
                _repository.Update(user);
            }
            int[] orgIds = view.OrganizationIds.Split(',').Select(id => int.Parse(id)).ToArray();

            _relevanceRepository.DeleteBy("UserOrg", user.Id);
            _relevanceRepository.AddRelevance("UserOrg", orgIds.ToLookup(u =>user.Id));
        }