public static share_Images ConvertImageProductViewModelToImage(ImageProductViewModel viewModel)
 {
     return(new share_Images
     {
         ImageName = viewModel.ImageName,
         ImagePath = viewModel.ImagePath,
         Status = (int)Define.Status.Active,
         CreatedDate = DateTime.Now,
         ModifiedDate = DateTime.Now
     });
 }
        public static ImageProductViewModel ConvertToImageProductViewModel(share_Images image)
        {
            var imageViewModel = new ImageProductViewModel()
            {
                Id        = image.Id,
                ImageName = image.ImageName,
                ImagePath = image.ImagePath,
                IsActive  = image.Status == (int)Define.Status.Active ? true : false
            };

            return(imageViewModel);
        }
Exemple #3
0
        private string SaveAnImages(ImageProductViewModel imageProductViewModels)
        {
            string imageString = imageProductViewModels.Value.Split(";base64,")[1];

            byte[]         array     = Convert.FromBase64String(imageString);
            ImageConverter converter = new ImageConverter();
            Image          image     = (Image)converter.ConvertFrom(array);
            string         NewName   = Guid.NewGuid().ToString() + ".png";
            string         fullPath  = Path.Combine(_webHostEnvironment.WebRootPath, "images", NewName);

            image.Save(fullPath);
            return(NewName);
        }
        public int AddImage(ImageProductViewModel viewModel)
        {
            try
            {
                var image = ImageMapper.ConvertImageProductViewModelToImage(viewModel);
                _imageRepository.Add(image);
                _imageRepository.Save();

                return(image.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #5
0
        protected int UploadImage(IImageService imageService, HttpPostedFileBase file)
        {
            var    fileName = Path.GetFileName(file.FileName);
            string filePath = Define.ImageSavePath + Guid.NewGuid().ToString() + "/";

            if (!Directory.Exists(Server.MapPath(filePath)))
            {
                Directory.CreateDirectory(Server.MapPath(filePath));
            }

            var path = Path.Combine(Server.MapPath(filePath), fileName);

            file.SaveAs(path);

            var imageModel = new ImageProductViewModel
            {
                ImageName = file.FileName,
                ImagePath = Path.Combine(filePath, fileName)
            };

            return(imageService.AddImage(imageModel));
        }