示例#1
0
        public Boolean Create(VMUser vmModel)
        {
            try
            {

                Int32 uId;
                User model;

                // 不允许将密码设置为“**********”
                if (vmModel.U_Password == "**********")
                {
                    return false;
                }

                uId = GetUId();

                model = new User
                {
                    U_Id = uId,
                    Du_Id = vmModel.Du_Id,
                    U_IdCardNumber = vmModel.U_IdCardNumber,
                    U_Name = vmModel.U_Name,
                    U_LoginName = "LoginName" + uId, //[TOKEN_20160815_1559]
                    //U_LoginName = vmModel.Du_Name, //[TOKEN_20160815_1559]
                    U_Password = EncryptPassword(vmModel.U_Password),
                    U_Departments = vmModel.U_Departments,
                    U_Roles = vmModel.U_Roles,
                    U_Remark = vmModel.U_Remark,
                    U_AddTime = vmModel.U_AddTime,
                    U_Status = vmModel.U_Status,
                    U_Sort = uId
                };

                olsEni.Users.Add(model);
                olsEni.SaveChanges();

                UpdateUserDepartment(model);
                UpdateUserRole(model);

                return true;
            }
            catch (Exception ex)
            {
                StaticHelper.RecordSystemLog(ex);
                return false;
            }
        }
示例#2
0
        internal ResponseJson RefreshTime(User u)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Error, now);

            try
            {

                UserOnline uo;

                uo = olsEni.UserOnlines.SingleOrDefault(m => m.U_Id == u.U_Id);

                if (uo == null)
                {
                    uo = new UserOnline
                    {
                        U_Id = u.U_Id,
                        UO_Name = u.U_Name,
                        UO_IdCardNumber = u.U_IdCardNumber,
                        UO_RefreshTime = now
                    };
                    olsEni.Entry(uo).State = EntityState.Added;
                }
                else
                {
                    uo.UO_RefreshTime = now;
                }

                if (0 == olsEni.SaveChanges())
                {
                    resJson.message = ResponseMessage.SaveChangesError;
                    return resJson;
                }

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
示例#3
0
        public void UpdateUserRole(User model)
        {
            List<User_Role> urs;
            Int32[] rs;

            urs = olsEni.User_Role.Where(m => m.U_Id == model.U_Id).ToList();
            foreach (var ud in urs)
            {
                olsEni.Entry(ud).State = EntityState.Deleted;
            }
            olsEni.SaveChanges();

            rs = JsonConvert.DeserializeObject<Int32[]>(model.U_Roles);
            foreach (var r in rs)
            {

                olsEni.User_Role.Add(new User_Role
                {
                    U_Id = model.U_Id,
                    R_Id = Convert.ToInt32(r)
                });
            }
            olsEni.SaveChanges();
        }
示例#4
0
        public void UpdateUserDepartment(User model)
        {
            List<User_Department> uds;
            Int32[] ds;

            uds = olsEni.User_Department.Where(m => m.U_Id == model.U_Id).ToList();
            foreach (var ud in uds)
            {
                olsEni.Entry(ud).State = EntityState.Deleted;
            }
            olsEni.SaveChanges();

            ds = JsonConvert.DeserializeObject<Int32[]>(model.U_Departments);
            foreach (var d in ds)
            {

                olsEni.User_Department.Add(new User_Department
                {
                    U_Id = model.U_Id,
                    D_Id = Convert.ToInt32(d)
                });
            }
            olsEni.SaveChanges();
        }