예제 #1
0
        public ActionResult Edit(int id)
        {
            var dept = DeptBD.Get(id);
            var m    = new DeptEditVM
            {
                Input = Map <Dept, DeptEditVM.EditInput>(dept)
            };

            foreach (var func in dept.Corp.Funcs)
            {
                m.Input.CorpFuncIds = m.Input.CorpFuncIds + "," + func.Id;
            }
            if (m.Input.CorpFuncIds != "")
            {
                m.Input.CorpFuncIds = m.Input.CorpFuncIds.Substring(1);
            }
            foreach (var func in dept.Funcs)
            {
                m.Input.DeptFuncIds = m.Input.DeptFuncIds + "," + func.Id;
            }
            if (m.Input.DeptFuncIds != "")
            {
                m.Input.DeptFuncIds = m.Input.DeptFuncIds.Substring(1);
            }
            m.CanChangeDeptFunc = IsAdmin();
            return(ForView(m));
        }
예제 #2
0
        private int Save(DeptEditVM.EditInput input, bool changeDeptFunc)
        {
            Dept dept;

            if (input.Id == 0)
            {
                dept       = new Dept();
                dept.Corp  = GetLoginCorp();
                dept.Funcs = new DomainList <Func>();
            }
            else
            {
                dept = DeptBD.Get(input.Id);
            }
            if (!AdminCode.Equals(dept.Code, StringComparison.OrdinalIgnoreCase))
            {
                dept.Code = input.Code;
            }
            dept.Name = input.Name;
            if (IsAdmin() && changeDeptFunc)
            {
                dept.Funcs.Clear();
                if (!string.IsNullOrEmpty(input.DeptFuncIds))
                {
                    Array.ForEach(input.DeptFuncIds.Split(','), o => dept.Funcs.Add(FuncBD.Get(int.Parse(o))));
                }
            }
            DeptBD.Save(dept);
            return(dept.Id);
        }