示例#1
0
        public IActionResult Create()
        {
            var template = new BEThemeViewModel()
            {
                CreatedBy      = User.Identity.Name,
                Specificulture = CurrentLanguage
            };

            return(View(template));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, BEThemeViewModel template)
        {
            if (id != template.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var result = await template.SaveModelAsync(true).ConfigureAwait(false);

                    if (result.IsSucceed)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        if (result.Exception != null)
                        {
                            ModelState.AddModelError(string.Empty, result.Exception.Message);
                        }

                        foreach (var error in result.Errors)
                        {
                            ModelState.AddModelError(string.Empty, error);
                        }
                        return(View(template));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BEThemeViewModel.Repository.CheckIsExists(m => m.Id == template.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                //return RedirectToAction("Index");
            }
            ViewData["Action"]     = "Edit";
            ViewData["Controller"] = "Template";
            return(View(template));
        }
        private bool InitThemes(SiocCmsContext context, IDbContextTransaction transaction)
        {
            bool isSucceed = true;
            var  getThemes = BEThemeViewModel.Repository.GetModelList(_context: context, _transaction: transaction);

            if (getThemes.IsSucceed && getThemes.Data.Count == 0)
            {
                BEThemeViewModel theme = new BEThemeViewModel(new SiocTheme()
                {
                    Name = "Default",

                    CreatedBy = "Admin"
                }, context, transaction);

                isSucceed = isSucceed && theme.SaveModel(true, context, transaction).IsSucceed;
            }

            return(isSucceed);
        }
        private bool InitThemes(SiocCmsContext context, IDbContextTransaction transaction)
        {
            bool isSucceed = true;
            var  getThemes = BEThemeViewModel.Repository.GetModelList(_context: context, _transaction: transaction);

            if (getThemes.IsSucceed && getThemes.Data.Count == 0)
            {
                //if (getThemes.Data.Count == 0)
                //{
                BEThemeViewModel theme = new BEThemeViewModel(new SiocTheme()
                {
                    Name = "Default",

                    CreatedBy = "Admin"
                }, context, transaction);

                isSucceed = isSucceed && theme.SaveModel(true, context, transaction).IsSucceed;
                //}
                //else
                //{
                //    foreach (var theme in getThemes.Data)
                //    {
                //        string folderPath = CommonHelper.GetFullPath(new string[]
                //        {
                //            SWCmsConstants.Parameters.TemplatesFolder,
                //            theme.Name
                //        });

                //        FileRepository.Instance.DeleteFolder(folderPath);

                //        foreach (var item in theme.Templates)
                //        {
                //            isSucceed = isSucceed && item.SaveModel(true, _context: context, _transaction: transaction).IsSucceed;
                //        }
                //    }
                //}
            }

            return(isSucceed);
        }
示例#5
0
        public async Task <IActionResult> Create(BEThemeViewModel template)
        {
            if (ModelState.IsValid)
            {
                template.CreatedDateTime = DateTime.UtcNow;
                var result = await template.SaveModelAsync(true).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error);
                    }
                    return(View(template));
                }
            }
            return(View(template));
        }
示例#6
0
        public void InitSWCms()
        {
            SiocCmsContext        context        = null;
            SiocCmsAccountContext accountContext = null;
            IDbContextTransaction transaction    = null;

            try
            {
                if (InitConnectionString())
                {
                    context        = new SiocCmsContext();
                    accountContext = new SiocCmsAccountContext();
                    context.Database.Migrate();
                    accountContext.Database.Migrate();
                    transaction = context.Database.BeginTransaction();
                    bool isSucceed = true;
                    //var getConnectionString = BEParameterViewModel.Repository.GetSingleModel(
                    //    c => c.Name == SWCmsConstants.ConfigurationKeyword.ConnectionString,
                    //    _context: context, _transaction: transaction);

                    //if (!getConnectionString.IsSucceed)
                    //{
                    //    BEParameterViewModel cnn = new BEParameterViewModel()
                    //    {
                    //        Name = SWCmsConstants.ConfigurationKeyword.ConnectionString,
                    //        Value = ConnectionString,
                    //        Description = SWCmsConstants.ConfigurationType.System
                    //    };
                    //    cnn.SaveModel(_context: context, _transaction: transaction);
                    //}

                    // EN-US
                    var getCulture = BECultureViewModel.Repository.GetSingleModel(
                        c => c.Specificulture == "en-us",
                        _context: context,
                        _transaction: transaction);

                    if (!getCulture.IsSucceed)
                    {
                        BECultureViewModel cultureViewModel = new BECultureViewModel()
                        {
                            Specificulture = "en-us",
                            FullName       = "United States",
                            Description    = "United States",
                            Icon           = "flag-icon-us",
                            Alias          = "US"
                        };
                        isSucceed = isSucceed && cultureViewModel.SaveModel(_context: context, _transaction: transaction).IsSucceed;
                    }

                    // VI-VN
                    getCulture = BECultureViewModel.Repository.GetSingleModel(
                        c => c.Specificulture == "vi-vn",
                        _context: context,
                        _transaction: transaction);

                    if (!getCulture.IsSucceed)
                    {
                        BECultureViewModel cultureViewModel = new BECultureViewModel()
                        {
                            Specificulture = "vi-vn",
                            FullName       = "Vietnam",
                            Description    = "Việt Nam",
                            Icon           = "flag-icon-vn",
                            Alias          = "VN"
                        };
                        isSucceed = isSucceed && cultureViewModel.SaveModel(_context: context, _transaction: transaction).IsSucceed;
                    }

                    var getPosition = BEPositionViewModel.Repository.GetModelList(_context: context, _transaction: transaction);
                    if (isSucceed && (!getPosition.IsSucceed || getPosition.Data.Count == 0))
                    {
                        BEPositionViewModel p = new BEPositionViewModel()
                        {
                            Description = nameof(SWCmsConstants.CatePosition.Nav)
                        };
                        isSucceed = isSucceed && p.SaveModel(_context: context, _transaction: transaction).IsSucceed;
                        p         = new BEPositionViewModel()
                        {
                            Description = nameof(SWCmsConstants.CatePosition.Top)
                        };
                        isSucceed = isSucceed && p.SaveModel(_context: context, _transaction: transaction).IsSucceed;
                        p         = new BEPositionViewModel()
                        {
                            Description = nameof(SWCmsConstants.CatePosition.Left)
                        };
                        isSucceed = isSucceed && p.SaveModel(_context: context, _transaction: transaction).IsSucceed;
                        p         = new BEPositionViewModel()
                        {
                            Description = nameof(SWCmsConstants.CatePosition.Footer)
                        };
                        isSucceed = isSucceed && p.SaveModel(_context: context, _transaction: transaction).IsSucceed;
                    }
                    var getThemes = BEThemeViewModel.Repository.GetModelList(_context: context, _transaction: transaction);
                    if (isSucceed && getThemes.IsSucceed)
                    {
                        if (getThemes.Data.Count == 0)
                        {
                            BEThemeViewModel theme = new BEThemeViewModel(new SiocTheme()
                            {
                                Name = "Default",

                                CreatedBy = "Admin"
                            })
                            {
                                IsActived      = true,
                                Specificulture = "vi-vn"
                            };

                            isSucceed = isSucceed && theme.SaveModel(true, context, transaction).IsSucceed;

                            if (isSucceed)
                            {
                                ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel(
                                                                     c => c.Keyword == SWCmsConstants.ConfigurationKeyword.Theme && c.Specificulture == "vi-vn", context, transaction)).Data;
                                if (config == null)
                                {
                                    config = new ConfigurationViewModel()
                                    {
                                        Keyword        = SWCmsConstants.ConfigurationKeyword.Theme,
                                        Specificulture = "vi-vn",
                                        Category       = SWCmsConstants.ConfigurationType.User,
                                        DataType       = SWCmsConstants.DataType.String,
                                        Description    = "Cms Theme",

                                        Value = ""
                                    };
                                }
                                else
                                {
                                    config.Value = theme.Name;
                                }
                                isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed;
                            }

                            if (isSucceed)
                            {
                                ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel(
                                                                     c => c.Keyword == SWCmsConstants.ConfigurationKeyword.ThemeId && c.Specificulture == "vi-vn", context, transaction)).Data;
                                if (config == null)
                                {
                                    config = new ConfigurationViewModel()
                                    {
                                        Keyword        = SWCmsConstants.ConfigurationKeyword.Theme,
                                        Specificulture = "vi-vn",
                                        Category       = SWCmsConstants.ConfigurationType.User,
                                        DataType       = SWCmsConstants.DataType.String,
                                        Description    = "Cms Theme",

                                        Value = theme.Model.Id.ToString()
                                    };
                                }
                                else
                                {
                                    config.Value = theme.Model.Id.ToString();
                                }
                                isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed;
                            }

                            if (isSucceed)
                            {
                                ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel(
                                                                     c => c.Keyword == SWCmsConstants.ConfigurationKeyword.Theme && c.Specificulture == "en-us", context, transaction)).Data;
                                if (config == null)
                                {
                                    config = new ConfigurationViewModel()
                                    {
                                        Keyword        = SWCmsConstants.ConfigurationKeyword.Theme,
                                        Specificulture = "en-us",
                                        Category       = SWCmsConstants.ConfigurationType.User,
                                        DataType       = SWCmsConstants.DataType.String,
                                        Description    = "Cms Theme",

                                        Value = theme.Name
                                    };
                                }
                                else
                                {
                                    config.Value = Name;
                                }
                                isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed;
                            }

                            if (isSucceed)
                            {
                                ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel(
                                                                     c => c.Keyword == SWCmsConstants.ConfigurationKeyword.ThemeId && c.Specificulture == "en-us", context, transaction)).Data;
                                if (config == null)
                                {
                                    config = new ConfigurationViewModel()
                                    {
                                        Keyword        = SWCmsConstants.ConfigurationKeyword.ThemeId,
                                        Specificulture = "en-us",
                                        Category       = SWCmsConstants.ConfigurationType.User,
                                        DataType       = SWCmsConstants.DataType.String,
                                        Description    = "Cms Theme",

                                        Value = theme.Model.Id.ToString()
                                    };
                                }
                                else
                                {
                                    config.Value = theme.Model.Id.ToString();
                                }
                                isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed;
                            }
                            if (isSucceed)
                            {
                                InitConfigurations(context, transaction);
                            }
                        }
                        else
                        {
                            foreach (var theme in getThemes.Data)
                            {
                                string folderPath = CommonHelper.GetFullPath(new string[]
                                {
                                    SWCmsConstants.Parameters.TemplatesFolder,
                                    theme.Name
                                });

                                var delFolder = FileRepository.Instance.DeleteFolder(folderPath);

                                foreach (var item in theme.Templates)
                                {
                                    try
                                    {
                                        isSucceed = isSucceed && item.SaveModel(true, _context: context, _transaction: transaction).IsSucceed;
                                    }
                                    catch { }
                                }
                            }
                        }
                    }

                    if (isSucceed)
                    {
                        BECategoryViewModel cate = new BECategoryViewModel(new SiocCategory()
                        {
                            Title          = "Home",
                            Specificulture = "vi-vn",
                            Template       = "_Home",
                            Type           = (int)SWCmsConstants.CateType.Home,
                            CreatedBy      = "Admin"
                        });

                        isSucceed = isSucceed && cate.SaveModel(false, context, transaction).IsSucceed;
                        BECategoryViewModel uscate = new BECategoryViewModel(new SiocCategory()
                        {
                            Title          = "Home",
                            Specificulture = "en-us",
                            Template       = "_Home",
                            Type           = (int)SWCmsConstants.CateType.Home,
                            CreatedBy      = "Admin"
                        });
                        isSucceed = isSucceed && uscate.SaveModel(false, context, transaction).IsSucceed;
                    }


                    if (isSucceed)
                    {
                        GlobalLanguageService.Instance.RefreshCultures(context, transaction);

                        transaction.Commit();
                        IsInit = true;
                    }
                    else
                    {
                        transaction.Rollback();
                        IsInit = false;
                    }
                }
            }
            catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only
            {
                IsInit = false;
                transaction?.Rollback();
                throw ex;
            }
            finally
            {
                context?.Dispose();
                accountContext?.Dispose();
            }
        }
        public void InitSWCms()
        {
            SiocCmsContext        context        = null;
            SiocCmsAccountContext accountContext = null;
            IDbContextTransaction transaction    = null;

            try
            {
                if (InitConnectionString())
                {
                    context        = new SiocCmsContext();
                    accountContext = new SiocCmsAccountContext();
                    context.Database.Migrate();
                    accountContext.Database.Migrate();
                    transaction = context.Database.BeginTransaction();

                    var getConnectionString = BEParameterViewModel.Repository.GetSingleModel(
                        c => c.Name == SWCmsConstants.ConfigurationKeyword.ConnectionString,
                        _context: context, _transaction: transaction);

                    if (!getConnectionString.IsSucceed)
                    {
                        BEParameterViewModel cnn = new BEParameterViewModel()
                        {
                            Name        = SWCmsConstants.ConfigurationKeyword.ConnectionString,
                            Value       = ConnectionString,
                            Description = SWCmsConstants.ConfigurationType.System
                        };
                        cnn.SaveModel(_context: context, _transaction: transaction);
                    }

                    // EN-US
                    var getCulture = BECultureViewModel.Repository.GetSingleModel(
                        c => c.Specificulture == "en-us",
                        _context: context,
                        _transaction: transaction);

                    if (!getCulture.IsSucceed)
                    {
                        BECultureViewModel cultureViewModel = new BECultureViewModel()
                        {
                            Specificulture = "en-us",
                            FullName       = "United States",
                            Description    = "United States",
                            Icon           = "flag-icon-us",
                            Alias          = "US"
                        };
                        cultureViewModel.SaveModel(_context: context, _transaction: transaction);
                    }

                    // VI-VN
                    getCulture = BECultureViewModel.Repository.GetSingleModel(
                        c => c.Specificulture == "vi-vn",
                        _context: context,
                        _transaction: transaction);

                    if (!getCulture.IsSucceed)
                    {
                        BECultureViewModel cultureViewModel = new BECultureViewModel()
                        {
                            Specificulture = "vi-vn",
                            FullName       = "Vietnam",
                            Description    = "Việt Nam",
                            Icon           = "flag-icon-vn",
                            Alias          = "VN"
                        };
                        cultureViewModel.SaveModel(_context: context, _transaction: transaction);
                    }

                    var getPosition = BEPositionViewModel.Repository.GetModelList(_context: context, _transaction: transaction);
                    if (!getPosition.IsSucceed || getPosition.Data.Count == 0)
                    {
                        BEPositionViewModel p = new BEPositionViewModel()
                        {
                            Description = nameof(SWCmsConstants.CatePosition.Top)
                        };
                        p.SaveModel(_context: context, _transaction: transaction);
                        p = new BEPositionViewModel()
                        {
                            Description = nameof(SWCmsConstants.CatePosition.Left)
                        };
                        p.SaveModel(_context: context, _transaction: transaction);
                        p = new BEPositionViewModel()
                        {
                            Description = nameof(SWCmsConstants.CatePosition.Footer)
                        };
                        p.SaveModel(_context: context, _transaction: transaction);
                    }
                    var getThemes = BEThemeViewModel.Repository.GetModelList(_context: context, _transaction: transaction);
                    if (getThemes.IsSucceed)
                    {
                        if (getThemes.Data.Count == 0)
                        {
                            BEThemeViewModel theme = new BEThemeViewModel(new SiocTheme()
                            {
                                Name      = "Default",
                                CreatedBy = "Admin"
                            })
                            {
                                IsActived = true
                            };

                            theme.SaveModel(true, context, transaction);
                        }
                        else
                        {
                            foreach (var theme in getThemes.Data)
                            {
                                string folderPath = CommonHelper.GetFullPath(new string[]
                                {
                                    SWCmsConstants.Parameters.TemplatesFolder,
                                    theme.Name
                                });

                                var delFolder = FileRepository.Instance.DeleteFolder(folderPath);

                                foreach (var item in theme.Templates)
                                {
                                    try
                                    {
                                        item.SaveModel(true, _context: context, _transaction: transaction);
                                    }
                                    catch { }
                                }
                            }
                        }
                    }

                    GlobalLanguageService.Instance.RefreshCultures(context, transaction);
                    InitConfigurations(context, transaction);
                    transaction.Commit();
                    IsInit = true;
                }
            }
            catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only
            {
                IsInit = false;
                transaction?.Rollback();
                throw ex;
            }
            finally
            {
                context?.Dispose();
                accountContext?.Dispose();
            }
        }
        private bool InitThemes(SiocCmsContext context, IDbContextTransaction transaction)
        {
            bool isSucceed = true;
            var  getThemes = BEThemeViewModel.Repository.GetModelList(_context: context, _transaction: transaction);

            if (getThemes.IsSucceed && getThemes.Data.Count == 0)
            {
                if (getThemes.Data.Count == 0)
                {
                    BEThemeViewModel theme = new BEThemeViewModel(new SiocTheme()
                    {
                        Name = "Default",

                        CreatedBy = "Admin"
                    })
                    {
                        IsActived      = true,
                        Specificulture = "vi-vn"
                    };

                    isSucceed = isSucceed && theme.SaveModel(true, context, transaction).IsSucceed;

                    if (isSucceed)
                    {
                        ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel(
                                                             c => c.Keyword == SWCmsConstants.ConfigurationKeyword.Theme && c.Specificulture == "vi-vn", context, transaction)).Data;
                        if (config == null)
                        {
                            config = new ConfigurationViewModel()
                            {
                                Keyword        = SWCmsConstants.ConfigurationKeyword.Theme,
                                Specificulture = "vi-vn",
                                Category       = SWCmsConstants.ConfigurationType.User,
                                DataType       = SWCmsConstants.DataType.String,
                                Description    = "Cms Theme",

                                Value = ""
                            };
                        }
                        else
                        {
                            config.Value = theme.Name;
                        }
                        isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed;
                    }

                    if (isSucceed)
                    {
                        ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel(
                                                             c => c.Keyword == SWCmsConstants.ConfigurationKeyword.ThemeId && c.Specificulture == "vi-vn", context, transaction)).Data;
                        if (config == null)
                        {
                            config = new ConfigurationViewModel()
                            {
                                Keyword        = SWCmsConstants.ConfigurationKeyword.Theme,
                                Specificulture = "vi-vn",
                                Category       = SWCmsConstants.ConfigurationType.User,
                                DataType       = SWCmsConstants.DataType.String,
                                Description    = "Cms Theme",

                                Value = theme.Model.Id.ToString()
                            };
                        }
                        else
                        {
                            config.Value = theme.Model.Id.ToString();
                        }
                        isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed;
                    }

                    if (isSucceed)
                    {
                        ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel(
                                                             c => c.Keyword == SWCmsConstants.ConfigurationKeyword.Theme && c.Specificulture == "en-us", context, transaction)).Data;
                        if (config == null)
                        {
                            config = new ConfigurationViewModel()
                            {
                                Keyword        = SWCmsConstants.ConfigurationKeyword.Theme,
                                Specificulture = "en-us",
                                Category       = SWCmsConstants.ConfigurationType.User,
                                DataType       = SWCmsConstants.DataType.String,
                                Description    = "Cms Theme",

                                Value = theme.Name
                            };
                        }
                        else
                        {
                            config.Value = Name;
                        }
                        isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed;
                    }

                    if (isSucceed)
                    {
                        ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel(
                                                             c => c.Keyword == SWCmsConstants.ConfigurationKeyword.ThemeId && c.Specificulture == "en-us", context, transaction)).Data;
                        if (config == null)
                        {
                            config = new ConfigurationViewModel()
                            {
                                Keyword        = SWCmsConstants.ConfigurationKeyword.ThemeId,
                                Specificulture = "en-us",
                                Category       = SWCmsConstants.ConfigurationType.User,
                                DataType       = SWCmsConstants.DataType.String,
                                Description    = "Cms Theme",

                                Value = theme.Model.Id.ToString()
                            };
                        }
                        else
                        {
                            config.Value = theme.Model.Id.ToString();
                        }
                        isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed;
                    }
                    if (isSucceed)
                    {
                        InitConfigurations(context, transaction);
                    }
                }
                else
                {
                    foreach (var theme in getThemes.Data)
                    {
                        string folderPath = CommonHelper.GetFullPath(new string[]
                        {
                            SWCmsConstants.Parameters.TemplatesFolder,
                            theme.Name
                        });

                        var delFolder = FileRepository.Instance.DeleteFolder(folderPath);

                        foreach (var item in theme.Templates)
                        {
                            try
                            {
                                isSucceed = isSucceed && item.SaveModel(true, _context: context, _transaction: transaction).IsSucceed;
                            }
                            catch { }
                        }
                    }
                }
            }

            return(isSucceed);
        }