Exemplo n.º 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
            });
        }
Exemplo n.º 2
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();
            }
        }