Example #1
0
 public DepartmentTypeVM(DepartmentType bo)
 {
     this.ID = bo.ID;
     this.Name = bo.Name;
     this.Description = bo.Description;
     this.SortCode = bo.SortCode;
 }
        public ActionResult CreateOrEdit(Guid id)
        {
            bool isNew = false;
            var bo = _Service.GetSingle(id);
            if (bo == null)
            {
                bo = new DepartmentType();
                bo.ID = id;
                isNew = true;
            }
            var boVM = new DepartmentTypeVM(bo);

            //! 使用调转的方式包括对话框和页面方式
            //var editor = PageComponentRepository<DepartmentTypeVM>.CreateOrEditDialog(boVM, isNew);
            var editor = PageComponentRepository<DepartmentTypeVM>.CreateOrEditPage(boVM, isNew);

            return Json(editor);
        }
        public ActionResult Save(DepartmentTypeVM boVM)
        {
            if (ModelState.IsValid)
            {
                var bo = _Service.GetSingle(boVM.ID);
                if (bo == null)
                {
                    bo = new DepartmentType();
                    bo.ID = boVM.ID;
                }

                boVM.MapToBo(bo);
                _Service.AddOrEditAndSave(bo);

                // 这里采用直接跳转的方式,避开 AjaxForm 回转处理,跳转的时候,在本框架中,一般跳回Index,
                // 如果需要定位页码,类型等,请考虑 Index 中配置好参数,在下面的跳转调用中对应配置好参数即可。
                return JavaScript("window.location.href ='../DepartmentType/Index';");
            }
            else
            {
                var vItems = new List<ValidatorResult>();
                foreach (var item in ModelState)
                {
                    if (item.Value.Errors != null)
                    {
                        foreach (var vItem in item.Value.Errors)
                        {
                            var errItem = new ValidatorResult();
                            errItem.Name = item.Key;
                            errItem.ErrorMessage = vItem.ErrorMessage;
                            vItems.Add(errItem);
                        }
                    }
                }

                //var editor = PageComponentRepository<DepartmentTypeVM>.UpdateCreateOrEditDialog(boVM, false, vItems).InnerHtmlContent;
                var editor = PageComponentRepository<DepartmentTypeVM>.UpdateCreateOrEditPage(boVM, false, vItems).InnerHtmlContent;
                return Json(editor);
            }
        }
Example #4
0
 public void MapToBo(DepartmentType bo)
 {
     bo.Name = this.Name;
     bo.Description = this.Description;
     bo.SortCode = this.SortCode;
 }