コード例 #1
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            this.Image = SWCmsHelper.GetFullPath(new string[] {
                GlobalConfigurationService.Instance.GetLocalString("Domain", Specificulture),
                Image
            });
            var getChilds = Repository.GetModelListBy
                                (p => p.SiocCategoryCategorySiocCategory.Any(c => c.ParentId == Id &&
                                                                             c.Specificulture == Specificulture)
                                );

            if (getChilds.IsSucceed)
            {
                Childs = getChilds.Data;
            }
            var countArticle = NavCategoryArticleViewModel.Repository.Count(c => c.CategoryId == Id && c.Specificulture == Specificulture
                                                                            , _context: _context, _transaction: _transaction);

            if (countArticle.IsSucceed)
            {
                TotalArticle = countArticle.Data;
            }

            var countProduct = NavCategoryProductViewModel.Repository.Count(c => c.CategoryId == Id && c.Specificulture == Specificulture
                                                                            , _context: _context, _transaction: _transaction);

            if (countProduct.IsSucceed)
            {
                TotalProduct = countProduct.Data;
            }
        }
コード例 #2
0
 public bool SaveFile(FileViewModel file)
 {
     try
     {
         if (!string.IsNullOrEmpty(file.Content))
         {
             string folder = Path.Combine(CurrentDirectory, file.FileFolder);
             if (!Directory.Exists(folder))
             {
                 Directory.CreateDirectory(file.FileFolder);
             }
             string fileName = SWCmsHelper.GetFullPath(new string[] { folder, file.Filename + file.Extension }); //string.Format(file.FileFolder, file.Filename);
             //var logPath = System.IO.Path.GetTempFileName();
             using (var writer = File.CreateText(fileName))
             {
                 writer.WriteLine(file.Content); //or .Write(), if you wish
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
コード例 #3
0
        public override SiocProduct ParseModel(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            if (string.IsNullOrEmpty(Id))
            {
                Id = Guid.NewGuid().ToString(); //Common.Common.GetBase62(8);
                CreatedDateTime = DateTime.UtcNow;
            }
            if (Properties.Count > 0)
            {
                JArray arrProperties = new JArray();
                foreach (var p in Properties.Where(p => !string.IsNullOrEmpty(p.Value) && !string.IsNullOrEmpty(p.Name)).OrderBy(p => p.Priority))
                {
                    arrProperties.Add(JObject.FromObject(p));
                }
                ExtraProperties = arrProperties.ToString(Formatting.None);
            }

            Template = View != null?string.Format(@"{0}/{1}{2}", View.FolderType, View.FileName, View.Extension) : Template;

            if (ThumbnailFileStream != null)
            {
                string folder = SWCmsHelper.GetFullPath(new string[]
                {
                    SWCmsConstants.Parameters.UploadFolder, "Products", DateTime.UtcNow.ToString("dd-MM-yyyy")
                });
                string filename      = SWCmsHelper.GetRandomName(ThumbnailFileStream.Name);
                bool   saveThumbnail = SWCmsHelper.SaveFileBase64(folder, filename, ThumbnailFileStream.Base64);
                if (saveThumbnail)
                {
                    SWCmsHelper.RemoveFile(Thumbnail);
                    Thumbnail = SWCmsHelper.GetFullPath(new string[] { folder, filename });
                }
            }
            if (ImageFileStream != null)
            {
                string folder = SWCmsHelper.GetFullPath(new string[]
                {
                    SWCmsConstants.Parameters.UploadFolder, "Products", DateTime.UtcNow.ToString("dd-MM-yyyy")
                });
                string filename  = SWCmsHelper.GetRandomName(ImageFileStream.Name);
                bool   saveImage = SWCmsHelper.SaveFileBase64(folder, filename, ImageFileStream.Base64);
                if (saveImage)
                {
                    SWCmsHelper.RemoveFile(Image);
                    Image = SWCmsHelper.GetFullPath(new string[] { folder, filename });
                }
            }

            //Tags = ListTag.ToString(Newtonsoft.Json.Formatting.None);
            NormalPrice = SWCmsHelper.ReversePrice(StrNormalPrice);
            DealPrice   = SWCmsHelper.ReversePrice(StrDealPrice);
            ImportPrice = SWCmsHelper.ReversePrice(StrImportPrice);

            GenerateSEO();

            return(base.ParseModel(_context, _transaction));
        }
コード例 #4
0
        public bool DeleteTemplate(string name, string templateFolder)
        {
            string fullPath = SWCmsHelper.GetFullPath(new string[]
            {
                templateFolder,
                name + SWCmsConstants.Parameters.TemplateExtension
            });

            if (File.Exists(fullPath))
            {
                CommonHelper.RemoveFile(fullPath);
            }
            return(true);
        }
コード例 #5
0
 public bool SaveWebFile(FileViewModel file)
 {
     try
     {
         string fullPath = CommonHelper.GetFullPath(new string[] {
             SWCmsConstants.Parameters.WebRootPath,
             file.FileFolder
         });
         if (!string.IsNullOrEmpty(file.Filename))
         {
             if (!Directory.Exists(fullPath))
             {
                 Directory.CreateDirectory(fullPath);
             }
             string fileName = SWCmsHelper.GetFullPath(new string[] { fullPath, file.Filename + file.Extension }); //string.Format(file.FileFolder, file.Filename);
             //var logPath = System.IO.Path.GetTempFileName();
             if (File.Exists(fileName))
             {
                 DeleteFile(fileName);
             }
             if (string.IsNullOrEmpty(file.FileStream))
             {
                 using (var writer = File.CreateText(fileName))
                 {
                     writer.WriteLine(file.Content); //or .Write(), if you wish
                     return(true);
                 }
             }
             else
             {
                 string base64 = file.FileStream.Split(',')[1];
                 byte[] bytes  = Convert.FromBase64String(base64);
                 using (var writer = File.Create(fileName))
                 {
                     writer.Write(bytes, 0, bytes.Length);
                     return(true);
                 }
             }
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
コード例 #6
0
        public IActionResult Templates(string folder)
        {
            folder = folder ?? SWCmsConstants.TemplateFolder.Layouts;
            string templateFoler = SWCmsHelper.GetFullPath(new string[]
            {
                SWCmsConstants.Parameters.TemplatesFolder
                , SWCmsConstants.Default.DefaultTemplateFolder
                , folder
            });

            var templates = TemplateRepository.Instance.GetTemplates(templateFoler);

            ViewBag.folder = folder;
            return(View(templates));
        }
コード例 #7
0
        public IActionResult EditTemplate(string folder, string name)
        {
            string templateFoler = SWCmsHelper.GetFullPath(new string[]
            {
                SWCmsConstants.Parameters.TemplatesFolder
                , SWCmsConstants.Default.DefaultTemplateFolder
                , folder
            });
            var template = TemplateRepository.Instance.GetTemplate(name, templateFoler);

            if (template == null)
            {
                return(RedirectToAction("templates", new { folder }));
            }
            ViewBag.folder = folder;
            return(View(template));
        }
コード例 #8
0
        public IActionResult Index(string folder, IFormFile file)
        {
            if (file?.Length > 0)
            {
                folder = SWCmsHelper.GetFullPath(new string[]
                {
                    SWCmsConstants.Parameters.FileFolder,
                    folder
                });
                string filename = FileRepository.Instance.SaveWebFile(file, folder);
            }
            var files       = FileRepository.Instance.GetTopFiles(folder);
            var directories = FileRepository.Instance.GetTopDirectories(folder);

            ViewData["directories"] = directories;
            ViewBag.folder          = folder;
            return(View(files));
        }
コード例 #9
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            IsClone = true;
            ListSupportedCulture = GlobalLanguageService.ListSupportedCulture;
            this.ListSupportedCulture.ForEach(c => c.IsSupported =
                                                  (Id == 0 && c.Specificulture == Specificulture) ||
                                                  Repository.CheckIsExists(a => a.Id == Id && a.Specificulture == c.Specificulture, _context, _transaction)
                                              );

            if (!string.IsNullOrEmpty(this.Tags))
            {
                ListTag = JArray.Parse(this.Tags);
            }

            this.Templates = this.Templates ?? BETemplateViewModel.Repository.GetModelListBy(
                t => t.Template.Name == ActivedTemplate && t.FolderType == this.TemplateFolderType).Data;
            this.View = Templates.FirstOrDefault(t => !string.IsNullOrEmpty(this.Template) && this.Template.Contains(t.FileName + t.Extension));
            this.View = View ?? Templates.FirstOrDefault();
            if (this.View == null)
            {
                this.View = new BETemplateViewModel(new SiocTemplate()
                {
                    Extension    = SWCmsConstants.Parameters.TemplateExtension,
                    TemplateId   = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0),
                    TemplateName = ActivedTemplate,
                    FolderType   = TemplateFolderType,
                    FileFolder   = this.TemplateFolder,
                    FileName     = SWCmsConstants.Default.DefaultTemplate,
                    ModifiedBy   = ModifiedBy,
                    Content      = "<div></div>"
                });
            }
            this.Template = SWCmsHelper.GetFullPath(new string[]
            {
                this.View?.FileFolder
                , this.View?.FileName
            });

            this.ModuleNavs   = GetModuleNavs(_context, _transaction);
            this.ParentNavs   = GetParentNavs(_context, _transaction);
            this.ChildNavs    = GetChildNavs(_context, _transaction);
            this.PositionNavs = GetPositionNavs(_context, _transaction);
        }
コード例 #10
0
        public async Task <RepositoryResponse <BEMediaViewModel> > UploadAsync([FromForm] string fileFolder, [FromForm] string title, [FromForm] string description)
        {
            var files = Request.Form.Files;

            if (files.Count > 0)
            {
                var fileUpload = files.FirstOrDefault();

                string folderPath = //$"{SWCmsConstants.Parameters.UploadFolder}/{fileFolder}/{DateTime.UtcNow.ToString("MMM-yyyy")}";
                                    SWCmsHelper.GetFullPath(new[] {
                    SWCmsConstants.Parameters.UploadFolder,
                    fileFolder,
                    DateTime.UtcNow.ToString("MMM-yyyy")
                });
                // string.Format("Uploads/{0}", fileFolder);
                //return ImageHelper.ResizeImage(Image.FromStream(fileUpload.OpenReadStream()), System.IO.Path.Combine(_env.WebRootPath, folderPath));
                //var fileName = await Common.UploadFileAsync(filePath, files.FirstOrDefault());
                string fileName =
                    SWCmsHelper.GetFullPath(new[] {
                    "/",
                    await UploadFileAsync(files.FirstOrDefault(), folderPath).ConfigureAwait(false)
                });
                BEMediaViewModel media = new BEMediaViewModel(new SiocMedia()
                {
                    Specificulture  = _lang,
                    FileName        = fileName.Split('.')[0].Substring(fileName.LastIndexOf('/') + 1),
                    FileFolder      = folderPath,
                    Extension       = fileName.Substring(fileName.LastIndexOf('.')),
                    CreatedDateTime = DateTime.UtcNow,
                    FileType        = fileUpload.ContentType.Split('/')[0],
                    FileSize        = fileUpload.Length,
                    Title           = title ?? fileName,
                    Description     = description ?? fileName
                });
                //media.SaveModel();
                return(media.SaveModel());
            }
            else
            {
                return(new RepositoryResponse <BEMediaViewModel>());
            }
        }
コード例 #11
0
        public void UnZipFile(string fileName, string folder)
        {
            string filePath = SWCmsHelper.GetFullPath(new string[] {
                SWCmsConstants.Parameters.WebRootPath,
                folder,
                fileName
            });
            string webFolder = SWCmsHelper.GetFullPath(new string[]
            {
                SWCmsConstants.Parameters.WebRootPath,
                folder
            });

            try
            {
                ZipFile.ExtractToDirectory(filePath, webFolder);
            }
            catch
            {
            }
        }
コード例 #12
0
 public override SiocTemplate ParseModel()
 {
     if (Id == 0)
     {
         CreatedDateTime = DateTime.UtcNow;
     }
     FileFolder = SWCmsHelper.GetFullPath(new string[]
     {
         SWCmsConstants.Parameters.TemplatesFolder
         , TemplateName
         , FolderType
     });
     //if (FileName.IndexOf(Extension)==-1)
     //{
     //    FileName += Extension;
     //}
     Content = Content?.Trim();
     Scripts = Scripts?.Trim();
     Styles  = Styles?.Trim();
     return(base.ParseModel());
 }
コード例 #13
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            this.Image = SWCmsHelper.GetFullPath(new string[] {
                GlobalConfigurationService.Instance.GetLocalString("Domain", Specificulture),
                Image
            });
            this.View = FETemplateViewModel.GetTemplateByPath(Template, Specificulture, _context, _transaction).Data;
            if (View != null)
            {
                switch (Type)
                {
                case CateType.Home:
                    GetSubModules(_context, _transaction);
                    break;

                case CateType.Blank:
                    break;

                case CateType.Article:
                    break;

                case CateType.Modules:
                    GetSubModules(_context, _transaction);
                    break;

                case CateType.List:
                    GetSubArticles(_context, _transaction);
                    break;

                case CateType.ListProduct:
                    GetSubProducts(_context, _transaction);
                    break;

                default:
                    break;
                }
            }
        }
コード例 #14
0
 public string SaveFile(IFormFile file, string fullPath)
 {
     try
     {
         //string fullPath = CommonHelper.GetFullPath(new string[] {
         //    SWCmsConstants.Parameters.WebRootPath,
         //    folder
         //});
         if (file.Length > 0)
         {
             if (!Directory.Exists(fullPath))
             {
                 Directory.CreateDirectory(fullPath);
             }
             string filename = file.FileName;// Guid.NewGuid().ToString("N");
             string filePath = SWCmsHelper.GetFullPath(new string[] { fullPath, filename });
             //var logPath = System.IO.Path.GetTempFileName();
             if (File.Exists(filePath))
             {
                 DeleteFile(filePath);
             }
             using (var stream = new FileStream(filePath, FileMode.Create))
             {
                 file.CopyTo(stream);
             }
             return(filename);
         }
         else
         {
             return(string.Empty);
         }
     }
     catch
     {
         return(string.Empty);
     }
 }
コード例 #15
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            ListSupportedCulture = GlobalLanguageService.ListSupportedCulture;
            StrNormalPrice       = SWCmsHelper.FormatPrice(NormalPrice);
            StrDealPrice         = SWCmsHelper.FormatPrice(DealPrice);
            StrImportPrice       = SWCmsHelper.FormatPrice(ImportPrice);

            //if (!string.IsNullOrEmpty(this.Tags))
            //{
            //    ListTag = JArray.Parse(this.Tags);
            //}
            Properties = new List <ExtraProperty>();
            if (!string.IsNullOrEmpty(ExtraProperties))
            {
                JArray arr = JArray.Parse(ExtraProperties);
                foreach (JObject item in arr)
                {
                    Properties.Add(item.ToObject <ExtraProperty>());
                }
            }
            //Get Templates
            this.Templates = this.Templates ??
                             BETemplateViewModel.Repository.GetModelListBy(
                t => t.Template.Name == ActivedTemplate && t.FolderType == this.TemplateFolderType).Data;
            if (!string.IsNullOrEmpty(Template))
            {
                this.View = Templates.FirstOrDefault(t => Template.Contains(t.FileName));
            }
            this.View = View ?? Templates.FirstOrDefault();

            if (this.View == null)
            {
                this.View = new BETemplateViewModel(new SiocTemplate()
                {
                    Extension    = SWCmsConstants.Parameters.TemplateExtension,
                    TemplateId   = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0),
                    TemplateName = ActivedTemplate,
                    FolderType   = TemplateFolderType,
                    FileFolder   = this.TemplateFolder,
                    FileName     = SWCmsConstants.Default.DefaultTemplate,
                    ModifiedBy   = ModifiedBy,
                    Content      = "<div></div>"
                });
            }
            this.Template = SWCmsHelper.GetFullPath(new string[]
            {
                this.View?.FileFolder
                , this.View?.FileName
            });

            var getCateProduct = CommonRepository.Instance.GetCategoryProductNav(Id, Specificulture, _context, _transaction);

            if (getCateProduct.IsSucceed)
            {
                this.Categories = getCateProduct.Data;
                this.Categories.ForEach(c => {
                    c.IsActived = NavCategoryProductViewModel.Repository.CheckIsExists(n => n.CategoryId == c.CategoryId && n.ProductId == Id, _context, _transaction);
                });
            }

            var getModuleProduct = CommonRepository.Instance.GetModuleProductNav(Id, Specificulture, _context, _transaction);

            if (getModuleProduct.IsSucceed)
            {
                this.Modules = getModuleProduct.Data;
            }

            var getProductModule = CommonRepository.Instance.GetProductModuleNav(Id, Specificulture, _context, _transaction);

            if (getProductModule.IsSucceed)
            {
                this.ModuleNavs = getProductModule.Data;
            }

            var getProductMedia = NavProductMediaViewModel.Repository.GetModelListBy(n => n.ProductId == Id && n.Specificulture == Specificulture, _context, _transaction);

            if (getProductMedia.IsSucceed)
            {
                MediaNavs = getProductMedia.Data.OrderBy(p => p.Priority).ToList();
                MediaNavs.ForEach(n => n.IsActived = true);
            }

            var getRelatedProduct = NavRelatedProductViewModel.Repository.GetModelListBy(n => (n.SourceProductId == Id || n.RelatedProductId == Id) && n.Specificulture == Specificulture, _context, _transaction);

            if (getRelatedProduct.IsSucceed)
            {
                ProductNavs = getRelatedProduct.Data.OrderBy(p => p.Priority).ToList();
                ProductNavs.ForEach(n => n.IsActived = true);
            }

            this.ListSupportedCulture.ForEach(c => c.IsSupported =
                                                  (string.IsNullOrEmpty(Id) && c.Specificulture == Specificulture) ||
                                                  Repository.CheckIsExists(a => a.Id == Id && a.Specificulture == c.Specificulture, _context, _transaction)
                                              );
            this.ActivedModules = new List <BEModuleViewModel>();
            foreach (var module in this.ModuleNavs.Where(m => m.IsActived))
            {
                var getModule = BEModuleViewModel.Repository.GetSingleModel(m => m.Id == module.ModuleId && m.Specificulture == module.Specificulture, _context, _transaction);
                if (getModule.IsSucceed)
                {
                    this.ActivedModules.Add(getModule.Data);
                    this.ActivedModules.ForEach(m => m.LoadData(Id));
                }
            }
        }
コード例 #16
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            IsClone = true;
            ListSupportedCulture = GlobalLanguageService.ListSupportedCulture;
            this.ListSupportedCulture.ForEach(c => c.IsSupported =
                                                  (Id == 0 && c.Specificulture == Specificulture) ||
                                                  Repository.CheckIsExists(a => a.Id == Id && a.Specificulture == c.Specificulture, _context, _transaction)
                                              );
            Columns = new List <ModuleFieldViewModel>();
            JArray arrField = !string.IsNullOrEmpty(Fields) ? JArray.Parse(Fields) : new JArray();

            foreach (var field in arrField)
            {
                ModuleFieldViewModel thisField = new ModuleFieldViewModel()
                {
                    Name      = CommonHelper.ParseJsonPropertyName(field["name"].ToString()),
                    Priority  = field["priority"] != null ? field["priority"].Value <int>() : 0,
                    DataType  = (SWCmsConstants.DataType)(int) field["dataType"],
                    Width     = field["width"] != null ? field["width"].Value <int>() : 3,
                    IsDisplay = field["isDisplay"] != null ? field["isDisplay"].Value <bool>() : true
                };
                Columns.Add(thisField);
            }

            //Get Templates
            this.Templates = this.Templates ?? BETemplateViewModel.Repository.GetModelListBy(
                t => t.Template.Name == ActivedTemplate && t.FolderType == this.TemplateFolderType).Data;
            this.View = Templates.FirstOrDefault(t => !string.IsNullOrEmpty(this.Template) && this.Template.Contains(t.FileName + t.Extension));
            this.View = View ?? Templates.FirstOrDefault();
            if (this.View == null)
            {
                this.View = new BETemplateViewModel(new SiocTemplate()
                {
                    Extension    = SWCmsConstants.Parameters.TemplateExtension,
                    TemplateId   = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0),
                    TemplateName = ActivedTemplate,
                    FolderType   = TemplateFolderType,
                    FileFolder   = this.TemplateFolder,
                    FileName     = SWCmsConstants.Default.DefaultTemplate,
                    ModifiedBy   = ModifiedBy,
                    Content      = "<div></div>"
                });
            }
            this.Template = SWCmsHelper.GetFullPath(new string[]
            {
                this.View?.FileFolder
                , this.View?.FileName
            });

            var getDataResult = InfoModuleDataViewModel.Repository
                                .GetModelListBy(m => m.ModuleId == Id && m.Specificulture == Specificulture
                                                , "Priority", OrderByDirection.Ascending, null, null
                                                , _context, _transaction);

            if (getDataResult.IsSucceed)
            {
                getDataResult.Data.JsonItems = new List <JObject>();
                getDataResult.Data.Items.ForEach(d => getDataResult.Data.JsonItems.Add(d.JItem));
                Data = getDataResult.Data;
            }
            var getArticles = InfoArticleViewModel.GetModelListByModule(Id, Specificulture, SWCmsConstants.Default.OrderBy, OrderByDirection.Ascending
                                                                        , _context: _context, _transaction: _transaction
                                                                        );

            if (getArticles.IsSucceed)
            {
                Articles = getArticles.Data;
            }

            var getProducts = NavModuleProductViewModel.Repository.GetModelListBy(
                m => m.ModuleId == Id && m.Specificulture == Specificulture
                , SWCmsConstants.Default.OrderBy, OrderByDirection.Ascending
                , null, null
                , _context: _context, _transaction: _transaction
                );

            if (getProducts.IsSucceed)
            {
                Products = getProducts.Data;
            }
        }