Ejemplo n.º 1
0
    public Result SaveImage(string tableName, string fieldName, byte[] image, string PK, string PKValue)
    {
        SaveImageRequest  request  = new SaveImageRequest(tableName, fieldName, image, PK, PKValue);
        SaveImageResponse response = this.SaveImage(request);

        return(response.SaveImageResult);
    }
Ejemplo n.º 2
0
    private SaveImageResponse SaveImage(SaveImageRequest request)
    {
        CFInvokeInfo info = new CFInvokeInfo();

        info.Action            = "http://tempuri.org/IServiceBase/SaveImage";
        info.RequestIsWrapped  = true;
        info.ReplyAction       = "http://tempuri.org/IServiceBase/SaveImageResponse";
        info.ResponseIsWrapped = true;
        SaveImageResponse retVal = base.Invoke <SaveImageRequest, SaveImageResponse>(info, request);

        return(retVal);
    }
Ejemplo n.º 3
0
        public async Task <Models.Image> SaveImage(SaveImageRequest request)
        {
            await using var target = new MemoryStream(request.ImageData);
            var data     = target.ToArray();
            var fileName = request.FileName;
            var c        = 0;

            while (true)
            {
                if (!_imageRepository.ImageExists(fileName))
                {
                    break;
                }
                c++;
                var tokens = request.FileName.Split('.');
                fileName = tokens[0] + "(" + c + ")." + tokens[^ 1];
Ejemplo n.º 4
0
        public SaveImageResponse SaveImage(SaveImageRequest request)
        {
            SaveImageResponse response = new SaveImageResponse();

            if (request != null)
            {
                ImageViewModel viewModel = request.ViewModel;
                if (viewModel.ImageContent != null)
                {
                    if (!string.IsNullOrEmpty(viewModel.StorageName) && viewModel.ImageContent.Contains(viewModel.StorageName))
                    {
                        response.ImageViewModel = viewModel;
                        return(response);
                    }
                    if (viewModel.OriginalName == null)
                    {
                        response.ImageViewModel = null;
                        return(response);
                    }
                    Image  Image;
                    string storageName = string.Empty;
                    if (viewModel.ImageID != 0)
                    {
                        storageName = viewModel.StorageName;
                    }
                    else
                    {
                        storageName = Guid.NewGuid().ToString() + viewModel.ImageType;
                    }
                    string imagePath = CreateFolder(request.ImageCategory, request.AccountId.ToString());
                    imagePath = Path.Combine(imagePath, storageName);

                    if (System.IO.File.Exists(imagePath))
                    {
                        System.IO.File.Delete(imagePath);
                    }
                    if (!System.IO.File.Exists(imagePath))
                    {
                        if (viewModel.ImageContent.Split(',').Length == 2)
                        {
                            string imageContent = viewModel.ImageContent.Split(',')[1];
                            byte[] imageData    = Convert.FromBase64String(imageContent);
                            using (MemoryStream ms = new MemoryStream(imageData))
                            {
                                Image = Image.FromStream(ms);
                                Image.Save(imagePath);
                            }
                            viewModel.ImageContent    = null;
                            viewModel.StorageName     = storageName;
                            viewModel.FriendlyName    = viewModel.OriginalName;
                            viewModel.ImageCategoryID = request.ImageCategory;
                            viewModel.AccountID       = Convert.ToInt16(request.AccountId);
                        }
                        else
                        {
                            viewModel = null;
                        }
                    }
                    response.ImageViewModel = viewModel;
                }
            }
            else
            {
                response.ImageViewModel = null;
            }
            return(response);
        }
Ejemplo n.º 5
0
        public ActionResult UploadProductImage(SaveImageRequest request)
        {
            var filePath = FilesUtils.SaveImage(request.File);

            return(Json(new { id = filePath.FileId, url = filePath.Url }));
        }