private static void FormatPictureForNews(WebImage img, libraryNaturguiden.Picture picture) { var imgFormated = img.Clone(); imgFormated = cropImage(imgFormated, 400, 200); picture.FormatedUrl = $"images/news/{picture.FileName} _news_{Guid.NewGuid()}.{img.ImageFormat}"; imgFormated.Save("../" + picture.FormatedUrl); }
public static async Task <HttpStatusCode> UpdatePictureAsync(libraryNaturguiden.Picture picture) { Setup(); HttpResponseMessage response = await client.PutAsJsonAsync($"api/Picture/{picture.Id}", picture); response.EnsureSuccessStatusCode(); return(response.StatusCode); }
public static async Task <libraryNaturguiden.Picture> GetPictureAsync(int id) { Setup(); libraryNaturguiden.Picture value = null; HttpResponseMessage response = await client.GetAsync("api/Picture/" + id); if (response.IsSuccessStatusCode) { value = await response.Content.ReadAsAsync <libraryNaturguiden.Picture>(); } return(value); }
private static void FormatPictureForAlbum(WebImage img, libraryNaturguiden.Picture picture) { var imgThumb = img.Clone(); var imgFormated = img.Clone(); imgThumb = cropImage(imgThumb, 600, 400); imgFormated.Resize(1806, 1206, true, true); imgFormated.Crop(3, 3, 3, 3); picture.ThumbUrl = $"images/album/thumbs/{picture.FileName}_thumb_{Guid.NewGuid()}.{img.ImageFormat}"; picture.FormatedUrl = $"images/album/{picture.FileName}_album_{Guid.NewGuid()}.{img.ImageFormat}"; imgThumb.Save("../" + picture.ThumbUrl); imgFormated.Save("../" + picture.FormatedUrl); }
public void EditPicture(libraryNaturguiden.Picture picture) { var dbPicture = db.Picture.Where(x => x.Id == picture.Id).FirstOrDefault(); dbPicture.Alt = picture.Alt; dbPicture.Date = picture.Date; dbPicture.Owner = picture.Owner; dbPicture.Url = picture.Url; dbPicture.FormatedUrl = picture.FormatedUrl; dbPicture.ThumbUrl = picture.ThumbUrl; dbPicture.Filename = picture.FileName; dbPicture.Format = picture.Format; dbPicture.Category = picture.Categories == null ? null : db.Category.Where(x => picture.Categories.Contains(x.Id)).ToList(); db.SaveChanges(); }
public static async Task <HttpStatusCode> DeletePictureAsync(int id) { libraryNaturguiden.Picture picture = null; Setup(); HttpResponseMessage response = await client.GetAsync("api/Picture/" + id); if (response.IsSuccessStatusCode) { picture = await response.Content.ReadAsAsync <libraryNaturguiden.Picture>(); response = await client.DeleteAsync($"api/Picture/{id}"); } if (response.IsSuccessStatusCode) { removePictureFromDisc(picture); } return(response.StatusCode); }
public void AddPicture(libraryNaturguiden.Picture newPicture) { var picture = new Picture { Alt = newPicture.Alt, Date = newPicture.Date, Owner = newPicture.Owner, Url = newPicture.Url, FormatedUrl = newPicture.FormatedUrl, ThumbUrl = newPicture.ThumbUrl, Filename = newPicture.FileName, Format = newPicture.Format, Category = newPicture.Categories == null ? null : db.Category.Where(x => newPicture.Categories.Contains(x.Id)).ToList() }; db.Picture.Add(picture); db.SaveChanges(); }
public static async Task <HttpStatusCode> CreatePictureAsync(libraryNaturguiden.Picture picture, WebImage img) { if (picture.Format.ToLower().Equals("album")) { FormatPictureForAlbum(img, picture); } else if (picture.Format.ToLower().Equals("news")) { FormatPictureForNews(img, picture); } picture.Url = $"images/{picture.FileName}_orginal_{Guid.NewGuid()}.{img.ImageFormat}"; img.Save("../" + picture.Url); Setup(); HttpResponseMessage response = await client.PostAsJsonAsync("api/Picture", picture); response.EnsureSuccessStatusCode(); return(response.StatusCode); }