Ejemplo n.º 1
0
        public static FormTableSection CreateFrom(Guid formId, Guid formSectionId, IFormTableSectionUpdatable fields)
        {
            fields.ThrowIfNull(nameof(fields));

            return(new FormTableSection(formId, formSectionId)
            {
                FormSectionName = fields.FormSectionName,
                IsEnabled = fields.IsEnabled,
                ScriptVariable = fields.ScriptVariable,
                //FileTemplate = fields.FileTemplate, // NOTE(jhlee): 여기서 안하고 Create 하는 쪽에서 직접 주입
                CreatedDate = DateTimeOffset.Now
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 대시보드 테이블 업무 영역을 업데이트한다. (필드만 업데이트한다.)
        /// </summary>
        public FormTableSection UpdateFormTableSectionFields(Guid formId, Guid formSectionId, IFormTableSectionUpdatable fields)
        {
            using (var repo = new FormTableRepository())
            {
                var formSection = repo.SelectFormTableSection(formId, formSectionId);
                if (formSection == null)
                {
                    throw new ObjectNotFoundException($"업데이트 할 대상 업무 영역을 찾을 수 없습니다.\r\n업무 영역 ID: \"{formSectionId}\"");
                }

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

                repo.BeginTransaction();

                try
                {
                    if (repo.UpdateFormTableSection(formSection, CurrentUser.UserId))
                    {
                        repo.InsertFormTableSectionGroupMembers(formId, formSectionId, fields.FileSourceUploaders, DateTimeOffset.Now);
                        repo.UpdateDateFileTemplate(formSection.FileTemplate);
                        repo.CommitTransaction();

                        logger.Info($"업무영이 업데이트 되었습니다. 업무영역: \"{formSection.FormSectionName}\""
                                    + $"\r\n\r\n"
                                    + $"updated: {UpdatedField.Print(updated)}"
                                    + $"\r\n\r\n"
                                    + $"{formSection}");

                        return(formSection);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, $"업무영역 필드 업데이트 중 알 수 없는 오류가 발생하였습니다.  업무영역: '{formSection.FormName}/{formSection.FormSectionName}'"
                                 + $"\r\n\r\n"
                                 + $"{formSection}");

                    try
                    {
                        repo.RollBackTransaction();
                    }
                    catch (Exception rex)
                    {
                        logger.Fatal(ex, $"업무영역 필드 업데이트 함수에서 롤백 실행중 치명적인 에러가 발생했습니다.  업무영역: '{formSection.FormName}/{formSection.FormSectionName}'"
                                     + $"\r\n\r\n"
                                     + $"{formSection}");

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

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

                return(null);
            }
        }
Ejemplo n.º 3
0
        public void Update(IFormTableSectionUpdatable fields, out List <UpdatedField> updated)
        {
            fields.ThrowIfNull(nameof(fields));

            updated = new List <UpdatedField>();

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

                FormSectionName = fields.FormSectionName;
            }

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

                ScriptVariable = fields.ScriptVariable;
            }

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

                IsEnabled = fields.IsEnabled;
            }

            var oldUploaders = FileSourceUploaders.Keys.OrderBy(o => o).ToArray();
            var newUploaders = fields.FileSourceUploaders.OrderBy(o => o).ToArray();

            if (!oldUploaders.SequenceEqual(newUploaders))
            {
                updated.Add(new UpdatedField
                {
                    FieldName = nameof(FileSourceUploaders),
                    OldValue  = oldUploaders,
                    NewValue  = newUploaders
                });

                // service 단에서 업데이트 처리함.
            }


            if (fields.FileTemplate != null)
            {
                if (FileTemplate == null)
                {
                    // service 단에서 채워줘야 함.
                }
                else
                {
                    List <UpdatedField> temp = null;
                    FileTemplate.Update(fields.FileTemplate, out temp);

                    updated.AddRange(temp);
                }
            }

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

                Validate();
            }
        }
Ejemplo n.º 4
0
        public void Update(IFormTableSectionUpdatable fields)
        {
            List <UpdatedField> updated = null;

            this.Update(fields, out updated);
        }