public async Task <IActionResult> Post([FromForm] ShopDTOin shop) { var stream = shop.Picture.OpenReadStream(); CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("drtn3myw4", "662324151252959", "nX0XPARZfpO_WRuESu_3cPoidrA"); CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(account); CloudinaryDotNet.Actions.ImageUploadParams uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams() { File = new CloudinaryDotNet.FileDescription(shop.Picture.Name, stream) }; CloudinaryDotNet.Actions.ImageUploadResult uploadResult = cloudinary.Upload(uploadParams); Shop newShop = new Shop(); newShop.Name = shop.Name; newShop.Address = shop.Address; newShop.PicturePath = uploadResult.SecureUri.ToString(); newShop.Locality = shop.Locality; newShop.Description = shop.Description; _context.Shop.Add(newShop); await _context.SaveChangesAsync(); return(Created($"api/Shop/{newShop.ShopId}", newShop)); }
private void SearchLogoInCloud(string ticker, ref string logoLink) { var cloudinaryAccount = new CloudinaryDotNet.Account( _appSettings.CloudinaryCloudName, _appSettings.CloudinaryApiKey, _appSettings.CloudinaryApiSecret); var cloudinary = new CloudinaryDotNet.Cloudinary(cloudinaryAccount); var checkLogoInCloud = cloudinary.GetResource(ticker); if (checkLogoInCloud.StatusCode == HttpStatusCode.OK) { logoLink = checkLogoInCloud.SecureUrl; } else { // если лого в облаке нет, попытаемся загрузить его туда try { var uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams() { File = new CloudinaryDotNet.FileDescription(ticker + ".png", logoLink), PublicId = ticker }; var uploadResult = cloudinary.Upload(uploadParams); if (uploadResult.StatusCode == HttpStatusCode.OK) { logoLink = uploadResult.SecureUrl?.ToString(); } } catch { // если не получилось, оставляем logoLink как есть, т.е. ссылкой, полученной из StocksWebScraping.GetLogo } } }
public JsonResult CreatePost(Post model) { if (ModelState.IsValid) { using (KonanDBContext _dc = new KonanDBContext()) { model.Id = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 22).Replace("/", "_").Replace("+", "-"); model.Id_A = Session["Id"].ToString(); model.Date = DateTime.Now; var acc = _dc.Accounts.Where(a => a.Id == model.Id_A).FirstOrDefault(); acc.Points += 5; _dc.Entry(acc).State = EntityState.Modified; _dc.SaveChanges(); if (model.Description != null) { Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase); MatchCollection mactches = regx.Matches(model.Description); foreach (Match match in mactches) { model.Description = model.Description.Replace(match.Value, "<a href='" + match.Value + "'>" + match.Value + "</a>"); } } if (model.File != null) { if (model.File.ContentLength > 0) { CloudinaryDotNet.Account account = new CloudinaryDotNet.Account( "ursaciuc-adrian", "473916817971436", "S_S0CSKbWFMVh9-Se8ZXKxWLQLg"); CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(account); var uploadParams = new ImageUploadParams() { File = new FileDescription(model.File.FileName, model.File.InputStream) }; var uploadResult = cloudinary.Upload(uploadParams); model.ImageUrl = uploadResult.Uri.OriginalString; } } _dc.Posts.Add(model); _dc.SaveChanges(); } } return(Json("success")); }
public QuizzesController(ICRUDRepo repo, IMapper mapper, IOptions <CloudinarySettings> cloudinarySettings) { _mapper = mapper; _repo = repo; var account = new CloudinaryDotNet.Account() { ApiKey = cloudinarySettings.Value.ApiKey, ApiSecret = cloudinarySettings.Value.ApiSecret, Cloud = cloudinarySettings.Value.CloudName }; _cloud = new CloudinaryHelper(account); }
public WordsController(ICRUDRepo repo, IMapper mapper, IOptions <CloudinarySettings> cloudinarySettings, IUploadService dropbox) { var cloudAccount = new CloudinaryDotNet.Account() { ApiKey = cloudinarySettings.Value.ApiKey, ApiSecret = cloudinarySettings.Value.ApiSecret, Cloud = cloudinarySettings.Value.CloudName }; _mapper = mapper; _repo = repo; _cloud = new CloudinaryHelper(cloudAccount); _dropbox = dropbox; }
public QuestionsController(ICRUDRepo repo, IMapper mapper, IOptions <CloudinarySettings> cloudSetting, IUploadService dropBox, IConfiguration config) { _dropBox = dropBox; var account = new CloudinaryDotNet.Account() { ApiSecret = cloudSetting.Value.ApiSecret, ApiKey = cloudSetting.Value.ApiKey, Cloud = cloudSetting.Value.CloudName }; _helper = new CloudinaryHelper(account); _mapper = mapper; _repo = repo; _config = config; }
public static async Task <string> UploadImage(Context context, Uri imageUri, string publicId, int size) { var account = new CloudinaryDotNet.Account(CloudName, ApiKey, ApiSecret); var cloudinary = new CloudinaryDotNet.Cloudinary(account); var uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams { File = new CloudinaryDotNet.Actions.FileDescription(FilePathUtilities.GetAbsoluteFilePath(context, GetImageUri(context, ResizeImage(context, imageUri, size)))), PublicId = publicId }; var uploadResult = await cloudinary.UploadAsync(uploadParams); return(uploadResult.Uri.OriginalString); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>( options => options.UseSqlServer(this.configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <ApplicationUser>(IdentityOptionsProvider.GetIdentityOptions) .AddRoles <ApplicationRole>().AddEntityFrameworkStores <ApplicationDbContext>(); services.Configure <CookiePolicyOptions>( options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddControllersWithViews( options => { options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()); }).AddRazorRuntimeCompilation(); services.AddRazorPages(); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddSingleton(this.configuration); // Data repositories services.AddScoped(typeof(IDeletableEntityRepository <>), typeof(EfDeletableEntityRepository <>)); services.AddScoped(typeof(IRepository <>), typeof(EfRepository <>)); services.AddScoped <IDbQueryRunner, DbQueryRunner>(); services.AddTransient <ICarRepository, CarRepository>(); services.AddTransient <ICarModelTypeService, CarModelTypeService>(); //this.RegisterServiceLayer(services); var cloudinaryAccount = new CloudinaryDotNet.Account( this.configuration["Cloudinary:CloudName"], this.configuration["Cloudinary:ApiKey"], this.configuration["Cloudinary:ApiSecret"]); services.AddCloudinary(cloudinaryAccount, ServiceLifetime.Singleton); // Application services services.AddTransient <IEmailSender, NullMessageSender>(); services.AddTransient <ISettingsService, SettingsService>(); }
protected void btnDelete_Click(object sender, ImageClickEventArgs e) { ImageButton Delete = (ImageButton)sender; string IDVal = Delete.CommandArgument; int id = int.Parse(IDVal); HEWDataContext context = new HEWDataContext(); Project project = context.Projects.SingleOrDefault(i => i.ID == id); IEnumerable<ProjectsImage> images = context.ProjectsImages.Where(i => i.ProjectID == id); CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("dlyvxs7of", "634626974285569", "FtB_0jhcmFypFS7QTwCBKcPRGzE"); CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(account); cloudinary.DeleteResources(images.Select(i => i.ImgPublicID).ToArray()); context.ProjectsImages.DeleteAllOnSubmit(images); context.Projects.DeleteOnSubmit(project); context.SubmitChanges(); gvProjects.DataBind(); }
protected void btnDelete_Click(object sender, ImageClickEventArgs e) { ImageButton Delete = (ImageButton)sender; string IDVal = Delete.CommandArgument; int id = int.Parse(IDVal); HEWDataContext context = new HEWDataContext(); Project project = context.Projects.SingleOrDefault(i => i.ID == id); IEnumerable <ProjectsImage> images = context.ProjectsImages.Where(i => i.ProjectID == id); CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("dlyvxs7of", "634626974285569", "FtB_0jhcmFypFS7QTwCBKcPRGzE"); CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(account); cloudinary.DeleteResources(images.Select(i => i.ImgPublicID).ToArray()); context.ProjectsImages.DeleteAllOnSubmit(images); context.Projects.DeleteOnSubmit(project); context.SubmitChanges(); gvProjects.DataBind(); }
public ActionResult ViewProfile(EditProfileViewModel model) { ViewBag.Id = Session["Id"].ToString(); string id = Session["Id"].ToString(); if (string.IsNullOrEmpty(model.OldPassword) && string.IsNullOrEmpty(model.NewPassword) && string.IsNullOrEmpty(model.ConfirmNewPassword) && model.File == null) { ModelState.AddModelError("", "No changes to save!"); return(View(model)); } if (!string.IsNullOrEmpty(model.NewPassword) && string.IsNullOrEmpty(model.OldPassword)) { ModelState.AddModelError("", "Please enter the old password!"); return(View(model)); } Account account = _dc.Accounts.FirstOrDefault(a => a.Id == id); if (!string.IsNullOrEmpty(model.OldPassword) && !string.Equals(Account.PasswordHash(model.OldPassword), account.Password)) { ModelState.AddModelError("", "The old password is incorrect!"); return(View(model)); } else { if (!string.IsNullOrEmpty(model.OldPassword) && string.IsNullOrEmpty(model.NewPassword)) { ModelState.AddModelError("", "Please enter the new password!"); return(View(model)); } else { if (!string.Equals(model.NewPassword, model.ConfirmNewPassword)) { ModelState.AddModelError("", "Password confirmation must match!"); return(View(model)); } else { if (!string.IsNullOrEmpty(model.OldPassword) && string.Equals(model.NewPassword, model.OldPassword)) { ModelState.AddModelError("", "Your new password can't be same as old password!"); return(View(model)); } else { if (!string.IsNullOrEmpty(model.OldPassword)) { account.Password = Account.PasswordHash(model.NewPassword); _dc.Entry(account).State = EntityState.Modified; _dc.SaveChanges(); } } } } } if (model.File != null) { if (model.File.ContentLength > 0) { CloudinaryDotNet.Account cloud = new CloudinaryDotNet.Account( "ursaciuc-adrian", "473916817971436", "S_S0CSKbWFMVh9-Se8ZXKxWLQLg"); CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(cloud); var uploadParams = new ImageUploadParams() { File = new FileDescription(model.File.FileName, model.File.InputStream) }; var uploadResult = cloudinary.Upload(uploadParams); model.ImageUrl = uploadResult.Uri.ToString(); string sessionId = Session["Id"].ToString(); var acc = _dc.Accounts.Find(sessionId); acc.ImageUrl = model.ImageUrl; _dc.Entry(acc).State = EntityState.Modified; _dc.SaveChanges(); } } return(View(model)); }
private string Upload2Cloudinary(HttpPostedFileBase file, string filename) { var settings = ConfigurationManager.AppSettings; CloudinaryDotNet.Account cloudinaryAccount = new CloudinaryDotNet.Account(settings["Cloudinary.CloudName"], settings["Cloudinary.ApiKey"], settings["Cloudinary.ApiSecret"]); string PublicId = Path.GetFileNameWithoutExtension(filename); CloudinaryDotNet.Actions.ImageUploadParams uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams() { //File = new CloudinaryDotNet.Actions.FileDescription(@"E:\godestalbin - Pictures\circle_blue.png"), File = new CloudinaryDotNet.Actions.FileDescription(filename, file.InputStream), PublicId = PublicId }; CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(cloudinaryAccount); cloudinary.DeleteResources(new string[] { PublicId }); CloudinaryDotNet.Actions.ImageUploadResult uploadResult = cloudinary.Upload(uploadParams); return uploadResult.Version; }
public ActionResult SaveFormattedPersonInfo(PersonInfoModel model) { //string decodedMainInfo = string.Empty; //string decodedDiagnosis = string.Empty; //string decodedMoneyInfo = string.Empty; //if (formattedMainInfo != string.Empty) //{ // decodedMainInfo = Server.UrlDecode(formattedMainInfo); //} //if (formattedDiagnosis != string.Empty) //{ // decodedDiagnosis = Server.UrlDecode(formattedDiagnosis); //} //if (formattedMoneyInfo != string.Empty) //{ // decodedMoneyInfo = Server.UrlDecode(formattedMoneyInfo); //} var image = model.Images; CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("df0y2fmjb", "339727939792644", "zUdYMjTI2P1QLNPJeTrYugstHPA"); //CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(account); _personRepository.SetPersonPageInfo(model.MainInfo, model.Diagnosis, model.MoneyInfo); return Json(new { }); }
private string Upload2Cloudinary(Stream file, string filename) { var settings = ConfigurationManager.AppSettings; CloudinaryDotNet.Account cloudinaryAccount = new CloudinaryDotNet.Account(settings["Cloudinary.CloudName"], settings["Cloudinary.ApiKey"], settings["Cloudinary.ApiSecret"]); string PublicId = Path.GetFileNameWithoutExtension(filename); CloudinaryDotNet.Transformation et = new CloudinaryDotNet.Transformation().Angle(new string[] { "exif" }).Width(100).Height(100).Crop("thumb").Gravity("face").Radius(8); CloudinaryDotNet.Transformation et2 = new CloudinaryDotNet.Transformation().Effect("grayscale"); CloudinaryDotNet.Actions.ImageUploadParams uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams() { File = new CloudinaryDotNet.Actions.FileDescription(filename, file), PublicId = PublicId, //Format = "png", //That makes the file much bigger 3,5Kb -> 55Kb //EagerTransforms = new List<CloudinaryDotNet.Transformation>{ et }, Transformation = et //Exif = true //Rotate automatically according to EXIF data }; CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(cloudinaryAccount); cloudinary.DeleteResources(new string[] { PublicId }); CloudinaryDotNet.Actions.ImageUploadResult uploadResult = cloudinary.Upload(uploadParams); return uploadResult.Version; }