Esempio n. 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;
            }
        }
        public ActionResult Create(VMUser u)
        {
            if (ModelState.IsValid)
            {

                if (um.Create(u))
                {
                    return Redirect("/Contents/html/parent_reload.htm");
                }
            }

            ViewBag.Duties = um.GetDutyList(u.Du_Id);
            ViewBag.Departments = new UDepartment().List();
            ViewBag.Roles = new URole().List();

            return View(u);
        }
Esempio n. 3
0
        public VMUser GetNew()
        {
            VMUser model;

            model = new VMUser()
            {
                U_Id = 0,
                Du_Id = 0,
                Du_Name = "",
                U_Name = "",
                U_LoginName = "LoginName0", //[TOKEN_20160815_1559]
                U_Password = "",
                U_RePassword = "",
                U_Departments = "[]",
                U_Roles = "[]",
                U_Remark = "",
                U_AddTime = DateTime.Now,
                U_Status = (Byte)Status.Available
            };

            return model;
        }
Esempio n. 4
0
        public VMUser Get(Int32 id)
        {
            User model;
            VMUser vmModel;
            Duty duty;
            String duName;

            model = olsEni.Users.Single(m =>
                m.U_Id == id
                && m.U_Status == (Byte)Status.Available);

            if (null != model.Du_Id)
            {
                duty = olsEni.Duties.SingleOrDefault(m => m.Du_Id == model.Du_Id);
                duName = duty.Du_Name;
            }
            else
            {
                duName = "";
            }

            vmModel = new VMUser
            {
                U_Id = model.U_Id,
                Du_Id = model.Du_Id,
                Du_Name = duName,
                U_IdCardNumber = model.U_IdCardNumber,
                U_Name = model.U_Name,
                U_LoginName = model.U_LoginName,
                U_Password = "******",
                U_RePassword = "******",
                U_Departments = model.U_Departments,
                U_Roles = model.U_Roles,
                U_Remark = model.U_Remark,
                U_AddTime = model.U_AddTime,
                U_Status = model.U_Status,
                U_Sort = model.U_Sort
            };

            return vmModel;
        }
Esempio n. 5
0
        public Boolean Edit(VMUser vmModel)
        {
            try
            {

                User model;

                model = olsEni.Users.Single(m =>
                    m.U_Id == vmModel.U_Id
                    && m.U_Status == (Byte)Status.Available);

                model.U_Id = vmModel.U_Id;
                model.Du_Id = vmModel.Du_Id;
                model.U_IdCardNumber = vmModel.U_IdCardNumber;
                model.U_Name = vmModel.U_Name;
                model.U_LoginName = vmModel.U_LoginName;
                model.U_Departments = vmModel.U_Departments;
                model.U_Roles = vmModel.U_Roles;
                model.U_Remark = vmModel.U_Remark;
                model.U_Status = vmModel.U_Status;
                model.U_Sort = vmModel.U_Sort;

                if ("**********" != vmModel.U_Password)
                {
                    model.U_Password = EncryptPassword(vmModel.U_Password);
                }

                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                UpdateUserDepartment(model);
                UpdateUserRole(model);

                return true;
            }
            catch (Exception ex)
            {
                StaticHelper.RecordSystemLog(ex);
                return false;
            }
        }