Exemple #1
0
        public static MenuItem CreateFrom(IMenuItemUpdatable fields)
        {
            fields.ThrowIfNull(nameof(fields));

            return(new MenuItem(Guid.NewGuid())
            {
                Name = fields.Name,
                GroupName = fields.GroupName,
                IconName = fields.IconName,
                IsVisible = fields.IsVisible,
                SortOrder = fields.SortOrder,
                CreatedDate = DateTimeOffset.Now
            });
        }
Exemple #2
0
        /// <summary>
        /// 메뉴 아이템을 업데이트한다.
        /// </summary>
        public MenuItem UpdateMenu(Guid menuId, IMenuItemUpdatable fields)
        {
            using (var repo = new MenuRepository())
            {
                var menu = repo.SelectMenu(menuId);
                if (menu == null)
                {
                    throw new ObjectNotFoundException($"업데이트 대상 메뉴를 찾을 수 없습니다.\r\n메뉴 ID: \"{menuId}\"");
                }

                List <UpdatedField> updated = null;
                menu.Update(fields, out updated);

                repo.BeginTransaction();

                try
                {
                    if (repo.UpdateMenu(menu))
                    {
                        repo.UpdateMenuFormMap(menuId, fields.FormTables, DateTimeOffset.Now);
                        repo.CommitTransaction();

                        menu = repo.SelectMenu(menuId);

                        logger.Info(
                            $"메뉴 정보가 업데이트 되었습니다. 메뉴: \"{menu.Name}\""
                            + $"\r\n\r\n"
                            + $"Fields: {UpdatedField.Print(updated)}"
                            + $"\r\n\r\n"
                            + $"{menu}");

                        return(menu);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, $"메뉴 정보를 업데이트 하는 도중 알 수 없는 오류가 발생하였습니다. 메뉴: \"{menu.Name}\""
                                 + $"\r\n\r\n"
                                 + $"{menu}");

                    try
                    {
                        repo.RollBackTransaction();
                    }
                    catch (Exception rex)
                    {
                        logger.Fatal(ex, $"메뉴 정보 업데이트 함수에서 롤백 실행중 치명적인 에러가 발생했습니다. 메뉴: \"{menu.Name}\""
                                     + $"\r\n\r\n"
                                     + $"{menu}");

                        ExceptionDispatchInfo.Capture(rex).Throw();
                        // not reached
                    }

                    ExceptionDispatchInfo.Capture(ex).Throw();
                    return(null); // not reached
                }

                return(null);
            }
        }
Exemple #3
0
        public void Update(IMenuItemUpdatable fields, out List <UpdatedField> updated)
        {
            fields.ThrowIfNull(nameof(fields));

            updated = new List <UpdatedField>();

            if (Name != fields.Name)
            {
                updated.Add(new UpdatedField
                {
                    FieldName = nameof(Name),
                    OldValue  = Name,
                    NewValue  = fields.Name
                });

                Name = fields.Name;
            }

            if (GroupName != fields.GroupName)
            {
                updated.Add(new UpdatedField
                {
                    FieldName = nameof(GroupName),
                    OldValue  = GroupName,
                    NewValue  = fields.GroupName
                });

                GroupName = fields.GroupName;
            }

            if (IconName != fields.IconName)
            {
                updated.Add(new UpdatedField
                {
                    FieldName = nameof(IconName),
                    OldValue  = IconName,
                    NewValue  = fields.IconName
                });

                IconName = fields.IconName;
            }

            if (SortOrder != fields.SortOrder)
            {
                updated.Add(new UpdatedField
                {
                    FieldName = nameof(SortOrder),
                    OldValue  = SortOrder,
                    NewValue  = fields.SortOrder
                });

                SortOrder = fields.SortOrder;
            }

            if (IsVisible != fields.IsVisible)
            {
                updated.Add(new UpdatedField
                {
                    FieldName = nameof(IsVisible),
                    OldValue  = IsVisible,
                    NewValue  = fields.IsVisible
                });

                IsVisible = fields.IsVisible;
            }

            if (fields.FormTables != null && fields.FormTables.Any())
            {
                if (fields.FormTables.Length != FormTables.Count)
                {
                    updated.Add(new UpdatedField
                    {
                        FieldName = nameof(FormTables),
                        OldValue  = $"[ {string.Join(", ", FormTables.Select(o => $"'{o.FormId}'"))} ]",
                        NewValue  = $"[ {string.Join(", ", fields.FormTables.Select(formId => $"'{formId}'"))} ]"
                    });

                    // repository에서 처리
                }
            }

            if (updated.Any())
            {
                UpdatedDate = DateTimeOffset.Now;

                Validate();
            }
        }
Exemple #4
0
        public void Update(IMenuItemUpdatable fields)
        {
            List <UpdatedField> updated = null;

            this.Update(fields, out updated);
        }