Esempio n. 1
0
 protected static void InitPages(string culture, MixCmsContext context, IDbContextTransaction transaction)
 {
     V_0 = JObject.Parse(FileRepository.get_Instance().GetFile("pages.json", "data", true, "{}").get_Content()).get_Item("data").ToObject <List <MixPage> >().GetEnumerator();
     try
     {
         while (V_0.MoveNext())
         {
             V_1 = V_0.get_Current();
             V_1.set_Specificulture(culture);
             V_1.set_SeoTitle(V_1.get_Title().ToLower());
             V_1.set_SeoName(SeoHelper.GetSEOString(V_1.get_Title(), '-'));
             V_1.set_SeoDescription(V_1.get_Title().ToLower());
             V_1.set_SeoKeywords(V_1.get_Title().ToLower());
             V_1.set_CreatedDateTime(DateTime.get_UtcNow());
             V_1.set_CreatedBy("SuperAdmin");
             context.Entry <MixPage>(V_1).set_State(4);
             stackVariable43 = new MixUrlAlias();
             stackVariable43.set_Id(V_1.get_Id());
             stackVariable43.set_SourceId(V_1.get_Id().ToString());
             stackVariable43.set_Type(0);
             stackVariable43.set_Specificulture(culture);
             stackVariable43.set_CreatedDateTime(DateTime.get_UtcNow());
             stackVariable43.set_Alias(V_1.get_Title().ToLower());
             stackVariable43.set_Status(2.ToString());
             context.Entry <MixUrlAlias>(stackVariable43).set_State(4);
         }
     }
     finally
     {
         ((IDisposable)V_0).Dispose();
     }
     return;
 }
Esempio n. 2
0
        protected bool InitPositions(MixCmsContext context, IDbContextTransaction transaction)
        {
            bool isSucceed = true;
            var  count     = context.MixPortalPage.Count();

            if (count == 0)
            {
                var p = new MixPosition()
                {
                    Description = nameof(MixEnums.CatePosition.Nav)
                };
                context.Entry(p).State = EntityState.Added;
                p = new MixPosition()
                {
                    Description = nameof(MixEnums.CatePosition.Top)
                };
                context.Entry(p).State = EntityState.Added;
                p = new MixPosition()
                {
                    Description = nameof(MixEnums.CatePosition.Left)
                };
                context.Entry(p).State = EntityState.Added;
                p = new MixPosition()
                {
                    Description = nameof(MixEnums.CatePosition.Footer)
                };
                context.Entry(p).State = EntityState.Added;

                context.SaveChanges();
            }
            return(isSucceed);
        }
Esempio n. 3
0
        protected static void InitPages(string culture, MixCmsContext context, IDbContextTransaction transaction)
        {
            /* Init Languages */
            var pages   = FileRepository.Instance.GetFile(MixConstants.CONST_FILE_PAGES, "data", true, "{}");
            var obj     = JObject.Parse(pages.Content);
            var arrPage = obj["data"].ToObject <List <MixPage> >();

            foreach (var page in arrPage)
            {
                page.Specificulture       = culture;
                page.SeoTitle             = page.Title.ToLower();
                page.SeoName              = SeoHelper.GetSEOString(page.Title);
                page.SeoDescription       = page.Title.ToLower();
                page.SeoKeywords          = page.Title.ToLower();
                page.CreatedDateTime      = DateTime.UtcNow;
                page.CreatedBy            = "SuperAdmin";
                context.Entry(page).State = EntityState.Added;
                var alias = new MixUrlAlias()
                {
                    Id              = page.Id,
                    SourceId        = page.Id.ToString(),
                    Type            = (int)UrlAliasType.Page,
                    Specificulture  = culture,
                    CreatedDateTime = DateTime.UtcNow,
                    Alias           = page.Title.ToLower(),
                    Status          = (int)MixContentStatus.Published
                };
                context.Entry(alias).State = EntityState.Added;
            }
        }
Esempio n. 4
0
        public static async Task <RepositoryResponse <bool> > ImportData(
            string culture, Lib.ViewModels.MixAttributeSets.ReadViewModel attributeSet, IFormFile file)
        {
            using (var context = new MixCmsContext())
            {
                var result = new RepositoryResponse <bool>()
                {
                    IsSucceed = true
                };
                try
                {
                    List <ImportViewModel> data = LoadFileData(culture, attributeSet, file);

                    var fields   = MixAttributeFields.UpdateViewModel.Repository.GetModelListBy(f => f.AttributeSetId == attributeSet.Id).Data;
                    var priority = ImportViewModel.Repository.Count(m => m.AttributeSetName == attributeSet.Name && m.Specificulture == culture).Data;
                    foreach (var item in data)
                    {
                        priority += 1;

                        //item.Model.Id = Guid.NewGuid().ToString();
                        //item.Model.Specificulture = culture;
                        //item.Model.CreatedDateTime = DateTime.UtcNow;
                        //item.Model.Priority = context.MixAttributeSetData.Count() + 1;
                        item.Priority         = priority;
                        item.Fields           = fields;
                        item.AttributeSetName = attributeSet.Name;
                        item.ParseModel();
                        context.Entry(item.Model).State = Microsoft.EntityFrameworkCore.EntityState.Added;
                        foreach (var val in item.Values)
                        {
                            val.DataId         = item.Id;
                            val.Specificulture = culture;
                            val.ParseModel();
                            //val.Model.DataId = item.Id;
                            //val.Model.CreatedDateTime = DateTime.UtcNow;
                            //val.Model.Specificulture = culture;
                            //val.Model.Id = Guid.NewGuid().ToString();
                            context.Entry(val.Model).State = Microsoft.EntityFrameworkCore.EntityState.Added;
                        }
                    }
                    int tmp = await context.SaveChangesAsync();

                    //if (result.IsSucceed)
                    //{
                    //    foreach (var item in data)
                    //    {
                    //       item.GenerateCache(item.Model, item);
                    //    }
                    //}
                    return(result);
                }
                catch (Exception ex)
                {
                    result.IsSucceed = false;
                    result.Exception = ex;
                    result.Errors.Add(ex.Message);
                    return(result);
                }
            }
        }
Esempio n. 5
0
 protected static bool InitCultures(InitCulture culture, MixCmsContext context, IDbContextTransaction transaction)
 {
     V_0 = true;
     try
     {
         if (context.get_MixCulture().Count <MixCulture>() == 0)
         {
             stackVariable5 = new MixCulture();
             stackVariable5.set_Id(1);
             stackVariable5.set_Specificulture(culture.get_Specificulture());
             stackVariable5.set_FullName(culture.get_FullName());
             stackVariable5.set_Description(culture.get_Description());
             stackVariable5.set_Icon(culture.get_Icon());
             stackVariable5.set_Alias(culture.get_Alias());
             stackVariable5.set_Status(2.ToString());
             stackVariable5.set_CreatedDateTime(DateTime.get_UtcNow());
             context.Entry <MixCulture>(stackVariable5).set_State(4);
             dummyVar0 = context.SaveChanges();
         }
     }
     catch
     {
         dummyVar1 = exception_0;
         V_0       = false;
     }
     return(V_0);
 }
Esempio n. 6
0
        protected bool InitCultures(InitCulture culture, MixCmsContext context, IDbContextTransaction transaction)
        {
            bool isSucceed = true;

            try
            {
                if (context.MixCulture.Count() == 0)
                {
                    // EN-US

                    var enCulture = new MixCulture()
                    {
                        Specificulture = culture.Specificulture,
                        FullName       = culture.FullName,
                        Description    = culture.Description,
                        Icon           = culture.Icon,
                        Alias          = culture.Alias,
                        Status         = (int)MixEnums.MixContentStatus.Published
                    };
                    context.Entry(enCulture).State = EntityState.Added;

                    context.SaveChanges();
                }
            }
            catch
            {
                isSucceed = false;
            }
            return(isSucceed);
        }
Esempio n. 7
0
        public async Task <RepositoryResponse <bool> > InitCms(string siteName, InitCulture culture)
        {
            RepositoryResponse <bool> result         = new RepositoryResponse <bool>();
            MixCmsContext             context        = null;
            MixCmsAccountContext      accountContext = null;
            MixChatServiceContext     messengerContext;
            IDbContextTransaction     transaction    = null;
            IDbContextTransaction     accTransaction = null;
            bool isSucceed = true;

            try
            {
                if (!string.IsNullOrEmpty(MixService.GetConnectionString(MixConstants.CONST_CMS_CONNECTION)))
                {
                    context          = new MixCmsContext();
                    accountContext   = new MixCmsAccountContext();
                    messengerContext = new MixChatServiceContext();
                    //MixChatServiceContext._cnn = MixService.GetConnectionString(MixConstants.CONST_CMS_CONNECTION);
                    await context.Database.MigrateAsync();

                    await accountContext.Database.MigrateAsync();

                    await messengerContext.Database.MigrateAsync();

                    transaction = context.Database.BeginTransaction();

                    var countCulture = context.MixCulture.Count();

                    var isInit = countCulture > 0;

                    if (!isInit)
                    {
                        MixService.SetConfig <string>("SiteName", siteName);
                        isSucceed = InitCultures(culture, context, transaction);
                        isSucceed = isSucceed && InitPositions(context, transaction);
                        isSucceed = isSucceed && await InitConfigurationsAsync(siteName, culture, context, transaction);

                        isSucceed = isSucceed && await InitLanguagesAsync(culture, context, transaction);

                        isSucceed = isSucceed && InitThemes(siteName, context, transaction);
                    }
                    else
                    {
                        isSucceed = true;
                    }

                    if (isSucceed && context.MixPage.Count() == 0)
                    {
                        var cate = new MixPage()
                        {
                            Id              = 1,
                            Level           = 0,
                            Title           = "Home",
                            Specificulture  = culture.Specificulture,
                            Template        = "Pages/_Home.cshtml",
                            Type            = (int)MixPageType.Home,
                            CreatedBy       = "Admin",
                            CreatedDateTime = DateTime.UtcNow,
                            Status          = (int)PageStatus.Published
                        };


                        context.Entry(cate).State = EntityState.Added;
                        var alias = new MixUrlAlias()
                        {
                            Id              = 1,
                            SourceId        = "1",
                            Type            = (int)UrlAliasType.Page,
                            Specificulture  = culture.Specificulture,
                            CreatedDateTime = DateTime.UtcNow,
                            Alias           = cate.Title.ToLower()
                        };
                        context.Entry(alias).State = EntityState.Added;

                        var createVNHome = await context.SaveChangesAsync().ConfigureAwait(false);

                        isSucceed = createVNHome > 0;

                        var cate404 = new MixPage()
                        {
                            Id              = 2,
                            Title           = "404",
                            Level           = 0,
                            Specificulture  = culture.Specificulture,
                            Template        = "Pages/_404.cshtml",
                            Type            = (int)MixPageType.Article,
                            CreatedBy       = "Admin",
                            CreatedDateTime = DateTime.UtcNow,
                            Status          = (int)PageStatus.Published
                        };

                        var alias404 = new MixUrlAlias()
                        {
                            Id              = 2,
                            SourceId        = "2",
                            Type            = (int)UrlAliasType.Page,
                            Specificulture  = culture.Specificulture,
                            CreatedDateTime = DateTime.UtcNow,
                            Alias           = cate404.Title.ToLower()
                        };
                        context.Entry(cate404).State  = EntityState.Added;
                        context.Entry(alias404).State = EntityState.Added;

                        var create404 = await context.SaveChangesAsync().ConfigureAwait(false);

                        isSucceed = create404 > 0;
                    }

                    if (isSucceed)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        transaction.Rollback();
                    }
                }
                result.IsSucceed = isSucceed;
                return(result);
            }
            catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only
            {
                transaction?.Rollback();
                accTransaction?.Rollback();
                result.IsSucceed = false;
                result.Exception = ex;
                return(result);
            }
            finally
            {
                context?.Dispose();
                accountContext?.Dispose();
            }
        }