Beispiel #1
0
        public void Update(AppMenuDTO itemDto)
        {
            //get persisted item
            var persistedModel = _Repository.Get(itemDto.Id);

            if (persistedModel == null)
            {
                throw new DataNotFoundException(WeixinMessagesResources.AppMenu_NotExists);
            }

            var oldDTO = persistedModel.ToDto();

            // 可以修改的字段
            var current = oldDTO.ToModel();

            current.Name      = itemDto.Name;
            current.Key       = itemDto.Key;
            current.Url       = itemDto.Url;
            current.SortOrder = itemDto.SortOrder;
            current.AppId     = itemDto.AppId;
            if (itemDto.Parent != null)
            {
                current.Parent = _Repository.Get(itemDto.Parent.Id);
            }

            // 数据验证
            this.ValidateModel(persistedModel);

            this.OperationLog(WeixinMessagesResources.Update_AppMenu, persistedModel.ToDto(), oldDTO);

            // Merge changes
            _Repository.Merge(persistedModel, current);
            //commit unit of work
            _Repository.UnitOfWork.Commit();
        }
        public ActionResult EditAppMenu(AppMenuDTO appMenu, Guid?parent)
        {
            return(HttpHandleExtensions.AjaxCallGetResult(() =>
            {
                if (parent.HasValue)
                {
                    appMenu.Parent = _appMenuService.FindBy(parent.Value);
                }

                if (appMenu.Id == Guid.Empty)
                {
                    _appMenuService.Add(appMenu);
                    this.JsMessage = MessagesResources.Add_Success;
                }
                else
                {
                    _appMenuService.Update(appMenu);
                    this.JsMessage = MessagesResources.Update_Success;
                }

                return Json(new AjaxResponse
                {
                    Succeeded = true,
                    RedirectUrl = Url.Action("Index")
                });
            }));
        }
        public static string GetOperationLog(this AppMenuDTO entity, AppMenuDTO oldDTO = null)
        {
            var sb = new StringBuilder();

            if (oldDTO == null)
            {
                sb.AppendLine(string.Format("{0}: {1}", CommonMessageResources.Name, entity.Name));
                sb.AppendLine(string.Format("{0}: {1}", CommonMessageResources.Url, entity.Url));
                sb.AppendLine(string.Format("{0}: {1}", WeixinMessagesResources.Key, entity.Key));
                sb.AppendLine(string.Format("{0}: {1}", WeixinMessagesResources.AppId, entity.AppId));
            }
            else
            {
                if (entity.Name != oldDTO.Name)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                CommonMessageResources.Name, oldDTO.Name, entity.Name));
                }
                if (entity.Url != oldDTO.Url)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                CommonMessageResources.Url, oldDTO.Url, entity.Url));
                }
                if (entity.Key != oldDTO.Key)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                WeixinMessagesResources.Key, oldDTO.Key, entity.Key));
                }
                if (entity.AppId != oldDTO.AppId)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                WeixinMessagesResources.AppId, oldDTO.AppId, entity.AppId));
                }

                var parentName = string.Empty;
                if (entity.Parent != null)
                {
                    parentName = entity.Parent.Name;
                }

                var oldParentName = string.Empty;
                if (oldDTO.Parent != null)
                {
                    oldParentName = oldDTO.Parent.Name;
                }

                if (parentName != oldParentName)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                WeixinMessagesResources.Parent, oldParentName, parentName));
                }
            }

            return(sb.ToString().TrimEnd('\r', '\n'));
        }
Beispiel #4
0
        public AppMenuDTO Add(AppMenuDTO itemDto)
        {
            var model = itemDto.ToModel();

            model.Id      = IdentityGenerator.NewSequentialGuid();
            model.Created = DateTime.UtcNow;

            if (model.Parent != null && model.Parent.Id != Guid.Empty)
            {
                model.Parent = _Repository.Get(itemDto.Parent.Id);
            }

            // 数据验证
            this.ValidateModel(model);
            _Repository.Add(model);

            this.OperationLog(WeixinMessagesResources.Add_AppMenu, model.ToDto(), null);

            //commit the unit of work
            _Repository.UnitOfWork.Commit();

            return(model.ToDto());
        }
Beispiel #5
0
 public static AppMenu ToModel(this AppMenuDTO dto)
 {
     return(Mapper.Map <AppMenu>(dto));
 }
Beispiel #6
0
 private void OperationLog(string action, AppMenuDTO itemDto, AppMenuDTO oldDto = null)
 {
     OperateRecorder.RecordOperation(itemDto.Id.ToString(), action,
                                     itemDto.GetOperationLog(oldDto));
 }