Beispiel #1
0
        public ActionResult Update(UserViewModel viewModel)
        {
            if (viewModel.UserContract.DepId == default(Guid))
            {
                ModelState.AddModelError("", "请选择部门");
            }
            else if (viewModel.UserContract.RoleId == default(Guid))
            {
                ModelState.AddModelError("", "请选择角色");
            }
            else if (viewModel.UserContract.IsValid())
            {
                var status = _userService.Update(viewModel.UserContract);
                switch (status)
                {
                    case ResultStatus.Success:
                        return RedirectToAction("Index");
                    case ResultStatus.Failed:
                        ModelState.AddModelError("", string.Format("修改用户信息{0}失败", viewModel.UserContract.NickName));
                        break;
                }
            }

            var roleExpression = new[]
            {
                new ExpressionCriteria{ PropertyName = "IsDel", Value = 0, Operate = Operator.Equal },
            };
            var roles = _roleService.Get(roleExpression, properties: new[] { "Id", "Name" }).Select(p => new SelectListItem
            {
                Text = p.Name,
                Value = p.Id.ToString(),
            }).ToList();
            //var roles = _roleService.GetByUser(CurrentUser.UserName, properties: new[] { "Id", "Name" }).Select(p => new SelectListItem
            //{
            //    Text = p.Name,
            //    Value = p.Id.ToString(),
            //}).ToList();
            ViewData["Roles"] = roles;
            ViewData["RoleItem"] = viewModel.UserContract.RoleId;

            var deptExpression = new[]
            {
                new ExpressionCriteria{ PropertyName = "DEPT_INFO_ISDEL", Value = 0, Operate = Operator.Equal },
            };

            var departs = _departmentService.Get(deptExpression, properties: new[] { "Id", "Name" }).Select(p => new SelectListItem
            {
                Text = p.Name,
                Value = p.Id.ToString(),
            }).ToList();
            //var departs = _departmentService.GetByUser(CurrentUser.UserName, properties: new[] { "Id", "Name" }).Select(p => new SelectListItem
            //{
            //    Text = p.Name,
            //    Value = p.Id.ToString(),
            //}).ToList();
            ViewData["Departments"] = departs;
            ViewData["DepartItem"] = viewModel.UserContract.DepId;

            ModelState.AddModelError("", viewModel.UserContract.ErrorMessage);

            var userInfo = _userService.GetByUniqueId(viewModel.UserContract.Id.ToString());

            if (userInfo != null)
            {
                return View(new UserViewModel(userInfo));
            }
            throw new ItemNotExistException("指定用户不存在!");
        }
Beispiel #2
0
        public ActionResult Create(UserViewModel viewModel)
        {
            var roleExpression = new[]
            {
                new ExpressionCriteria{ PropertyName = "IsDel", Value = 0, Operate = Operator.Equal },
            };
            var roles = _roleService.Get(roleExpression, properties: new[] { "Id", "Name" }).Select(p => new SelectListItem
            {
                Text = p.Name,
                Value = p.Id.ToString(),
            }).ToList(); ;
            //var roles = _roleService.GetByUser(CurrentUser.UserName, properties: new[] { "Id", "Name" }).Select(p => new SelectListItem
            //{
            //    Text = p.Name,
            //    Value = p.Id.ToString(),
            //}).ToList();
            ViewData["Roles"] = roles;

            var deptExpression = new[]
            {
                new ExpressionCriteria{ PropertyName = "DEPT_INFO_ISDEL", Value = 0, Operate = Operator.Equal },
            };

            var departs = _departmentService.Get(deptExpression, properties: new[] { "Id", "Name" }).Select(p => new SelectListItem
            {
                Text = p.Name,
                Value = p.Id.ToString(),
            }).ToList();
            //var departs = _departmentService.GetByUser(CurrentUser.UserName, properties: new[] { "Id", "Name" }).Select(p => new SelectListItem
            //{
            //    Text = p.Name,
            //    Value = p.Id.ToString(),
            //}).ToList();
            ViewData["Departments"] = departs;

            if (viewModel.UserContract.DepId == default(Guid))
            {
                ModelState.AddModelError("", "请选择部门");

            }
            else if (viewModel.UserContract.RoleId == default(Guid))
            {
                ModelState.AddModelError("", "请选择角色");

            }
            else if (viewModel.UserContract.IsValid())
            {

                var rs = _userService.Create(viewModel.UserContract);
                if (rs != ResultStatus.Success)
                {
                    ModelState.AddModelError("", rs == ResultStatus.Duplicate ? "记录已经存在" : "添加失败");
                    return View(new UserViewModel(viewModel.UserContract));
                }
                return RedirectToAction("Index");
            }
            else
            {
                ModelState.AddModelError("", viewModel.UserContract.ErrorMessage);
            }

            return View(new UserViewModel(viewModel.UserContract));
        }