Beispiel #1
0
        public async Task Edit(int id, EditBlogInput input, string imageFolderPath)
        {
            var blog = await Get(id);

            var sources   = input.Content.GetBase64Sources();
            var extension = "";

            byte[] imageBytes = null;
            string imageName  = "";

            foreach (var src in sources)
            {
                extension  = src.GetExtensionFromBase64ImageSource();
                imageBytes = Convert.FromBase64String(src.GetValueFromBase64ImageSource());
                imageName  = $"{Guid.NewGuid()}.{extension}";
                Upload.ByteArrayToFile($"{imageFolderPath}/{imageName}", imageBytes);
                input.Content = input.Content.Replace(src, $"{_configuration.GetSection("Domain").Value}/{Blog.IMAGE_PATH}/{imageName}");
            }

            if (input.Image != null)
            {
                blog.Image = await Upload.UploadImageAsync(input.Image, imageFolderPath);
            }

            blog.Title           = input.Title;
            blog.Description     = input.Description;
            blog.Content         = input.Content;
            blog.SeoUrl          = input.SeoUrl;
            blog.MetaTitle       = input.MetaTitle;
            blog.MetaDescription = input.MetaDescription;

            await _blogService.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task Create(CreateBlogInput input, string imageFolderPath)
        {
            var sources   = input.Content.GetBase64Sources();
            var extension = "";

            byte[] imageBytes = null;
            string imageName  = "";

            foreach (var src in sources)
            {
                extension  = src.GetExtensionFromBase64ImageSource();
                imageBytes = Convert.FromBase64String(src.GetValueFromBase64ImageSource());
                imageName  = $"{Guid.NewGuid()}.{extension}";
                Upload.ByteArrayToFile($"{imageFolderPath}/{imageName}", imageBytes);
                input.Content = input.Content.Replace(src, $"{_configuration.GetSection("Domain").Value}/{ContentPage.IMAGE_PATH}/{imageName}");
            }

            var blog = new Blog(
                title: input.Title,
                image: await Upload.UploadImageAsync(input.Image, imageFolderPath),
                description: input.Description,
                content: input.Content,
                seoUrl: input.SeoUrl,
                metaDescription: input.MetaDescription,
                metaTitle: input.MetaTitle);

            await _blogService.Create(blog);

            await _blogService.SaveChangesAsync();
        }
Beispiel #3
0
        public async Task Edit(int id, EditContentPageInput input, string imageFolderPath)
        {
            var contentPageEntity = await Get(id);

            var sources   = input.Content.GetBase64Sources();
            var extension = "";

            byte[] imageBytes = null;
            string imageName  = "";

            foreach (var src in sources)
            {
                extension  = src.GetExtensionFromBase64ImageSource();
                imageBytes = Convert.FromBase64String(src.GetValueFromBase64ImageSource());
                imageName  = $"{Guid.NewGuid()}.{extension}";
                Upload.ByteArrayToFile($"{imageFolderPath}/{imageName}", imageBytes);
                input.Content = input.Content.Replace(src, $"{_configuration.GetSection("Domain").Value}/{ContentPage.IMAGE_PATH}/{imageName}");
            }

            contentPageEntity.Title           = input.Title;
            contentPageEntity.Content         = input.Content;
            contentPageEntity.SeoUrl          = input.SeoUrl;
            contentPageEntity.MetaTitle       = input.MetaTitle;
            contentPageEntity.MetaDescription = input.MetaDescription;

            await _contentPageRepo.SaveChangesAsync();
        }
Beispiel #4
0
        public async Task Create(CreateProductInput input, string imageFolderPath)
        {
            var sources   = input.Description.GetBase64Sources();
            var extension = "";

            byte[] imageBytes = null;
            string imageName  = "";

            foreach (var src in sources)
            {
                extension  = src.GetExtensionFromBase64ImageSource();
                imageBytes = Convert.FromBase64String(src.GetValueFromBase64ImageSource());
                imageName  = $"{Guid.NewGuid()}.{extension}";
                Upload.ByteArrayToFile($"{imageFolderPath}/{imageName}", imageBytes);
                input.Description = input.Description.Replace(src, $"{_configuration.GetSection("Domain").Value}/{Product.IMAGE_PATH}/{imageName}");
            }

            var product = new Product(name: input.Name,
                                      productCategoryId: 1,
                                      code: "product",
                                      description: input.Description,
                                      price: input.Price,
                                      images: string.Join(";", await Task.WhenAll <string>(input.ImageFiles.Select(img => Upload.UploadImageAsync(img, imageFolderPath)))),
                                      status: input.Status,
                                      seoUrl: input.SeoUrl,
                                      metaDescription: input.MetaDescription,
                                      metaTitle: input.MetaTitle);
            await _productRepo.Create(product);
        }
Beispiel #5
0
        public async Task Edit(int id, EditProductInput input, string imageFolderPath)
        {
            var product = await Get(id);

            if (product == null)
            {
                throw new Exception("product not found");
            }

            var sources   = input.Description.GetBase64Sources();
            var extension = "";

            byte[] imageBytes = null;
            string imageName  = "";

            foreach (var src in sources)
            {
                extension  = src.GetExtensionFromBase64ImageSource();
                imageBytes = Convert.FromBase64String(src.GetValueFromBase64ImageSource());
                imageName  = $"{Guid.NewGuid()}.{extension}";
                Upload.ByteArrayToFile($"{imageFolderPath}/{imageName}", imageBytes);
                input.Description = input.Description.Replace(src, $"{_configuration.GetSection("Domain").Value}/{Product.IMAGE_PATH}/{imageName}");
            }

            var imgs = new List <string>();

            if (input.ImageLinks != null)
            {
                imgs.AddRange(input.ImageLinks.Select(x => x.Replace($"{Product.IMAGE_PATH}/", "")));
            }
            if (input.ImageFiles != null)
            {
                imgs.AddRange(await Task.WhenAll <string>(input.ImageFiles.Select(img => Upload.UploadImageAsync(img, imageFolderPath))));
            }
            product.Images          = string.Join(";", imgs);
            product.Name            = input.Name;
            product.Code            = "product";
            product.Description     = input.Description;
            product.Price           = input.Price;
            product.Status          = input.Status;
            product.SeoUrl          = input.SeoUrl;
            product.MetaDescription = input.MetaDescription;
            product.MetaTitle       = input.MetaTitle;
        }