Esempio n. 1
0
        private async Task GenerateDefaultBtn(FormModel formModel)
        {
            if (formModel.TableName == null)
            {
                throw new UserMessageException("Не удалось определить таблицу");
            }
            var btns = new[]
            {
                new { SysName = "Add", Name = "Добавить запись", IconName = "add", IsDetail = false, TypeBtn = TypeBtn.Normal, StylingMode = StylingMode.Contained, Location = Location.Before },
                new { SysName = "Edit", Name = "Редактировать запись", IconName = "edit", IsDetail = false, TypeBtn = TypeBtn.Normal, StylingMode = StylingMode.Contained, Location = Location.Before },
                new { SysName = "Copy", Name = "Копировать запись", IconName = "copy", IsDetail = false, TypeBtn = TypeBtn.Normal, StylingMode = StylingMode.Contained, Location = Location.Before },
                new { SysName = "Save", Name = "Сохранить", IconName = "save", IsDetail = true, TypeBtn = TypeBtn.Success, StylingMode = StylingMode.Outlined, Location = Location.After },
                new { SysName = "Delete", Name = "Удалить запись", IconName = "remove", IsDetail = false, TypeBtn = TypeBtn.Normal, StylingMode = StylingMode.Contained, Location = Location.Before },
                new { SysName = "Refresh", Name = "Обновить данные", IconName = "refresh", IsDetail = false, TypeBtn = TypeBtn.Normal, StylingMode = StylingMode.Contained, Location = Location.Before }
            };

            foreach (var btn in btns)
            {
                var btnModel = await _reportDbContext.ButtonForm.FirstOrDefaultAsync(f => f.FormId == formModel.Id && f.SysName == btn.SysName);

                if (btnModel != null)
                {
                    continue;
                }
                btnModel             = new ButtonForm();
                btnModel.SysName     = btn.SysName;
                btnModel.Height      = 32;
                btnModel.Width       = 32;
                btnModel.DisplayName = "";
                btnModel.ToolTip     = btn.Name;
                btnModel.IsDetail    = btn.IsDetail;
                btnModel.FormModel   = formModel;
                btnModel.IconName    = btn.IconName;
                btnModel.TypeBtn     = btn.TypeBtn;
                btnModel.StylingMode = btn.StylingMode;
                btnModel.Location    = btn.Location;
                await _reportDbContext.AddAsync(btnModel);
            }

            await _reportDbContext.SaveChangesAsync();
        }