public static void Backup(Image img) { Image newImage = null; string newUrl = File.PreventNameClash(img.GetFileURL()).Replace(Site.MapPath("~/").Replace(@"\", "/"), "~/"); string newName = File.GetFileName(newUrl).Split('.').FirstOrDefault(); newImage = GetImage(img.Name); if (newImage != null) { newImage.GetResizes().ForEach((imgT) => { Backup(imgT); }); newImage.Active = false; newImage.BackupOf = newImage.ID + 0; newImage.ID = 0; newImage.Name = newName; newImage.URL = newImage.GetURL(); System.IO.File.Copy(Site.MapPath(img.GetFileURL()), Site.MapPath(newUrl)); System.IO.File.Copy(Site.MapPath(img.GetThumbUrl()), Site.MapPath(newImage.GetThumbUrl())); using (ImgRDataContext db = new ImgRDataContext()) { var query = (from pp in db.tbl_Images where pp.Name.Equals(img.Name) select pp).FirstOrDefault(); if (query != null) { query.Name = newImage.Name; query.URL = newImage.URL; query.BackupOf = img.ID; query.Active = false; } db.SubmitChanges(); } } }
public static void Edit(Device dv) { if (Exists(dv)) { using (ImgRDataContext db = new ImgRDataContext()) { var query = (from pp in db.tbl_ImageDevices where pp.ID.Equals(dv.ID) || pp.ShortName.Equals(dv.ShortName) select pp).FirstOrDefault(); if (query != null) { query.Width = dv.Width; query.Height = dv.Height; query.UserAgent = dv.UserAgent; query.Orientation = Convert.ToInt32(dv.Orientation); query.Name = dv.Name; query.IsDefault = dv.IsDefault; if (query.IsDefault) { removeAllDefault(); } } db.SubmitChanges(); } for (int i = 0; i < Devices.Count; i++) { var device = Devices[i]; if (device.ID == dv.ID || device.ShortName.Equals(dv.ShortName)) { device = Map(dv.Map()); } } } }
private static long AddToDatabase(Image img) { using (ImgRDataContext db = new ImgRDataContext()) { db.tbl_Images.InsertOnSubmit(Image.Map(img)); db.SubmitChanges(); } return(GetImage(img.Name).ID); }
public static void Add(Image img) { img.Name = CreateImageName(); img.Extension = "jpg"; bool willReplaceExistingImage = false; Image newImage = null; img.URL = img.GetFileURL(); if (img.Data != null) { //save the image if (System.IO.File.Exists(Site.MapPath(img.URL))) { // create and save a backup of the original image if exists willReplaceExistingImage = true; string newUrl = File.PreventNameClash(img.URL).Replace(Site.MapPath("~/"), "~/"); string newName = File.GetFileName(newUrl).Split('.').FirstOrDefault(); System.IO.File.Copy(Site.MapPath(img.URL), Site.MapPath(newUrl)); newImage = GetImage(img.Name); if (newImage != null) { newImage.Active = false; newImage.BackupOf = newImage.ID + 0; newImage.ID = 0; newImage.Name = newName; newImage.URL = newUrl; } } img.Data.ToBitmap().Save(Site.MapPath(img.URL), GetImageFormat(img.Extension)); if (img.Data != null) { img.Data.ToBitmap().Scale(160).Save(Site.MapPath(img.GetThumbUrl()), GetImageFormat(img.Extension)); } img.CreationTime = DateTime.Now; img.ID = AddToDatabase(img); if (img.ResizeForDevices) { img.SaveTransforms(); } if (willReplaceExistingImage) { using (ImgRDataContext db = new ImgRDataContext()) { var query = (from pp in db.tbl_Images where pp.Name.Equals(img.Name) select pp).FirstOrDefault(); if (query != null) { query.Name = newImage.Name; query.URL = newImage.URL; query.BackupOf = img.ID; query.Active = false; } db.SubmitChanges(); } } } }
public static void Add(Device dv) { if (!Exists(dv)) { using (ImgRDataContext db = new ImgRDataContext()) { db.tbl_ImageDevices.InsertOnSubmit(dv.Map()); db.SubmitChanges(); Devices.Add(dv); } } }
private static void removeAllDefault() { Devices.ForEach((device) => device.IsDefault = false); using (ImgRDataContext db = new ImgRDataContext()) { var query = (from pp in db.tbl_ImageDevices select pp); foreach (var device in query) { device.IsDefault = false; } db.SubmitChanges(); } }
public static void Edit(Image img) { if (img.Data != null) { var oldImg = GetImage(img.Name); bool doOldImgResize = oldImg.GetResizes().Count > 0; Backup(img); img.ID = 0; long newImgID = AddToDatabase(img); img.Data.ToBitmap().Save(Site.MapPath(img.GetRootUrl() + img.Name + "." + img.Extension), GetImageFormat(img.Extension)); img.Data.ToBitmap().Scale(160).Save(Site.MapPath(img.GetThumbUrl()), GetImageFormat(img.Extension)); if (doOldImgResize) { img.ID = newImgID; img.SaveTransforms(); } } else { using (ImgRDataContext db = new ImgRDataContext()) { var query = (from pp in db.tbl_Images where pp.ID.Equals(img.ID) || pp.Name.Equals(img.Name) select pp).FirstOrDefault(); if (query != null) { query.Title = img.Title; query.Category = img.Category; query.Description = img.Description; if (img.Data != null) { Bitmap bmp = img.Data.ToBitmap(); query.Width = bmp.Width; query.Height = bmp.Height; } db.SubmitChanges(); } } } }