Пример #1
0
        public List <FileViewModel> GetUploadFiles(string folder)
        {
            string fullPath = SwCmsHelper.GetFullPath(new string[] { SWCmsConstants.Parameters.UploadFolder, folder });

            CreateDirectoryIfNotExist(fullPath);

            DirectoryInfo d = new DirectoryInfo(fullPath); //Assuming Test is your Folder

            FileInfo[]           Files  = d.GetFiles();
            List <FileViewModel> result = new List <FileViewModel>();

            foreach (var file in Files.OrderByDescending(f => f.CreationTimeUtc))
            {
                using (StreamReader s = file.OpenText())
                {
                    result.Add(new FileViewModel()
                    {
                        FileFolder = folder,
                        Filename   = file.Name.Substring(0, file.Name.LastIndexOf('.')),
                        Extension  = file.Extension,
                        Content    = s.ReadToEnd()
                    });
                }
            }
            return(result);
        }
Пример #2
0
        public string SaveFile(IFormFile file, string fullPath)
        {
            try
            {
                if (file.Length > 0)
                {
                    CreateDirectoryIfNotExist(fullPath);

                    string filename = file.FileName;
                    string filePath = SwCmsHelper.GetFullPath(new string[] { fullPath, filename });
                    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);
            }
        }
Пример #3
0
        public async Task <RepositoryResponse <PaginationModel <InfoProductViewModel> > > GetList([FromBody] RequestPaging request)
        {
            string domain = string.Format("{0}://{1}", Request.Scheme, Request.Host);

            Expression <Func <SiocProduct, bool> > predicate = model =>
                                                               model.Specificulture == _lang &&
                                                               (!request.Status.HasValue || model.Status == (int)request.Status.Value) &&
                                                               (string.IsNullOrWhiteSpace(request.Keyword) ||
                                                                (
                                                                    model.Title.Contains(request.Keyword)

                                                                    || model.Excerpt.Contains(request.Keyword) ||
                                                                    model.Code.Contains(request.Keyword)
                                                                )
                                                               ) &&
                                                               (!request.FromDate.HasValue ||
                                                                (model.CreatedDateTime >= request.FromDate.Value.ToUniversalTime())
                                                               ) &&
                                                               (!request.ToDate.HasValue ||
                                                                (model.CreatedDateTime <= request.ToDate.Value.ToUniversalTime())
                                                               );

            var data = await InfoProductViewModel.Repository.GetModelListByAsync(predicate, request.OrderBy, request.Direction, request.PageSize, request.PageIndex).ConfigureAwait(false);

            if (data.IsSucceed)
            {
                data.Data.Items.ForEach(a =>
                {
                    a.DetailsUrl = SwCmsHelper.GetRouterUrl(
                        "Product", new { a.SeoName }, Request, Url);
                });
            }
            return(data);
        }
Пример #4
0
        public FileViewModel GetUploadFile(string name, string ext, string FileFolder)
        {
            FileViewModel result = null;

            string folder   = SwCmsHelper.GetFullPath(new string[] { SWCmsConstants.Parameters.UploadFolder, FileFolder });
            string fullPath = string.Format(@"{0}/{1}.{2}", folder, name, ext);

            FileInfo file = new FileInfo(fullPath);

            try
            {
                using (StreamReader s = file.OpenText())
                {
                    result = new FileViewModel()
                    {
                        FileFolder = FileFolder,
                        Filename   = file.Name.Substring(0, file.Name.LastIndexOf('.')),
                        Extension  = file.Extension.Remove(0, 1),
                        Content    = s.ReadToEnd()
                    };
                }
            }
            catch
            {
                // File invalid
            }
            return(result ?? new FileViewModel()
            {
                FileFolder = FileFolder
            });
        }
Пример #5
0
 public bool SaveTemplate(TemplateViewModel file)
 {
     try
     {
         if (!string.IsNullOrEmpty(file.Filename))
         {
             if (!Directory.Exists(file.FileFolder))
             {
                 Directory.CreateDirectory(file.FileFolder);
             }
             string fileName = SwCmsHelper.GetFullPath(new string[] { file.FileFolder, file.Filename + file.Extension });
             using (var writer = File.CreateText(fileName))
             {
                 writer.WriteLine(file.Content);
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
Пример #6
0
        public async Task <RepositoryResponse <PaginationModel <InfoUserViewModel> > > GetList(RequestPaging request)
        {
            Expression <Func <SiocCmsUser, bool> > predicate = model =>
                                                               (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                               (string.IsNullOrWhiteSpace(request.Keyword) ||
                                                                (
                                                                    model.Username.Contains(request.Keyword) ||
                                                                    model.FirstName.Contains(request.Keyword) ||
                                                                    model.LastName.Contains(request.Keyword)
                                                                )
                                                               ) &&
                                                               (!request.FromDate.HasValue ||
                                                                (model.CreatedDateTime >= request.FromDate.Value.ToUniversalTime())
                                                               ) &&
                                                               (!request.ToDate.HasValue ||
                                                                (model.CreatedDateTime <= request.ToDate.Value.ToUniversalTime())
                                                               );

            var data = await InfoUserViewModel.Repository.GetModelListByAsync(predicate, request.OrderBy, request.Direction, request.PageSize, request.PageIndex).ConfigureAwait(false);

            if (data.IsSucceed)
            {
                data.Data.Items.ForEach(a =>
                {
                    a.DetailsUrl = SwCmsHelper.GetRouterUrl(
                        "Profile", new { a.Id }, Request, Url);
                }
                                        );
            }
            return(data);
        }
Пример #7
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 });
             using (var writer = File.CreateText(fileName))
             {
                 writer.WriteLine(file.Content); //or .Write(), if you wish
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
        public override SiocProduct ParseModel(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            if (string.IsNullOrEmpty(Id))
            {
                Id = Guid.NewGuid().ToString();
                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));
        }
Пример #9
0
        public async Task <JObject> BEDetails(string viewType, string id)
        {
            switch (viewType)
            {
            case "be":
                if (!string.IsNullOrEmpty(id))
                {
                    var beResult = await ApiArticleViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                    if (beResult.IsSucceed)
                    {
                        beResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Article", new { beResult.Data.SeoName }, Request, Url);
                    }
                    return(JObject.FromObject(beResult));
                }
                else
                {
                    var model = new SiocArticle()
                    {
                        Specificulture = _lang,
                        Status         = (int)SWStatus.Preview,
                        Priority       = ApiArticleViewModel.Repository.Max(a => a.Priority).Data + 1
                    };
                    RepositoryResponse <ApiArticleViewModel> result = new RepositoryResponse <ApiArticleViewModel>()
                    {
                        IsSucceed = true,
                        Data      = new ApiArticleViewModel(model)
                    };
                    return(JObject.FromObject(result));
                }

            default:
                if (!string.IsNullOrEmpty(id))
                {
                    var beResult = await ApiArticleViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                    if (beResult.IsSucceed)
                    {
                        beResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Article", new { beResult.Data.SeoName }, Request, Url);
                    }
                    return(JObject.FromObject(beResult));
                }
                else
                {
                    var model = new SiocArticle();
                    RepositoryResponse <ApiArticleViewModel> result = new RepositoryResponse <ApiArticleViewModel>()
                    {
                        IsSucceed = true,
                        Data      = new ApiArticleViewModel(model)
                        {
                            Specificulture = _lang, Status = SWStatus.Preview
                        }
                    };
                    return(JObject.FromObject(result));
                }
            }
        }
Пример #10
0
        public async Task <JObject> BEDetails(string viewType, int?id)
        {
            switch (viewType)
            {
            case "be":
                if (id.HasValue)
                {
                    var beResult = await BECategoryViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                    if (beResult.IsSucceed)
                    {
                        beResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Page", new { beResult.Data.SeoName }, Request, Url);
                    }
                    return(JObject.FromObject(beResult));
                }
                else
                {
                    var model = new SiocCategory()
                    {
                        Specificulture = _lang, Status = (int)SWStatus.Preview
                    };

                    RepositoryResponse <BECategoryViewModel> result = new RepositoryResponse <BECategoryViewModel>()
                    {
                        IsSucceed = true,
                        Data      = await BECategoryViewModel.InitAsync(model)
                    };
                    return(JObject.FromObject(result));
                }

            default:
                if (id.HasValue)
                {
                    var beResult = await FECategoryViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                    if (beResult.IsSucceed)
                    {
                        beResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Page", new { beResult.Data.SeoName }, Request, Url);
                    }
                    return(JObject.FromObject(beResult));
                }
                else
                {
                    var model = new SiocCategory();
                    RepositoryResponse <FECategoryViewModel> result = new RepositoryResponse <FECategoryViewModel>()
                    {
                        IsSucceed = true,
                        Data      = new FECategoryViewModel(model)
                        {
                            Specificulture = _lang, Status = SWStatus.Preview
                        }
                    };
                    return(JObject.FromObject(result));
                }
            }
        }
Пример #11
0
        public async Task <RepositoryResponse <PaginationModel <InfoArticleViewModel> > > Get(int?pageSize = 15, int?pageIndex = 0, string orderBy = "Id", OrderByDirection direction = OrderByDirection.Ascending)
        {
            var data = await InfoArticleViewModel.Repository.GetModelListByAsync(
                m => m.Status != (int)SWStatus.Deleted && m.Specificulture == _lang, orderBy, direction, pageSize, pageIndex).ConfigureAwait(false);

            if (data.IsSucceed)
            {
                data.Data.Items.ForEach(a => a.DetailsUrl = SwCmsHelper.GetRouterUrl("Article", new { a.SeoName }, Request, Url));
            }
            return(data);
        }
Пример #12
0
        public bool DeleteFile(string name, string extension, string FileFolder)
        {
            string folder   = SwCmsHelper.GetFullPath(new string[] { SWCmsConstants.Parameters.UploadFolder, FileFolder });
            string fullPath = string.Format(@"{0}/{1}{2}", folder, name, extension);

            if (File.Exists(fullPath))
            {
                CommonHelper.RemoveFile(fullPath);
            }
            return(true);
        }
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var getAlias = ApiUrlAliasViewModel.Repository.GetSingleModel(
                u => u.Specificulture == Specificulture && u.SourceId == Id.ToString() && u.Type == (int)SWCmsConstants.UrlAliasType.Page);

            UrlAlias = getAlias.Data;
            if (UrlAlias == null)
            {
                UrlAlias = new ApiUrlAliasViewModel()
                {
                    Type           = SWCmsConstants.UrlAliasType.Page,
                    Specificulture = Specificulture,
                    Alias          = SeoName
                };
            }
            Cultures = Cultures ?? CommonRepository.Instance.LoadCultures(Specificulture, _context, _transaction);
            Cultures.ForEach(c => c.IsSupported = _context.SiocCategory.Any(m => m.Id == Id && m.Specificulture == c.Specificulture));
            if (!string.IsNullOrEmpty(this.Tags))
            {
                ListTag = JArray.Parse(this.Tags);
            }

            int themeId = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0);

            View = ApiTemplateViewModel.GetTemplateByPath(themeId, Template, SWCmsConstants.TemplateFolder.Pages, _context, _transaction);

            if (this.View == null)
            {
                this.View = new ApiTemplateViewModel(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);
        }
Пример #14
0
        public async Task <RepositoryResponse <BEArticleViewModel> > Save([FromBody] BEArticleViewModel article)
        {
            if (article != null)
            {
                var result = await article.SaveModelAsync(true).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    result.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Article", new { seoName = article.SeoName }, Request, Url);
                }
                return(result);
            }
            return(new RepositoryResponse <BEArticleViewModel>());
        }
Пример #15
0
 public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     Domain = GlobalConfigurationService.Instance.CmsConfigurations.GetLocalString("Domain", null, "/");
     if (Image != null && (Image.IndexOf("http") == -1 && Image[0] != '/'))
     {
         ImageUrl = SwCmsHelper.GetFullPath(new string[] {
             Domain, Image
         });
     }
     else
     {
         ImageUrl = Image;
     }
 }
Пример #16
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            Cultures = CommonRepository.Instance.LoadCultures(Specificulture, _context, _transaction);
            Cultures.ForEach(c => c.IsSupported = _context.SiocModule.Any(m => m.Id == Id && m.Specificulture == c.Specificulture));
            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()),
                    Title      = field["title"]?.ToString(),
                    Options    = field["options"] != null ? field["options"].Value <JArray>() : new JArray(),
                    Priority   = field["priority"] != null ? field["priority"].Value <int>() : 0,
                    DataType   = (SWCmsConstants.DataType)(int) field["dataType"],
                    Width      = field["width"] != null ? field["width"].Value <int>() : 3,
                    IsUnique   = field["isUnique"] != null ? field["isUnique"].Value <bool>() : true,
                    IsRequired = field["isRequired"] != null ? field["isRequired"].Value <bool>() : true,
                    IsDisplay  = field["isDisplay"] != null ? field["isDisplay"].Value <bool>() : true,
                    IsSelect   = field["isSelect"] != null ? field["isSelect"].Value <bool>() : false,
                    IsGroupBy  = field["isGroupBy"] != null ? field["isGroupBy"].Value <bool>() : false,
                };
                Columns.Add(thisField);
            }
            int themeId = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0);

            View = ApiTemplateViewModel.Repository.GetSingleModel(t =>
                                                                  t.TemplateId == themeId &&
                                                                  !string.IsNullOrEmpty(this.Template) && this.Template.Contains($"{t.FileName}{t.Extension}")).Data;
            if (this.View == null)
            {
                this.View = new ApiTemplateViewModel(new SiocTemplate()
                {
                    Extension    = SWCmsConstants.Parameters.TemplateExtension,
                    TemplateId   = themeId,
                    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
            });
        }
Пример #17
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);
        }
Пример #18
0
 public override Task <bool> ExpandViewAsync(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     Domain = GlobalConfigurationService.Instance.CmsConfigurations.GetLocalString("Domain", Specificulture, "/");
     if (Image != null && (Image.IndexOf("http") == -1 && Image[0] != '/'))
     {
         ImageUrl = SwCmsHelper.GetFullPath(new string[] {
             Domain, Image
         });
     }
     else
     {
         ImageUrl = Image;
     }
     return(base.ExpandViewAsync(_context, _transaction));
 }
        public RepositoryResponse <bool> Delete(RequestObject request)
        {
            string fullPath = SwCmsHelper.GetFullPath(new string[]
            {
                request.Key,
                request.Keyword
            });
            var result = FileRepository.Instance.DeleteWebFile(fullPath);

            return(new RepositoryResponse <bool>()
            {
                IsSucceed = result,
                Data = result
            });
        }
Пример #20
0
        public async Task <RepositoryResponse <ApiArticleViewModel> > Save([FromBody] ApiArticleViewModel Article)
        {
            if (Article != null)
            {
                Article.CreatedBy = User.Identity.Name;
                var result = await Article.SaveModelAsync(true).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    result.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Article", new { seoName = Article.SeoName }, Request, Url);
                }
                return(result);
            }
            return(new RepositoryResponse <ApiArticleViewModel>());
        }
Пример #21
0
        public async Task <RepositoryResponse <BEProductViewModel> > Save([FromBody] BEProductViewModel product)
        {
            if (product != null)
            {
                product.CreatedBy = User.Identity.Name;
                var result = await product.SaveModelAsync(true).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    result.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Product", new { seoName = product.SeoName }, Request, Url);
                }
                return(result);
            }
            return(new RepositoryResponse <BEProductViewModel>());
        }
Пример #22
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")
                });
                // save web files in wwwRoot
                string uploadPath = SwCmsHelper.GetFullPath(new[] {
                    SWCmsConstants.Parameters.WebRootPath,
                    folderPath
                });
                // 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(), uploadPath).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>());
            }
        }
Пример #23
0
        public bool SaveWebFile(FileViewModel file)
        {
            try
            {
                string fullPath = CommonHelper.GetFullPath(new string[] {
                    SWCmsConstants.Parameters.WebRootPath,
                    SWCmsConstants.Parameters.FileFolder,
                    file.FileFolder
                });
                if (!string.IsNullOrEmpty(file.Filename))
                {
                    CreateDirectoryIfNotExist(fullPath);

                    string fileName = SwCmsHelper.GetFullPath(new string[] { fullPath, file.Filename + file.Extension });
                    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);
            }
        }
Пример #24
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            UrlAlias = ApiUrlAliasViewModel.Repository.GetSingleModel(u => u.Specificulture == Specificulture && u.SourceId == Id.ToString()).Data;
            if (UrlAlias == null)
            {
                UrlAlias = new ApiUrlAliasViewModel()
                {
                    Specificulture = Specificulture
                };
            }
            ListSupportedCulture = CommonRepository.Instance.LoadCultures(Specificulture, _context, _transaction);
            ListSupportedCulture.ForEach(c => c.IsSupported = _context.SiocCategory.Any(m => m.Id == Id && m.Specificulture == c.Specificulture));
            if (!string.IsNullOrEmpty(this.Tags))
            {
                ListTag = JArray.Parse(this.Tags);
            }

            this.Templates = this.Templates ?? ApiTemplateViewModel.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 ApiTemplateViewModel(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);
        }
Пример #25
0
 public override SiocTemplate ParseModel(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     if (Id == 0)
     {
         CreatedDateTime = DateTime.UtcNow;
     }
     FileFolder = SwCmsHelper.GetFullPath(new string[]
     {
         SWCmsConstants.Parameters.TemplatesFolder
         , TemplateName
         , FolderType
     });
     Content = Content?.Trim();
     Scripts = Scripts?.Trim();
     Styles  = Styles?.Trim();
     return(base.ParseModel(_context, _transaction));
 }
Пример #26
0
 public IActionResult Home(string pageName, int pageIndex, int pageSize = 10)
 {
     // Home Page
     if (string.IsNullOrEmpty(pageName) || pageName == "Home")
     {
         //CategoryViewModel page = CategoryRepository.GetInstance().GetFEHomeModel(p => p.Type == (int)SWCmsConstants.CateType.Home && p.Specificulture == _lang);
         var getPage = FECategoryViewModel.Repository.GetSingleModel(p => p.Type == (int)SWCmsConstants.CateType.Home && p.Specificulture == CurrentLanguage);
         if (getPage.IsSucceed && getPage.Data.View != null)
         {
             ViewBag.pageClass = getPage.Data.CssClass;
             return(View(getPage.Data));
         }
         else
         {
             return(RedirectToAction("Index", "Portal", new { culture = CurrentLanguage }));
         }
     }
     else
     {
         var getPage = FECategoryViewModel.Repository.GetSingleModel(
             p => p.SeoName == pageName && p.Specificulture == CurrentLanguage);
         if (getPage.IsSucceed && getPage.Data.View != null)
         {
             if (getPage.Data.Type == SWCmsConstants.CateType.List)
             {
                 getPage.Data.Articles.Items.ForEach(a =>
                 {
                     a.Article.DetailsUrl = SwCmsHelper.GetRouterUrl("Article", new { a.Article.SeoName }, Request, Url);
                 });
             }
             if (getPage.Data.Type == SWCmsConstants.CateType.ListProduct)
             {
                 getPage.Data.Products.Items.ForEach(p =>
                 {
                     p.Product.DetailsUrl = SwCmsHelper.GetRouterUrl("Product", new { p.Product.SeoName }, Request, Url);
                 });
             }
             ViewBag.pageClass = getPage.Data.CssClass;
             return(View(getPage.Data));
         }
         else
         {
             return(Redirect(string.Format("/{0}", CurrentLanguage)));
         }
     }
 }
Пример #27
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));
        }
Пример #28
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            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);
        }
Пример #29
0
        public async Task <JObject> Details(string viewType, string id)
        {
            switch (viewType)
            {
            case "be":
                RepositoryResponse <ApiProductViewModel> apiResult = null;
                if (!string.IsNullOrEmpty(id))
                {
                    apiResult = await ApiProductViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                    if (apiResult.IsSucceed)
                    {
                        apiResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Product", new { apiResult.Data.SeoName }, Request, Url);
                    }
                    return(JObject.FromObject(apiResult));
                }
                else
                {
                    var model = new SiocProduct()
                    {
                        Specificulture = _lang,
                        Status         = GlobalConfigurationService.Instance.CmsConfigurations.DefaultStatus
                    };
                    apiResult = new RepositoryResponse <ApiProductViewModel>()
                    {
                        IsSucceed = true,
                        Data      = new ApiProductViewModel(model)
                    };
                    return(JObject.FromObject(apiResult));
                }

            default:

                var result = await FEProductViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    result.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Product", new { result.Data.SeoName }, Request, Url);
                }
                return(JObject.FromObject(result));
            }
        }
Пример #30
0
 public override SiocCmsUser ParseModel(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     if (MediaFile.FileStream != null)
     {
         MediaFile.FileFolder = SwCmsHelper.GetFullPath(new[] {
             SWCmsConstants.Parameters.UploadFolder,
             DateTime.UtcNow.ToString("MMM-yyyy")
         });;
         var isSaved = FileRepository.Instance.SaveWebFile(MediaFile);
         if (isSaved)
         {
             Avatar = MediaFile.FullPath;
         }
         else
         {
             IsValid = false;
         }
     }
     return(base.ParseModel(_context, _transaction));
 }