示例#1
0
        public async Task <ActionResult <bool> > PostBatch([FromForm] IFormFile file)
        {
            if (file == null || (file.GetExtension() != ".log" && file.GetExtension() != ".txt"))
            {
                return(BadRequest());
            }


            var result = await _logAppService.InsertLogBatchFileAsync(file);

            return(Ok(result));
        }
示例#2
0
 public IActionResult Create(Image Image, IFormFile Img, [FromServices] DataContext db)
 {
     Image.Picture     = Img.ToByteArray();
     Image.Length      = (int)Img.Length;
     Image.Extension   = Img.GetExtension();
     Image.ContentType = Img.ContentType;
     db.Image.Add(Image);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#3
0
 public IActionResult Create(Filmes filmes, IFormFile Img, [FromServices] Gerenciador_de_CinemaContext db)
 {
     filmes.Dados       = Img.ToByteArray();
     filmes.Length      = (int)Img.Length;
     filmes.Extension   = Img.GetExtension();
     filmes.ContentType = Img.ContentType;
     db.Filmes.Add(filmes);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#4
0
        public TransactionResult UpdateCategory(CategoryFormViewModel model, IFormFile headerImage)
        {
            try
            {
                string imgType = string.Empty;
                if (headerImage.Length > 0)
                {
                    imgType        = headerImage.GetExtension();
                    model.ImageUrl = string.Format("{0}{1}", GetUniqueSlugUrlForCategory(model.Name), imgType);
                }

                var category = new Category
                {
                    Id                                 = model.Id,
                    Name                               = model.Name,
                    ParentId                           = model.ParentId,
                    Priority                           = model.Priority,
                    Icon                               = model.Icon != null?model.Icon.Trim() : string.Empty,
                                              SlugUrl  = model.SlugUrl,
                                              ImageUrl = model.ImageUrl,
                                              IsUrun   = model.IsUrun
                };

                _dbContext.Category.Attach(category);
                _dbContext.Entry(category).State = EntityState.Modified;
                _dbContext.SaveChanges();

                if (headerImage.Length > 0)
                {
                    if (!headerImage.VerifyFileSize())
                    {
                        return(new TransactionResult(code: 7001, message: "Dosya boyutu 1mb tan fazla olamaz. Lütfen boyutu daha 1mb altında bir dosya seçiniz.", type: TransactionType.Error));
                    }

                    UploadImage(headerImage, PageContentTypes.Category, category.Id.ToString(), category.ImageUrl);
                }

                ClearCache("PopularCategories");

                return(new TransactionResult()
                {
                    Type = TransactionType.Success
                });
            }
            catch (Exception ex)
            {
                return(new TransactionResult(message: ex.Message, type: TransactionType.Error));
            }
        }
示例#5
0
        public TransactionResult UpdateCampaign(CampaignFormViewModel model, IFormFile headerImage)
        {
            try
            {
                string imgType = string.Empty;
                if (headerImage.Length > 0)
                {
                    imgType   = headerImage.GetExtension();
                    model.Url = string.Format("{0}{1}", GetUniqueSlugUrlForCampaign(model.Title), imgType);
                }

                var campaign = new Campain
                {
                    Id          = model.Id,
                    Title       = model.Title,
                    Description = model.Description,
                    TokenCount  = model.TokenCount,
                    Price       = model.Price,
                    Priority    = model.Priority,
                    IsActive    = bool.Parse(model.IsActive),
                    IsFree      = bool.Parse(model.IsFree),
                    SlugUrl     = GetUniqueSlugUrlForCampaign(model.Title),
                    Url         = model.Url
                };

                _dbContext.Campain.Attach(campaign);
                _dbContext.Entry(campaign).State = EntityState.Modified;
                _dbContext.SaveChanges();

                if (headerImage.Length > 0)
                {
                    if (!headerImage.VerifyFileSize())
                    {
                        return(new TransactionResult(code: 7001, message: "Dosya boyutu 1mb tan fazla olamaz. Lütfen boyutu daha 1mb altında bir dosya seçiniz.", type: TransactionType.Error));
                    }

                    UploadImage(headerImage, PageContentTypes.Campaign, campaign.Id.ToString(), campaign.Url);
                }

                return(new TransactionResult()
                {
                    Type = TransactionType.Success
                });
            }
            catch (Exception ex)
            {
                return(new TransactionResult(message: ex.Message, type: TransactionType.Error));
            }
        }
示例#6
0
        public PictureInfo SaveFile(IFormFile formFile, string fullPath, string uriPath, string addToFilename, bool resize = false, int width = 0, int height = 0)
        {
            var info = new PictureInfo
            {
                Filename  = formFile.GetFileNameSimplify(),
                Extension = formFile.GetExtension()
            };
            var filename = formFile.GetFileName();

            if (!string.IsNullOrEmpty(addToFilename))
            {
                var name = filename.Substring(0, filename.LastIndexOf('.')) + $"-{addToFilename}";
                filename = name + filename.Substring(filename.LastIndexOf('.'));
            }

            //High
            var fileNameHigh = filename.Replace(".", "-high.");
            var fileHighPath = Path.Combine(
                fullPath,
                fileNameHigh);

            using (var stream = new FileStream(fileHighPath, FileMode.Create))
            {
                formFile.CopyTo(stream);
            }

            var filePath = Path.Combine(
                fullPath,
                filename);

            //Medium
            if (resize)
            {
                using (Image image = Image.Load(formFile.OpenReadStream()))
                {
                    image.Mutate(x => x
                                 .Resize(width, height));

                    image.Save(filePath); // Automatic encoder selected based on extension.

                    var options = new ResizeOptions
                    {
                        Mode = ResizeMode.Crop,
                        Size = new Size(width, height)
                    };

                    image.Mutate(x => x.Resize(options));

                    image.Save(filePath, new SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder {
                        Quality = 90
                    });                                                                                       // Automatic encoder selected based on extension.
                }
            }
            else
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    formFile.CopyTo(stream);
                }
            }

            info.Location       = filePath;
            info.PictureUri     = uriPath + filename;
            info.PictureHighUri = uriPath + fileNameHigh;

            return(info);
        }
 public async Task <string> UploadSubtitlePartial(IFormFile subtitlePartial, Guid fansubID, Guid subtitleID, Guid subtitlePartialID)
 {
     return(await Upload(SubtitleBlobContainer, $"fansub/{fansubID}/subtitles/{subtitleID}/{subtitlePartialID}{subtitlePartial.GetExtension()}", subtitlePartial));
 }
 public async Task <string> UploadAvatar(IFormFile avatar, Guid userID)
 {
     return(await Upload(AvatarsBlobContainer, $"users/{userID}/avatar{avatar.GetExtension()}", avatar));
 }