private async Task SaveMainImage(ImageUploadDTO MainImage, int ProductId) { var pathAbsolute = @"C:\Domains\DaNBVQ\wwwroot\"; var urlProduct = _repoWrapper.Product.CreateImageURL(ProductId); MainImage.FileName = String.Format("{0}-00.{1}", urlProduct, MainImage.ExtensionType.Replace("image/", "")); MainImage.PathSave = "product/mainimages/original"; var PatchToSave = Path.Combine(pathAbsolute, MainImage.PathSave); var physicalPath = Path.Combine(PatchToSave, MainImage.FileName); await UploadImage(MainImage); //Utils.Util.WaterMark(physicalPath, MainImage.FileName); //Make Thumb & small try { var PatchSmall = "product/mainimages/small"; var PatchThumb = "product/mainimages/thumb"; Utils.Util.EditSize(physicalPath, Path.Combine(pathAbsolute, PatchSmall, MainImage.FileName), 500, 500); Utils.Util.EditSize(physicalPath, Path.Combine(pathAbsolute, PatchThumb, MainImage.FileName), 200, 200); } catch (Exception ex) { } ///Update Image Name _repoWrapper.Product.UpdateMainImageProduct(MainImage.FileName, ProductId); }
public async Task <IActionResult> EditAccessories([FromBody] PostProductShopManDTO model) { model.Product.ProductTypeId = 6; //MainImage if (model.MainImage != null) { String[] substrings = model.MainImage.Base64.Split(','); model.MainImage.Base64 = substrings[1]; } for (int i = 0; i < model.SubImageUpload.Length; i++) { if (model.SubImageUpload.Length > 0) { ImageUploadDTO obj = new ImageUploadDTO(); String[] substrings = model.SubImageUpload[i].Split(','); string header = substrings[0]; string step1 = header.Replace("data:", ""); string step2 = step1.Replace(";base64", ""); string imgData = substrings[1]; obj.Base64 = imgData; obj.FileName = model.SubImageFileName[i]; obj.ExtensionType = step2; model.SubImage.Add(obj); } } var result = await _repoWrapper.Product.UpdateProduct(model, (int)model.Product.ProductId, 1); return(Json(result)); }
public int UpdateImgProductBrand(ProductBrand model, ImageUploadDTO imgLogo, ImageUploadDTO imgBanner, int ProductBrandId, string UserId) { var pUserId = Guid.Parse(UserId); if (model != null) { var prodBrandSave = HanomaContext.ProductBrand.Find(ProductBrandId); if (prodBrandSave != null) { try { if (imgLogo.Base64 != null) { prodBrandSave.Logo = String.Format("{0}-mobile-logo.{1}", ProductBrandId, imgLogo.ExtensionType.Replace("image/", "")); } if (imgBanner.Base64 != null) { prodBrandSave.Banner = String.Format("{0}-mobile-banner.{1}", ProductBrandId, imgBanner.ExtensionType.Replace("image/", "")); } HanomaContext.SaveChanges(); return(model.ProductBrand_ID); } catch (Exception ex) { return(0); } } } return(ProductBrandId); }
private async Task UploadImage(ImageUploadDTO model) { try { var pathAbsolute = @"C:\Domains\DaNBVQ\wwwroot\data\"; var imageDataByteArray = Convert.FromBase64String(model.Base64); var imageDataStream = new MemoryStream(imageDataByteArray); imageDataStream.Position = 0; var file = File(imageDataByteArray, model.ExtensionType); var fileName = model.FileName; var pathToSave = Path.Combine(pathAbsolute, model.PathSave); var outPath = Path.Combine(pathToSave, fileName); if (file.FileContents.Length > 0) { using (MemoryStream ms = new MemoryStream(imageDataByteArray)) { using (Bitmap bm2 = new Bitmap(ms)) { bm2.Save(Path.Combine(pathToSave, fileName)); } } } else { } } catch (Exception ex) { } }
private async Task <bool> UploadChatFileS3(ImageUploadDTO model, string pathMain) { try { var imageDataByteArray = Convert.FromBase64String(model.Base64); var imageDataStream = new MemoryStream(imageDataByteArray); imageDataStream.Position = 0; var file = File(imageDataByteArray, model.ExtensionType); var fileName = model.FileName; if (file.FileContents.Length > 0) { Util.UploadS3(model.FileName, pathMain, imageDataStream, model.ExtensionType); return(true); } else { return(false); } } catch (Exception ex) { _logger.LogError($"Upload Product Image: " + ex.ToString()); return(false); } }
public async Task <IActionResult> CreateCV([FromBody] SumPostCurriculumnViateDTO model) { //MainImage if (model.MainImage != null) { String[] substrings = model.MainImage.Base64.Split(','); model.MainImage.Base64 = substrings[1]; } //Subimage for (int i = 0; i < model.SubImageUpload.Length; i++) { if (model.SubImageUpload.Length > 0) { ImageUploadDTO obj = new ImageUploadDTO(); String[] substrings = model.SubImageUpload[i].Split(','); string header = substrings[0]; string step1 = header.Replace("data:", ""); string step2 = step1.Replace(";base64", ""); string imgData = substrings[1]; obj.Base64 = imgData; obj.FileName = model.SubImageFileName[i]; obj.ExtensionType = step2; model.SubImage.Add(obj); } } var result = await _repoWrapper.Product.CreateCV(model); return(Json(result.Message)); }
public async Task <IActionResult> CreateDemand([FromBody] PostProductShopManDTO model) { if (model.typeForm == 2) { model.Product.ProductTypeId = 2; } if (model.typeForm == 4) { model.Product.ProductTypeId = 4; } if (model.typeForm == 6) { model.Product.ProductTypeId = 6; } if (model.typeForm == 8) { model.Product.ProductTypeId = 8; } if (model.typeForm == 12) { model.Product.ProductTypeId = 12; } //MainImage if (model.MainImage != null) { String[] substrings = model.MainImage.Base64.Split(','); model.MainImage.Base64 = substrings[1]; } //Subimage for (int i = 0; i < model.SubImageUpload.Length; i++) { if (model.SubImageUpload.Length > 0) { ImageUploadDTO obj = new ImageUploadDTO(); String[] substrings = model.SubImageUpload[i].Split(','); string header = substrings[0]; string step1 = header.Replace("data:", ""); string step2 = step1.Replace(";base64", ""); string imgData = substrings[1]; obj.Base64 = imgData; obj.FileName = model.SubImageFileName[i]; obj.ExtensionType = step2; model.SubImage.Add(obj); } } var result = await _repoWrapper.Product.CreateProduct(model); return(Json(result.Message)); }
private async Task SaveLogoImage(ImageUploadDTO MainImage, int libraryId) { var timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); MainImage.FileName = String.Format("{0}-00-{1}.{2}", libraryId, timestamp, MainImage.ExtensionType.Replace("image/", "")); MainImage.PathSave = "Library/mainimages/original"; await UploadImage(MainImage, MainImage.PathSave, "Library/mainimages/thumb"); await _repoWrapper.Library.UpdateImgLogoLibrary(MainImage.FileName, libraryId); }
private async Task SaveBannerImage(ImageUploadDTO MainImage, int ProductBrandId) { var timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); var productBrand = _repoWrapper.Brand.FirstOrDefault(x => x.ProductBrand_ID == ProductBrandId); MainImage.FileName = String.Format("{0}-mobile-banner-{1}.{2}", ProductBrandId, timestamp, MainImage.ExtensionType.Replace("image/", "")); MainImage.PathSave = "productbrand/banner/original"; await UploadImage(MainImage); await _repoWrapper.Brand.UpdateImgBannerProductBrand(MainImage.FileName, ProductBrandId); }
public Object uploadImage([FromBody] ImageUploadDTO imageUploadDTO) { // 删除非法base64字符 string converted = imageUploadDTO.base64.Replace(@"data:image/png;base64,", ""); converted = converted.Replace("data:image/jpeg;base64,", ""); MemoryStream ms = new MemoryStream(System.Convert.FromBase64String(converted)); var key = System.Guid.NewGuid().ToString() + ".png"; var uploadResult = OSSService.uploadFile(key, ms); return(new { url = OSSService.url + "/" + key, ok = uploadResult.HttpStatusCode == System.Net.HttpStatusCode.OK }); }
public IActionResult Add([FromBody] ImageUploadDTO imageUploadDto) { try { _productImageManager.Add(imageUploadDto); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void Add(ImageUploadDTO imageUploadDto) { var imageId = _imageRepository.Add(new Image { ImageBase64 = imageUploadDto.Image }); _productImageRepository.Add(new ProductImage { ProductId = imageUploadDto.ProductId, ImageId = imageId }); }
private async Task <List <string> > UploadImages(List <IFormFile> images) { var staffId = _claimPrincipalManager.Id; var uploadResult = new ImageUploadResult(); var result = new List <string>(); if (images.Count > 0) { foreach (var file in images) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams { File = new FileDescription(file.FileName, stream) }; uploadResult = _cloudinary.Upload(uploadParams); if (uploadResult.StatusCode == HttpStatusCode.OK) { var photoDto = new ImageUploadDTO { StaffId = staffId, ImageUrl = uploadResult.Uri.ToString(), ImageId = uploadResult.PublicId }; using (var client = _restClient.CreateClient(User)) { using ( var response = await client.PostAsync("/api/GeneralImage", new StringContent(JsonConvert.SerializeObject(photoDto), Encoding.UTF8, "application/json"))) { if (response.StatusCode == HttpStatusCode.Created) { dynamic imageId = JObject.Parse(response.Content.ReadAsStringAsync().Result); result.Add(imageId.imageId.ToString()); } } } } } } } return(result); }
public async Task <IActionResult> EditProduct(ProductShopManDTO ProductShopManDTO, IEnumerable <IFormFile> MainImage, string[] MainImageUpload, string[] MainImageFileName, string[] SubImageUpload, string[] SubImageFileName) { PostProductShopManDTO model = new PostProductShopManDTO(); //logo foreach (var file in MainImage) { if (file.Length > 0) { using (var ms = new System.IO.MemoryStream()) { file.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); model.MainImage.Base64 = s; model.MainImage.FileName = file.FileName; model.MainImage.ExtensionType = file.ContentType; } } } //SubImage for (int i = 0; i < SubImageUpload.Length; i++) { if (SubImageUpload.Length > 0) { ImageUploadDTO obj = new ImageUploadDTO(); String[] substrings = SubImageUpload[i].Split(','); string header = substrings[0]; string step1 = header.Replace("data:", ""); string step2 = step1.Replace(";base64", ""); string imgData = substrings[1]; obj.Base64 = imgData; obj.FileName = SubImageFileName[i]; obj.ExtensionType = step2; model.SubImage.Add(obj); } } model.Product = ProductShopManDTO; var result = await _repoWrapper.Product.UpdateProduct(model, (int)ProductShopManDTO.ProductId, 1); return(Redirect("/Shopman/Product")); }
/// <summary> /// Updates picture of student. /// </summary> /// <param name="imageUploadDTO"></param> /// <returns></returns> public async Task UpdateImageAsync(ImageUploadDTO imageUploadDTO) { var student = await _studentRepository.GetByIdAsync(imageUploadDTO.UserId); student.ThrowIfNullForGuidObject(); var formFile = imageUploadDTO.Image; formFile.ValidateFile(FileType.Image); var dto = new StudentDTO { Id = student.Id, Image = formFile }; student.ImagePath = await formFile.SaveImageToServerAsync <StudentDTO, Guid>(dto); await _studentRepository.UpdateAsync(student); }
public async Task <IActionResult> PostGeneralImage([FromBody] ImageUploadDTO model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var image = new GeneralImage { StaffId = model.StaffId, ImageUrl = model.ImageUrl, GeneralImageId = model.ImageId, AddDate = model.AddDate }; _context.GeneralImage.Add(image); return(await _context.SaveChangesAsync() > 0 ? StatusCode(201, new { imageId = image.GeneralImageId }) : StatusCode(424, new { imageId = string.Empty })); }
/// <summary> /// Saves the image, and returns the path for the image. /// If return value is null, something went wrong. /// </summary> /// <param name="s"></param> /// <param name="type"></param> /// <returns></returns> public string SaveImageToFolder(ImageUploadDTO imageviewmodel) { if (ValidateExtension(Path.GetExtension(imageviewmodel.FileName))) { string imagename = GenerateImageName(imageviewmodel.FileName); string imagePathTemp = GetFolder(imageviewmodel.ImageType); var imagePathFinal = Path.Combine(imagePathTemp, imagename); using (FileStream fs = File.Create(imagePathFinal)) { for (byte i = 0; i < imageviewmodel.Content.Length; i++) { fs.WriteByte(i); } } return(imagePathFinal); } return(null); }
public async Task <IActionResult> NeedBuyAccessories([FromBody] PostProductShopManDTO model) { model.Product.ProductTypeId = 6; //MainImage String[] substrings = model.MainImage.Base64.Split(','); model.MainImage.Base64 = substrings[1]; for (int i = 0; i < model.SubImage.Count; i++) { if (model.SubImage.Count > 0) { ImageUploadDTO obj = new ImageUploadDTO(); String[] substrings2 = model.SubImage[i].Base64.Split(','); model.SubImage[i].Base64 = substrings2[1]; } } var result = await _repoWrapper.Product.CreateProduct(model); return(Json(result)); }
public bool AddImageSaleListing(SaleListingDTO viewmodel, ImageUploadDTO img) { try { if (_imageService.ValidateExtension(img.FileName)) { string imgurl = _imageService.SaveImageToFolder(img); Image image = new Image { ImageURL = imgurl, Type = img.ImageType }; SaleListing salelisting = _saleListingRepository.GetSaleListing(viewmodel.ID); salelisting.Images.Add(image); _saleListingRepository.UpdateSaleListing(salelisting); //_log.LogSaleListing(salelisting.Owner.ID, salelisting.ID, eLogSaleListingType.Update); return(true); } return(false); } catch (Exception ex) { return(false); } }
private async Task <bool> UploadImage(ImageUploadDTO model, string pathMain, string pathThumb) { try { var imageDataByteArray = Convert.FromBase64String(model.Base64); var imageDataStream = new MemoryStream(imageDataByteArray); imageDataStream.Position = 0; var file = File(imageDataByteArray, model.ExtensionType); var fileName = model.FileName; //Image var inputStreamEnd = imageDataStream; //Image Thumb var inputStreamThumb = Util.ResizeImageStream(inputStreamEnd, 120, 120); if (file.FileContents.Length > 0) { await Util.UploadS3(model.FileName, pathMain, inputStreamEnd, model.ExtensionType); await Util.UploadS3(model.FileName, pathThumb, inputStreamThumb, file.ContentType); return(true); } else { return(false); } } catch (Exception ex) { _logger.LogError($"UploadImage: " + ex.ToString()); return(false); } }
/// <summary> /// Upload ảnh ủy nhiệm chi /// </summary> /// <param name="ImageUploadDTO"></param> /// <returns></returns> public async Task <ModelBase> PaymentUploadImage(ImageUploadDTO ImageUploadDTO, string OrderCode) { ModelBase output = new ModelBase(); var jwt = _httpContextAccessor.HttpContext.User.FindFirst(p => p.Type == "access_token").Value; if (jwt != null) { _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt); string apiUrl = $"/api/v1/Payment/PaymentUploadImage"; string paramRequest = $"?OrderCode={OrderCode}"; var json = JsonConvert.SerializeObject(ImageUploadDTO, Formatting.Indented); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PostAsync(apiUrl + paramRequest, stringContent); if (response.IsSuccessStatusCode) { string responseStream = await response.Content.ReadAsStringAsync(); output = JsonConvert.DeserializeObject <ModelBase>(responseStream); } } return(output); }
public async Task <int> PostLibrary(Library model, ImageUploadDTO imgLogo, string UserId) { var pUserId = Guid.Parse(UserId); if (model != null) { var libSave = HanomaContext.Library.Find(model.Library_ID); if (libSave == null) { var libraryNew = new Library { LibraryCategory_ID = model.LibraryCategory_ID, LibraryType_ID = model.LibraryType_ID, Title = model.Title, SubTitle = model.SubTitle, Image = model.Image, Description = model.Description, Content = model.Content, Author = model.Author, CreateDate = DateTime.Now, Counter = model.Counter, Active = true, URL = null, CreateBy = new Guid(UserId), LastEditBy = new Guid(UserId), LastEditDate = model.LastEditDate, Tag = model.Tag, Keyword = model.Keyword, AllowComment = model.AllowComment, MetaTitle = model.MetaTitle, MetaDescription = model.MetaDescription, AuthorPhone = model.AuthorPhone, MetaKeywords = model.MetaKeywords, AuthorEmail = model.AuthorEmail, AuthorJob = model.AuthorJob, AuthorCompany = model.AuthorCompany, ProductCategoryID = model.ProductCategoryID, ManufactoryID = model.ManufactoryID, ModelID = model.ModelID, StatusType_ID = 2, }; try { HanomaContext.Library.Add(libraryNew); await HanomaContext.SaveChangesAsync(); UpdateUrl(libraryNew.Library_ID); return(libraryNew.Library_ID); } catch (Exception ex) { libraryNew.Library_ID = 0; return(libraryNew.Library_ID); } } else { try { var urlNew = FormatURL(model.Title) + "-" + model.Library_ID.ToString(); libSave.LibraryCategory_ID = model.LibraryCategory_ID; libSave.LibraryType_ID = model.LibraryType_ID; libSave.Title = model.Title; libSave.SubTitle = model.SubTitle; libSave.Image = model.Image; libSave.Description = model.Description; libSave.Content = model.Content; libSave.Author = model.Author; libSave.CreateDate = DateTime.Now; libSave.Counter = model.Counter; libSave.Active = true; libSave.URL = null; libSave.CreateBy = new Guid(UserId); libSave.LastEditBy = new Guid(UserId); libSave.LastEditDate = model.LastEditDate; libSave.Tag = model.Tag; libSave.Keyword = model.Keyword; libSave.AllowComment = model.AllowComment; libSave.MetaTitle = model.MetaTitle; libSave.MetaDescription = model.MetaDescription; libSave.AuthorPhone = model.AuthorPhone; libSave.MetaKeywords = model.MetaKeywords; libSave.AuthorEmail = model.AuthorEmail; libSave.AuthorJob = model.AuthorJob; libSave.AuthorCompany = model.AuthorCompany; libSave.ProductCategoryID = model.ProductCategoryID; libSave.ManufactoryID = model.ManufactoryID; libSave.ModelID = model.ModelID; libSave.StatusType_ID = -1; await HanomaContext.SaveChangesAsync(); return(model.Library_ID); } catch (Exception ex) { return(0); } } } return(model.Library_ID); }
public async Task <IActionResult> PaymentUploadImage(ImageUploadDTO ImageUploadDTO, string OrderCode) { var data = await _repoWrapper.UpdateStore.PaymentUploadImage(ImageUploadDTO, OrderCode); return(Json(data)); }
public async Task <int> PostProductBrand(ProductBrand model, ImageUploadDTO imgLogo, ImageUploadDTO imgBanner, string UserId) { var pUserId = Guid.Parse(UserId); if (model != null) { var prodBrandSave = HanomaContext.ProductBrand.Find(model.ProductBrand_ID); if (prodBrandSave == null) { var productBrandNew = new ProductBrand { Location_ID = model.Location_ID, Name = model.Name, TradingName = model.TradingName, BrandName = model.BrandName, BusinessArea = model.BusinessArea, Address = model.Address, Telephone = model.Telephone, Mobile = model.Mobile, Website = model.Website, Description = model.Description, Email = model.Email, LastEditDate = DateTime.Now, CreateDate = DateTime.Now, Verified = true, Active = true, URL = null, CreateBy = new Guid(UserId), LastEditBy = new Guid(UserId), District = model.District, PostalCode = model.PostalCode, Country_ID = model.Country_ID, EmailDisplay = model.EmailDisplay, MapCode = model.MapCode, ReferralCode = model.ReferralCode, ProductBrandType_ID = 1 // Gian hàng quy mô nhỏ }; try { HanomaContext.ProductBrand.Add(productBrandNew); await HanomaContext.SaveChangesAsync(); UpdateUrlProductBrand(productBrandNew.ProductBrand_ID); UpdateProductBrandIdOfProduct(UserId, productBrandNew.ProductBrand_ID); UpgradeAccountAfterRegister(UserId); UpdateUserProfiler(UserId, productBrandNew.ProductBrand_ID); return(productBrandNew.ProductBrand_ID); } catch (Exception ex) { productBrandNew.ProductBrand_ID = 0; return(productBrandNew.ProductBrand_ID); } } else { try { var urlNew = FormatURL(model.Name) + "-" + model.ProductBrand_ID.ToString(); prodBrandSave.Location_ID = model.Location_ID; prodBrandSave.Name = model.Name; prodBrandSave.TradingName = model.TradingName; prodBrandSave.BrandName = model.BrandName; prodBrandSave.BusinessArea = model.BusinessArea; prodBrandSave.Address = model.Address; prodBrandSave.Telephone = model.Telephone; prodBrandSave.Mobile = model.Mobile; prodBrandSave.Website = model.Website; prodBrandSave.Description = model.Description; prodBrandSave.Email = model.Email; prodBrandSave.LastEditDate = DateTime.Now; prodBrandSave.Verified = true; prodBrandSave.Active = true; prodBrandSave.URL = urlNew; prodBrandSave.LastEditBy = pUserId; prodBrandSave.District = model.District; prodBrandSave.PostalCode = model.PostalCode; prodBrandSave.Country_ID = model.Country_ID; prodBrandSave.EmailDisplay = model.EmailDisplay; prodBrandSave.MapCode = model.MapCode; prodBrandSave.ReferralCode = model.ReferralCode; await HanomaContext.SaveChangesAsync(); UpdateUserProfiler(UserId, model.ProductBrand_ID); return(model.ProductBrand_ID); } catch (Exception ex) { return(0); } } } return(model.ProductBrand_ID); }
public async Task <IActionResult> AnalyzeText([FromBody] ImageUploadDTO data) { await _assetService.AnalyzeText(data.base64image); return(Ok()); }
public async Task <IActionResult> Upload([FromBody] ImageUploadDTO data) { var imageResult = await _assetService.AnalyzeImage(data.base64image); return(Ok(imageResult)); }
public async Task <IActionResult> CreateProduct([FromBody] PostProductShopManDTO model) { var productbrand = await _repoWrapper.Profile.GetBrandDetailByUserId(); var checkResult = await _repoWrapper.Product.CheckPostProduct(productbrand.ProductBrandId); if (checkResult.ErrorCode == "00" || checkResult.ErrorCode == "0") { if (model.typeForm == 1) { model.Product.ProductTypeId = 1; } if (model.typeForm == 3) { model.Product.ProductTypeId = 3; } if (model.typeForm == 5) { model.Product.ProductTypeId = 5; } if (model.typeForm == 7) { model.Product.ProductTypeId = 7; } if (model.typeForm == 11) { model.Product.ProductTypeId = 11; } //MainImage if (model.MainImage != null) { String[] substrings = model.MainImage.Base64.Split(','); model.MainImage.Base64 = substrings[1]; } //Subimage for (int i = 0; i < model.SubImageUpload.Length; i++) { if (model.SubImageUpload.Length > 0) { ImageUploadDTO obj = new ImageUploadDTO(); String[] substrings = model.SubImageUpload[i].Split(','); string header = substrings[0]; string step1 = header.Replace("data:", ""); string step2 = step1.Replace(";base64", ""); string imgData = substrings[1]; obj.Base64 = imgData; obj.FileName = model.SubImageFileName[i]; obj.ExtensionType = step2; model.SubImage.Add(obj); } } var result = await _repoWrapper.Product.CreateProduct(model); return(Json(result)); } else { return(Json(checkResult)); } }