Exemple #1
0
 public string UploadImage(MemoryStream memoryStream, string imageName, out ImageErrorModel errorModel)
 {
     errorModel = new ImageErrorModel();
     try
     {
         Stream stream       = new MemoryStream(memoryStream.ToArray());
         var    uploadParams = new ImageUploadParams()
         {
             File     = new FileDescription(imageName, stream),
             PublicId = imageName
         };
         var uploadResult = cloudinary.Upload(uploadParams);
         var link         = uploadResult.Uri.AbsoluteUri;
         errorModel.isSuccess = true;
         return(link);
     }
     catch (Exception imgurEx)
     {
         errorModel.exception       = imgurEx;
         errorModel.isSuccess       = false;
         errorModel.message         = "Không thể upload hình thành công";
         errorModel.ImageUploadEnum = Common.Enum.Log.ImageUploadEnum.Local;
         return("false");
     }
 }
        public async Task <IActionResult> EditProduct(ViewModels.PM.Product.EditProductViewModel editProductViewModel)
        {
            string          ImagePath       = null;;
            ImageErrorModel imageErrorModel = new ImageErrorModel();

            if (editProductViewModel.DefaultImage == null)
            {
                ImagePath = editProductViewModel.OldImage;
            }
            else
            {
                ImagePath = UploadImage(editProductViewModel.DefaultImage, ref imageErrorModel);
            }
            if (ModelState.IsValid)
            {
                Product objProduct = await this.ProductBLL.Find(editProductViewModel.ID);

                objProduct.ID             = editProductViewModel.ID;
                objProduct.Specification  = editProductViewModel.Specification;
                objProduct.DefaultImage   = ImagePath;
                objProduct.Price          = editProductViewModel.DefauftPrice;
                objProduct.isOnlineOnly   = editProductViewModel.isOnlineOnly;
                objProduct.StockMin       = editProductViewModel.StockMin;
                objProduct.Details        = editProductViewModel.Details;
                objProduct.IsAllowComment = editProductViewModel.IsAllowComment;
                objProduct.CreatedTime    = editProductViewModel.CreateTime;
                objProduct.BrandID        = editProductViewModel.Brand;
                objProduct.CategoryID     = editProductViewModel.Category;
                objProduct.SubGroupID     = editProductViewModel.SubGroup;
                await ProductBLL.Update(objProduct);

                return(RedirectToAction("Index"));
            }
            return(View(editProductViewModel));
        }
        public override string UploadImage(MemoryStream memoryStream, string imageName, out ImageErrorModel errorModel)
        {
            string imagePath = "";

            Logging.Logging logging = new Logging.Logging();

            errorModel = new ImageErrorModel();
            try
            {
                Image image = null;
                using (image = Image.FromStream(memoryStream))
                {
                    if (image.Width < defaultWidth || image.Height < defaultHeight)
                    {
                        //      image = resize(defaultWidth, defaultHeight, image);
                    }
                    imagePath = defaultLocationImage + "\\" + imageName;
                    image.Save(imagePath);
                    errorModel.isSuccess = true;
                    return("~/" + subRoot + "/" + imageName);
                }
            }
            catch (Exception e)
            {
                errorModel.exception       = e;
                errorModel.isSuccess       = false;
                errorModel.message         = "Không thể upload hình thành công";
                errorModel.ImageUploadEnum = Common.Enum.Log.ImageUploadEnum.Local;
                logging.ErrorLogs(errorModel.ToString());
                return("false");
            }
        }
        public async Task <IActionResult> AddProduct(ViewModels.PM.AddProductViewModel addProductViewModel)
        {
            if (ModelState.IsValid)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          ImagePath       = UploadImage(addProductViewModel.DefaultImage, ref imageErrorModel);
                if (imageErrorModel.isSuccess)
                {
                    Product product = new Product()
                    {
                        //MetaKey=addProductViewModel.MetaKey,
                        MetaTitle       = addProductViewModel.MetaTitle,
                        MetaDescription = addProductViewModel.MetaDescription,
                        Model           = addProductViewModel.Model,
                        //MetaKey=adProductViewModel.MetaTitle,
                        DefaultImage   = ImagePath,
                        Price          = addProductViewModel.DefauftPrice,
                        isOnlineOnly   = addProductViewModel.isOnlineOnly,
                        IsAllowComment = addProductViewModel.IsAllowComment,
                        StockMin       = addProductViewModel.StockMin,
                        //LadingPage = addProductViewModel.LadingPage,
                    };
                    product.BrandID    = addProductViewModel.Brand;
                    product.CategoryID = addProductViewModel.Category;
                    //product.MainGroup = await MainGroupBLL.Find(addProductViewModel.MainGroup);
                    product.SubGroupID = addProductViewModel.SubGroup;
                    await ProductBLL.Add(product);

                    return(RedirectToAction("Index"));
                }
            }
            return(View());
        }
Exemple #5
0
        public async Task <IActionResult> EditCategory(ViewModels.PM.Category.EditCategoryViewModel editcategory)
        {
            string          ImagePath       = null;
            ImageErrorModel imageErrorModel = new ImageErrorModel();

            if (editcategory.DefaultImage == null)
            {
                ImagePath = editcategory.OldImage;
            }
            else
            {
                ImagePath = UploadImage(editcategory.DefaultImage, ref imageErrorModel);
            }
            if (ModelState.IsValid)
            {
                Category objcategory = await this.CategoryBLL.Find(editcategory.ID);

                objcategory.Description  = editcategory.Description;
                objcategory.Name         = editcategory.Name;
                objcategory.DefaultImage = ImagePath;
                await CategoryBLL.Update(objcategory);

                return(RedirectToAction("Index"));
            }
            return(View(editcategory));
        }
        public async Task <IActionResult> EditMainGroup(ViewModels.PM.MainGroup.EditMainGroupViewModel editViewMainGroupModel)
        {
            ImageErrorModel imageErrorModel = new ImageErrorModel();
            string          ImagePath       = null;

            if (editViewMainGroupModel.DefaultImage == null)
            {
                ImagePath = editViewMainGroupModel.OldImage;
            }
            else
            {
                ImagePath = UploadImage(editViewMainGroupModel.DefaultImage, ref imageErrorModel);
            }
            if (ModelState.IsValid)
            {
                MainGroup objmaingroup = await this.MainGroupBLL.Find(editViewMainGroupModel.ID);

                objmaingroup.Description  = editViewMainGroupModel.Description;
                objmaingroup.Name         = editViewMainGroupModel.Name;
                objmaingroup.DefaultImage = ImagePath;
                objmaingroup.TypeSex      = editViewMainGroupModel.TypeSex;
                await MainGroupBLL.Update(objmaingroup);

                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> EditBrand(ViewModels.PM.Brand.EditBrandViewModel editBrand)
        {
            ImageErrorModel imageErrorModel = new ImageErrorModel();
            string          ImagePath       = null;

            if (editBrand.DefaultImage == null)
            {
                ImagePath = editBrand.OldImage;
            }
            else
            {
                ImagePath = UploadImage(editBrand.DefaultImage, ref imageErrorModel);
            }
            if (ModelState.IsValid)
            {
                Brand objbrand = await this.BrandBLL.Find(editBrand.ID);

                objbrand.Description  = editBrand.Description;
                objbrand.Name         = editBrand.Name;
                objbrand.DefaultImage = ImagePath;
                await BrandBLL.Update(objbrand);

                return(RedirectToAction("Index"));
            }
            return(View(editBrand));
        }
Exemple #8
0
        protected string UploadImage(IFormFile file, ref ImageErrorModel imageErrorModel)
        {
            MemoryStream memoryStream = new MemoryStream();

            file.CopyTo(memoryStream);
            string guidImage = DateTime.Now.ToString("yyMMddHHmmssff");
            string ImagePath = this.ImageServices.UploadImage(memoryStream, guidImage, out imageErrorModel);

            return(ImagePath);
        }
Exemple #9
0
        protected List <string> UploadListImage(List <IFormFile> listfile, ref List <ImageErrorModel> imageErrorModels)
        {
            List <string> ListImagePath = new List <string>();

            for (int i = 0; i < listfile.Count; i++)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          ImagePath       = UploadImage(listfile[i], ref imageErrorModel);
                imageErrorModels.Add(imageErrorModel);
                ListImagePath.Add(ImagePath);
            }
            return(ListImagePath);
        }
        //ListUpLoadImage

        public override bool DeleteImage(string ImageName, out ImageErrorModel errorModel)
        {
            errorModel = new ImageErrorModel();
            try
            {
                int    startNameIndex = ImageName.LastIndexOf('/') + 1;
                var    _imageName     = ImageName.Substring(startNameIndex, ImageName.Length - startNameIndex);
                string imagePath      = defaultLocationImage + "\\" + _imageName;
                return(true);
            }
            catch (Exception e)
            {
                errorModel.exception       = e;
                errorModel.message         = "Không thể xóa";
                errorModel.ImageUploadEnum = Common.Enum.Log.ImageUploadEnum.Local;
                return(false);
            }
        }
Exemple #11
0
        public async Task <ActionResult> AddCategory(ViewModels.PM.Category.AddCategoryViewModel addCategoryViewModel)
        {
            if (ModelState.IsValid)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          ImagePath       = UploadImage(addCategoryViewModel.DefaultImage, ref imageErrorModel);                if (imageErrorModel.isSuccess)
                {
                    Category category = new Category()
                    {
                        Name         = addCategoryViewModel.Name,
                        DefaultImage = ImagePath,
                        Description  = addCategoryViewModel.Description
                    };
                    await CategoryBLL.Add(category);

                    return(RedirectToAction("Index"));
                }
            }
            return(View());
        }
Exemple #12
0
        public async Task <IActionResult> AddHomeSlider(ViewModels.PM.HomeSlider.AddHomeSliderModel addHomeSliderModel)
        {
            if (ModelState.IsValid)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          DefaultImage1   = UploadImage(addHomeSliderModel.ImagePath, ref imageErrorModel);
                if (imageErrorModel.isSuccess)
                {
                    HomeSlider homeslider = new HomeSlider()
                    {
                        OrderIndex  = addHomeSliderModel.OrderIndex,
                        ImagePath   = DefaultImage1,
                        Description = addHomeSliderModel.Description
                    };
                    await HomeSliderBLL.Add(homeslider);

                    return(RedirectToAction("Index"));
                }
            }
            return(View());
        }
        public async Task <IActionResult> AddBrand(ViewModels.PM.Brand.AddBrandViewModel addBrandViewModel)
        {
            if (ModelState.IsValid)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          ImagePath       = UploadImage(addBrandViewModel.DefaultImage, ref imageErrorModel);
                if (imageErrorModel.isSuccess)
                {
                    Brand brand = new Brand()
                    {
                        Name         = addBrandViewModel.Name,
                        DefaultImage = ImagePath,
                        Description  = addBrandViewModel.Description
                    };
                    await BrandBLL.Add(brand);

                    return(RedirectToAction("Index"));
                }
            }
            return(View());
        }
Exemple #14
0
        public async Task <IActionResult> EditHomeSlider(ViewModels.PM.HomeSlider.EditHomeSliderModel editHomeSliderModel)
        {
            if (ModelState.IsValid)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          defaultImage1   = UploadImage(editHomeSliderModel.ImagePath, ref imageErrorModel);
                if (imageErrorModel.isSuccess)
                {
                    HomeSlider objSlider = await this.HomeSliderBLL.Find(editHomeSliderModel.ID);

                    objSlider.Description = editHomeSliderModel.Description;
                    objSlider.OrderIndex  = editHomeSliderModel.OrderIndex;
                    objSlider.ImagePath   = defaultImage1;
                    await HomeSliderBLL.Update(objSlider);

                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }
        public async Task <IActionResult> EditStore(ViewModels.PM.Store.EditViewStoreModel editViewStoreModel)
        {
            if (ModelState.IsValid)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          ImagePath       = UploadImage(editViewStoreModel.DefaultImage, ref imageErrorModel);
                if (imageErrorModel.isSuccess)
                {
                    Store objStore = await this.StoreBLL.Find(editViewStoreModel.ID);

                    objStore.Address      = editViewStoreModel.Address;
                    objStore.Description  = editViewStoreModel.Description;
                    objStore.NameStore    = editViewStoreModel.NameStore;
                    objStore.DefaultImage = ImagePath;
                    await StoreBLL.Update(objStore);

                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }
        public string UploadImage(MemoryStream memoryStream, string imageName, out ImageErrorModel errorModel)
        {
            errorModel = new ImageErrorModel();
            try
            {
                var    client   = new ImgurClient(CLientId, ClientSecret);
                var    endpoint = new ImageEndpoint(client);
                IImage image;

                image = endpoint.UploadImageStreamAsync(memoryStream).GetAwaiter().GetResult();
                errorModel.isSuccess = true;
                return(image.Link);
            }
            catch (ImgurException imgurEx)
            {
                errorModel.exception       = imgurEx;
                errorModel.isSuccess       = false;
                errorModel.message         = "Không thể upload hình thành công";
                errorModel.ImageUploadEnum = Common.Enum.Log.ImageUploadEnum.Local;
                return("false");
            }
        }
        public async Task <IActionResult> AddMainGroup(AddMainGroupViewModel addMainGroupViewModel)
        {
            if (ModelState.IsValid)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          ImagePath       = UploadImage(addMainGroupViewModel.DefaultImage, ref imageErrorModel);
                if (imageErrorModel.isSuccess)
                {
                    MainGroup mainGroup = new MainGroup()
                    {
                        Name         = addMainGroupViewModel.Name,
                        DefaultImage = ImagePath,
                        Description  = addMainGroupViewModel.Description,
                        TypeSex      = addMainGroupViewModel.TypeSex,
                    };
                    await MainGroupBLL.Add(mainGroup);

                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }
        public async Task <IActionResult> AddStore(ViewModels.PM.Store.AddViewStoreModel addViewStoreModel)
        {
            if (ModelState.IsValid)
            {
                ImageErrorModel imageErrorModel = new ImageErrorModel();
                string          ImagePath       = UploadImage(addViewStoreModel.DefaultImage, ref imageErrorModel);
                if (imageErrorModel.isSuccess)
                {
                    Store store = new Store()
                    {
                        Address      = addViewStoreModel.Address,
                        NameStore    = addViewStoreModel.NameStore,
                        DefaultImage = ImagePath,
                        Description  = addViewStoreModel.Description,
                        DistrictID   = addViewStoreModel.DicstrictID
                    };
                    await StoreBLL.Add(store);

                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }
Exemple #19
0
 public abstract bool DeleteImage(string ImageName, out ImageErrorModel errorModel);
Exemple #20
0
 public abstract string UploadImage(MemoryStream bytes, string imageName, out ImageErrorModel errorModel);
Exemple #21
0
 private string UploadImage(string imagePath, ref ImageErrorModel imageErrorModel)
 {
     throw new NotImplementedException();
 }