public ActionResult CreateUsers()
        {
            var emps         = employeeBll.GetEmployees();
            var emplanguages = employeeBll.GetEmployeeNames();
            List <OperaterAddEdit> operaterModelList = new List <OperaterAddEdit>();

            using (TransactionScope ts = new TransactionScope())
            {
                foreach (var item in emps)
                {
                    if (operatorBll.GetOperatorbyLoginName(item.FNUMBER) == null)
                    {
                        var empL = (from i in emplanguages
                                    where i.FID == item.FID
                                    select i).FirstOrDefault();
                        var operaterModel = new OperaterAddEdit()
                        {
                            Corp      = 1,
                            LoginName = item.FNUMBER,
                            RealName  = empL.FNAME,
                            Password  = Util.GetPassword(item.FNUMBER, "123456"),
                            IdCard    = item.FNUMBER,
                            Email     = item.FNUMBER,
                            Mobile    = item.FNUMBER,
                            Creator   = 0,
                            Role      = "2"
                        };
                        operaterModelList.Add(operaterModel);
                        operatorBll.SaveOperator(operaterModel);
                    }
                }
                ts.Complete();
            }
            return(Json(operaterModelList, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public ActionResult Create(OperaterAddEdit operators)
        {
            var ac = Request["actionName"] ?? "";

            if (ac != "")
            {
                return(OtherAction(ac));
            }
            if (ModelState.IsValid)
            {
                var user = Session[Constants.USER_KEY] as User;
                operators.Corp     = user.SysCorp.ID;
                operators.Creator  = user.SysOperator.ID;
                operators.Password = Util.GetPassword(operators.LoginName, operators.Password.Trim());
                operators.Email    = operators.LoginName;
                operators.IdCard   = operators.LoginName;
                operators.Mobile   = operators.LoginName;
                operators.Role     = operators.Role;
                //if (operatorBll.GetOperatorbyLoginName(operators.LoginName) != null)
                //{
                //    ModelState.AddModelError("LoginName", "当前用户已存在");
                //    return View(operators);
                //}
                if (!operatorBll.SaveOperator(operators))
                {
                    ModelState.AddModelError("errorresult", "添加失败");
                    TempData["resultMsgType"] = "error";
                    TempData["resultMsg"]     = "添加失败";
                    return(View(operators));
                }
                TempData["resultMsgType"] = "success";
                TempData["resultMsg"]     = "添加成功";
                return(RedirectToAction("Index"));
            }
            return(View(operators));
        }