public async Task <IPlatformResponse <IMessageResponse> > SaveImage(ImageEntities entityType, Guid id, byte[] image, string fileName, string contentType, CancellationToken?cancellationToken = null, IProgress <ISDKProgress> progress = null) { var tokenP = IssueNewTokenAndProgressContainer(cancellationToken, progress); if (string.IsNullOrEmpty(fileName)) { fileName = "App.Profile.Picture"; } if (string.IsNullOrEmpty(contentType)) { contentType = "image/png"; } var headers = new Dictionary <string, string> { { "Content-Type", contentType }, { "Filename", fileName } }; if ((await Login(Authorization, cancellationToken, progress)).Success) { var result = await _clientBuilder.Request <IMessageResponse>(ApiEndpoint.Api, $"v2/{entityType}/{id}/image", tokenP.CancellationToken, tokenP.Progress, HttpMethod.Post, null, image, "application/json", headers); await _cache.Delete($"Apps.{Authorization.UserName}{entityType}{id}"); return(result); } _log.Fatal(new Exception("Authorization Failed")); return(await Task.FromResult <IPlatformResponse <IMessageResponse> >(null)); }
public ActionResult UploadFile(Image Img, HttpPostedFileBase file) { try { //kjdshfkjdshf Image imageModel = new Image(); if (file.ContentLength > 0) { string _FileName = Path.GetFileName(file.FileName); string _path = Path.Combine(Server.MapPath("~/UploadedFiles"), _FileName); imageModel.ImagePath = _path; imageModel.FileName = _FileName; imageModel.Title = Img.Title; file.SaveAs(_path); } using (ImageEntities db = new ImageEntities()) { db.Images.Add(imageModel); db.SaveChanges(); } ViewBag.Message = "File Uploaded Successfully!!"; return(View()); } catch { ViewBag.Message = "File upload failed!!"; return(View()); } }
public ActionResult UserGallery() { using (ImageEntities db = new ImageEntities()) { int userId = GetUserId(User.Identity.Name); var usrImgList = db.Images.Where(x => x.UserId == userId).Select(x => x); List <Image> list = usrImgList.ToList(); return(View(list)); } }
public async Task <IPlatformResponse <IImage> > GetImage(ImageEntities entityType, Guid id, CancellationToken?cancellationToken = null, IProgress <ISDKProgress> progress = null) { var tokenP = IssueNewTokenAndProgressContainer(cancellationToken, progress); if ((await Login(Authorization, cancellationToken, progress)).Success) { return(await CacheHitOrMiss($"VehicleImage.{Authorization.UserName}.{entityType}" + id, () => _clientBuilder.Request <IImage>(ApiEndpoint.Api, $"v2/{entityType}/{id}/image", tokenP.CancellationToken, tokenP.Progress), TimeSpan.FromMinutes(60))); } _log.Fatal(new Exception("Authorization Failed")); return(await Task.FromResult <IPlatformResponse <IImage> >(null)); }
private void AddToDB(ImageUploadResult uploadResult) { string imageUrl = uploadResult.Uri.ToString(); Image uploadedImage = new Image { PhotoUrl = imageUrl, UserId = GetUserId(User.Identity.Name) }; using (ImageEntities db = new ImageEntities()) { db.Images.Add(uploadedImage); db.SaveChanges(); } }
public async Task <IPlatformResponse <IMessageResponse> > DeleteImage(ImageEntities entityType, Guid id, CancellationToken?cancellationToken = null, IProgress <ISDKProgress> progress = null) { var tokenP = IssueNewTokenAndProgressContainer(cancellationToken, progress); if ((await Login(Authorization, cancellationToken, progress)).Success) { var result = await _clientBuilder.Request <IMessageResponse>(ApiEndpoint.Api, $"v2/{entityType}/{id}/image", tokenP.CancellationToken, tokenP.Progress, HttpMethod.Delete); await _cache.Delete($"Apps.{Authorization.UserName}{entityType}{id}"); return(result); } _log.Fatal(new Exception("Authorization Failed")); return(await Task.FromResult <IPlatformResponse <IMessageResponse> >(null)); }
private async void Button_Click_1(object sender, RoutedEventArgs e) { FileInfo file = new FileInfo(fileName); using (ImageEntities imageEntities = new ImageEntities()) { ImageInfo my = new ImageInfo { Name = file.Name, ShortName = file.Name, Image = ImageConverter.ConvertImageToByteArray(ImageHandler.Source as BitmapImage), Text = "Zdjęcie" }; imageEntities.ImageInfo.Add(my); await imageEntities.SaveChangesAsync(); MessageBox.Show("Done", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } }
public async Task <IPlatformResponse <IMessageResponse> > SaveImage(ImageEntities entityType, Guid id, byte[] image, string fileName, string contentType, CancellationToken?cancellationToken = null, IProgress <ISDKProgress> progress = null) { SetupTokenAndProgress(cancellationToken, progress); return(await SdkClient.SaveImage(entityType, id, image, fileName, contentType, cancellationToken, progress)); }
public async Task <IPlatformResponse <IMessageResponse> > DeleteImage(ImageEntities entityType, Guid id, CancellationToken?cancellationToken = null, IProgress <ISDKProgress> progress = null) { SetupTokenAndProgress(cancellationToken, progress); return(await SdkClient.DeleteImage(entityType, id, cancellationToken, progress)); }
public ImageEntities Get() { return(dataContext ?? (dataContext = new ImageEntities())); }