示例#1
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")}"; // 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 = string.Format("/{0}", 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,
                    Description     = description
                });
                //media.SaveModel();
                return(media.SaveModel());
            }
            else
            {
                return(new RepositoryResponse <BEMediaViewModel>());
            }
        }
示例#2
0
        public async Task <JObject> BEDetails(string viewType, int?id = null)
        {
            switch (viewType)
            {
            default:
                if (id.HasValue)
                {
                    var feResult = await BEMediaViewModel.Repository.GetSingleModelAsync(
                        model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                    return(JObject.FromObject(feResult));
                }
                else
                {
                    var media = new SiocMedia()
                    {
                        Specificulture = _lang,
                        Priority       = BEMediaViewModel.Repository.Max(a => a.Priority).Data + 1
                    };
                    var result = new RepositoryResponse <BEMediaViewModel>()
                    {
                        IsSucceed = true,
                        Data      = (await BEMediaViewModel.InitViewAsync(media))
                    };
                    return(JObject.FromObject(result));
                }
            }
        }
示例#3
0
        public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var getMedia = BEMediaViewModel.Repository.GetSingleModel(m => m.Id == MediaId && m.Specificulture == Specificulture
                                                                      , _context: _context, _transaction: _transaction
                                                                      );

            Media = getMedia.Data;
        }
示例#4
0
        public async Task <RepositoryResponse <BEMediaViewModel> > Post(BEMediaViewModel model)
        {
            if (model != null)
            {
                var result = await model.SaveModelAsync(true).ConfigureAwait(false);

                return(result);
            }
            return(new RepositoryResponse <BEMediaViewModel>());
        }
示例#5
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 = SwCmsHelper.GetFullPath(new[] {
                    SWCmsConstants.Parameters.UploadFolder,
                    fileFolder,
                    DateTime.UtcNow.ToString("MM-yyyy")
                });
                // save web files in wwwRoot
                string uploadPath = SwCmsHelper.GetFullPath(new[] {
                    SWCmsConstants.Parameters.WebRootPath,
                    folderPath
                });

                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.Split('.')[0].Substring(fileName.LastIndexOf('/') + 1),
                    Description     = description ?? fileName.Split('.')[0].Substring(fileName.LastIndexOf('/') + 1)
                });
                return(await media.SaveModelAsync());
            }
            else
            {
                return(new RepositoryResponse <BEMediaViewModel>());
            }
        }
示例#6
0
        public async Task <JObject> BEDetails(string viewType, int?id = null)
        {
            switch (viewType)
            {
            default:
                if (id.HasValue)
                {
                    var feResult = await BEMediaViewModel.Repository.GetSingleModelAsync(
                        model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                    return(JObject.FromObject(feResult));
                }
                else
                {
                    var media = new SiocMedia()
                    {
                        Specificulture = _lang
                    };
                    return(JObject.FromObject((await BEMediaViewModel.InitAsync(media))));
                }
            }
        }