public static Photo GetPhotoByObjId(int objId, PhotoType type) { return(SQLDataAccess.ExecuteReadOne <Photo>("SELECT * FROM [Catalog].[Photo] WHERE [ObjId] = @ObjId and type=@type", CommandType.Text, GetPhotoFromReader, new SqlParameter("@ObjId", objId), new SqlParameter("@type", type.ToString()))); }
public static void DeletePhotoWithPath(PhotoType type, string photoName) { SQLDataAccess.ExecuteNonQuery("DELETE FROM [Catalog].[Photo] WHERE PhotoName = @PhotoName and type=@type", CommandType.Text, new SqlParameter("@PhotoName", photoName), new SqlParameter("@type", type.ToString())); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="filename"></param> /// <param name="type"></param> /// <returns></returns> public static int InsertPhoto(int id, string filename, PhotoType type) { string field = type == PhotoType.UserPhotos ? "User" : "Game"; return(DalHelper.Insert($"INSERT INTO {type.ToString()} ({field}, Photo) VALUES ({id}, @filename)" , new OleDbParameter("@filename", filename))); }
public static image ReadAndSaveFromUrl(this string url, long subdomainid, long ownerid, long contextid, PhotoType type) { var req = WebRequest.Create(url); WebResponse resp = null; try { resp = req.GetResponse(); } catch (Exception ex) { Syslog.Write(ex); } if (resp == null) { return(null); } try { var image = new image(); using (var repository = new TradelrRepository()) { var sd = repository.GetSubDomain(subdomainid); var extension = url.ToImageFormat().ToStringExtension(); var filename = BuildFilename(ownerid, extension); var handler = new FileHandler(filename, UploadFileType.IMAGE, sd.uniqueid); image.imageType = type.ToString(); image.subdomain = subdomainid; image.contextID = contextid; image.url = handler.Save(resp.GetResponseStream()); repository.AddImage(image); switch (type) { case PhotoType.PROFILE: var usr = repository.GetUserById(ownerid); if (usr != null) { usr.profilePhoto = image.id; } repository.Save("ReadAndSaveFromUrl:Profile"); break; default: break; } } return(image); } catch (Exception ex) { Syslog.Write(ex); return(null); } }
public async Task <IEnumerable <Data.Shared.Models.Photo> > GetPhotosAsync(PhotoType type, int typeId) { var photoResult = _photoRepository.GetSomeAsync(p => p.Type == type.ToString() && p.TypeId == typeId); var photos = new List <Data.Shared.Models.Photo>(); await foreach (var photo in photoResult) { photos.Add(photo.AsModel(_blobStorageRoot)); } return(photos); }
public async Task <IEnumerable <Data.Shared.Models.Photo> > GetPhotosByTypeAsync(PhotoType photoType, List <int> typeIds) { var type = photoType.ToString(); var photoResult = _photoRepository.GetSomeAsync(p => p.TypeId != null && p.Type == type && typeIds.Contains(p.TypeId.Value)); var photos = new List <Data.Shared.Models.Photo>(); await foreach (var photo in photoResult) { photos.Add(photo.AsModel(_blobStorageRoot)); } return(photos); }
public ActionResult UploadBase64Image(PhotoType Type, string strImage) { //Logger.InfoFormat("UploadBase64Image:strImage{0}====Type{1}", strImage, Type); strImage = strImage.Replace(' ', '+').Substring(strImage.IndexOf(',') + 1); strImage = strImage.Trim('\0'); byte[] arr = Convert.FromBase64String(strImage); using (MemoryStream ms = new MemoryStream(arr)) { string path = ConfigurationManager.AppSettings["repairImgPath"].ToString() + "/" + Type.ToString() + "/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string imgName = Guid.NewGuid().ToString("N") + ".jpeg"; Bitmap bmp = new Bitmap(ms); bmp.Save(path + imgName); List <Picture> pInfo = new List <Picture>(); pInfo.Add(new Picture { Type = Type, Url = Type.ToString() + "/" + imgName, CreateTime = DateTime.Now, Note = imgName }); if (pInfo.Count != 0) { using (var db = new MbContext()) { int i = 0; foreach (Picture item in pInfo) { item.CreateTime = DateTime.Now; item.SortField = i; i++; db.Picture.Add(item); db.SaveChanges(); } } return(Json(pInfo.Select(x => new { PictureId = x.PictureId, Name = x.Note }).ToArray())); } else { return(Json(new { error = "图片数量不能0" })); } } }
public string[] DeleteImage(long imageid, long subdomainid, PhotoType imageType) { var data = db.images.Where(x => x.id == imageid && x.subdomain == subdomainid); if (imageType != PhotoType.ALL) { data.Where(x => x.imageType == imageType.ToString()); } var imagepaths = data.Select(x => x.url).ToArray(); db.images.DeleteAllOnSubmit(data); db.SubmitChanges(); return(imagepaths); }
private static void DeletePhotoByOwnerIdAndType(int objId, PhotoType type) { SQLDataAccess.ExecuteNonQuery("Delete FROM [Catalog].[Photo] WHERE [ObjId] = @ObjId and type=@type", CommandType.Text, new SqlParameter("@objId", objId), new SqlParameter("@type", type.ToString())); }
/// <summary> /// return list of photos by type /// </summary> /// <param name="objId"></param> /// <param name="type"></param> /// <returns></returns> public static IEnumerable<Photo> GetPhotos(int objId, PhotoType type) { var list = SQLDataAccess.ExecuteReadIEnumerable<Photo>("SELECT * FROM [Catalog].[Photo] WHERE [objId] = @objId and type=@type ORDER BY [PhotoSortOrder]", CommandType.Text, GetPhotoFromReader, new SqlParameter("@objId", objId), new SqlParameter("@type", type.ToString())); return list; }
public static Photo GetPhotoByObjId(int objId, PhotoType type) { return SQLDataAccess.ExecuteReadOne<Photo>("SELECT * FROM [Catalog].[Photo] WHERE [ObjId] = @ObjId and type=@type", CommandType.Text, GetPhotoFromReader, new SqlParameter("@ObjId", objId), new SqlParameter("@type", type.ToString())); }
/// <summary> /// return list of filename to delete /// </summary> /// <param name="objId"></param> /// <param name="type"></param> /// <returns></returns> public static IEnumerable<string> GetNamePhotos(int objId, PhotoType type) { if (objId == 0) return SQLDataAccess.ExecuteReadIEnumerable<string>("SELECT PhotoName FROM [Catalog].[Photo] WHERE type=@type", CommandType.Text, reader => SQLDataHelper.GetString(reader, "PhotoName"), new SqlParameter("@type", type.ToString())); return SQLDataAccess.ExecuteReadIEnumerable<string>("SELECT PhotoName FROM [Catalog].[Photo] WHERE [objId] = @objId and type=@type", CommandType.Text, reader => SQLDataHelper.GetString(reader, "PhotoName"), new SqlParameter("@objId", objId), new SqlParameter("@type", type.ToString())); }
/// <summary> /// return count of photos by type /// </summary> /// <param name="objId"></param> /// <param name="type"></param> /// <returns></returns> public static int GetCountPhotos(int objId, PhotoType type) { if (objId == 0) return SQLDataAccess.ExecuteScalar<int>("SELECT Count(*) FROM [Catalog].[Photo] WHERE type=@type", CommandType.Text, new SqlParameter("@type", type.ToString())); var res = SQLDataAccess.ExecuteScalar<int>("SELECT Count(*) FROM [Catalog].[Photo] WHERE [objId] = @objId and type=@type", CommandType.Text, new SqlParameter("@objId", objId), new SqlParameter("@type", type.ToString())); return res; }
/// <summary> /// return count of photos by type /// </summary> /// <param name="objId"></param> /// <param name="type"></param> /// <returns></returns> public static int GetCountPhotos(int objId, PhotoType type) { if (objId == 0) { return(SQLDataAccess.ExecuteScalar <int>("SELECT Count(*) FROM [Catalog].[Photo] WHERE type=@type", CommandType.Text, new SqlParameter("@type", type.ToString()))); } var res = SQLDataAccess.ExecuteScalar <int>("SELECT Count(*) FROM [Catalog].[Photo] WHERE [objId] = @objId and type=@type", CommandType.Text, new SqlParameter("@objId", objId), new SqlParameter("@type", type.ToString())); return(res); }
/// <summary> /// return list of filename to delete /// </summary> /// <param name="objId"></param> /// <param name="type"></param> /// <returns></returns> public static IEnumerable <string> GetNamePhotos(int objId, PhotoType type) { if (objId == 0) { return(SQLDataAccess.ExecuteReadIEnumerable <string>("SELECT PhotoName FROM [Catalog].[Photo] WHERE type=@type", CommandType.Text, reader => SQLDataHelper.GetString(reader, "PhotoName"), new SqlParameter("@type", type.ToString()))); } return(SQLDataAccess.ExecuteReadIEnumerable <string>("SELECT PhotoName FROM [Catalog].[Photo] WHERE [objId] = @objId and type=@type", CommandType.Text, reader => SQLDataHelper.GetString(reader, "PhotoName"), new SqlParameter("@objId", objId), new SqlParameter("@type", type.ToString()))); }
/// <summary> /// return list of photos by type /// </summary> /// <param name="objId"></param> /// <param name="type"></param> /// <returns></returns> public static IEnumerable <Photo> GetPhotos(int objId, PhotoType type) { var list = SQLDataAccess.ExecuteReadIEnumerable <Photo>("SELECT * FROM [Catalog].[Photo] WHERE [objId] = @objId and type=@type ORDER BY [PhotoSortOrder]", CommandType.Text, GetPhotoFromReader, new SqlParameter("@objId", objId), new SqlParameter("@type", type.ToString())); return(list); }
public ActionResult Upload(PhotoType type, long?id) { if (!sessionid.HasValue) { return(SendJsonSessionExpired()); } long ownerid = sessionid.Value; if (Request.Files.Count < 1) { throw new Exception(); } var imageUpload = Request.Files[0]; var extIndex = imageUpload.FileName.LastIndexOf('.'); var ext = imageUpload.FileName.Substring(extIndex); string filename = ImgHelper.BuildFilename(sessionid.Value, ext); var handler = new FileHandler(filename, UploadFileType.IMAGE, MASTERdomain.uniqueid); var url = handler.Save(imageUpload.InputStream); if (string.IsNullOrEmpty(url)) { return(Content("," + GeneralConstants.PHOTO_UPLOAD_ERROR_PATH)); } image image = null; product_image pimage = null; long imageid; switch (type) { case PhotoType.BACKGROUND: case PhotoType.PROFILE: case PhotoType.COMPANY: image = new image { imageType = type.ToString(), url = url, subdomain = subdomainid.Value }; imageid = repository.AddImage(image); break; case PhotoType.PRODUCT: pimage = new product_image { url = url, subdomainid = subdomainid.Value }; repository.AddProductImage(pimage); imageid = pimage.id; break; default: throw new NotImplementedException(); } // depending on image type.... user usr; string retVal = ""; long profileID; string thumbnailUrl; switch (type) { case PhotoType.BACKGROUND: thumbnailUrl = Img.by_size(url, Imgsize.COMPACT); retVal = string.Concat(imageid, ",#background_image,", thumbnailUrl); break; case PhotoType.COMPANY: thumbnailUrl = Img.by_size(url, Imgsize.MEDIUM); profileID = id.HasValue ? id.Value : ownerid; usr = repository.GetUserById(profileID, subdomainid.Value); usr.organisation1.logo = imageid; image.contextID = usr.organisation.Value; repository.Save(); retVal = string.Concat(imageid, ",#company_image,", thumbnailUrl); CacheHelper.Instance.invalidate_dependency(DependencyType.organisation, subdomainid.Value.ToString()); break; case PhotoType.PROFILE: thumbnailUrl = Img.by_size(url, Imgsize.MEDIUM); profileID = id.HasValue ? id.Value : ownerid; usr = repository.GetUserById(profileID, subdomainid.Value); usr.profilePhoto = imageid; image.contextID = usr.id; repository.Save(); retVal = string.Concat(imageid, ",#profile_image,", thumbnailUrl); break; case PhotoType.PRODUCT: thumbnailUrl = Img.by_size(url, Imgsize.MEDIUM); retVal = string.Concat(imageid, ",#product_images,", thumbnailUrl); // for when editing products // when creating new product entry, contextid is only updated when product is saved, it will be 0 if images // uploaded and then product is not saved if (id.HasValue) { var productid = id.Value; pimage.productid = productid; repository.Save(); repository.UpdateProductMainThumbnail(productid, subdomainid.Value, imageid.ToString()); } break; } return(Content(retVal)); }
public ActionResult UploadImg(PhotoType Type) { try { HttpFileCollectionBase uploadFile = Request.Files; List <Picture> pInfo = new List <Picture>(); if (uploadFile.Count > 0) { for (int i = 0; i < uploadFile.Count; i++) { HttpPostedFileBase file = uploadFile[i]; string path = ConfigurationManager.AppSettings["repairImgPath"].ToString() + "/" + Type.ToString() + "/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string fileName = Guid.NewGuid().ToString("N") + "." + file.ContentType.ToString().Split('/')[1]; file.SaveAs(path + "/" + fileName); pInfo.Add(new Picture { Type = Type, Url = Type.ToString() + "/" + fileName, CreateTime = DateTime.Now, Note = file.FileName }); } } else { string imgFile = Guid.NewGuid().ToString("N") + ".jpg"; string filePath = ConfigurationManager.AppSettings["repairImgPath"].ToString() + "/" + Type.ToString() + "/"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } byte[] bytes = Request.BinaryRead(Request.TotalBytes); FileStream fStream = new FileStream(filePath + imgFile, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fStream); bw.Write(bytes); bw.Close(); fStream.Close(); pInfo.Add(new Picture { Type = Type, Url = Type.ToString() + "/" + imgFile, CreateTime = DateTime.Now, Note = imgFile }); } if (pInfo.Count != 0) { using (var db = new MbContext()) { int i = 0; foreach (Picture item in pInfo) { item.CreateTime = DateTime.Now; item.SortField = i; i++; db.Picture.Add(item); db.SaveChanges(); } } return(Json(pInfo.Select(x => new { PictureId = x.PictureId, Name = x.Note }).ToArray())); } else { return(Json(new { error = "图片数量不能0" })); } } catch (Exception ex) { return(Json(new { error = ex.Message })); } }
/// <summary> /// gets a photo by id and type /// </summary> /// <param name="id">id of photo</param> /// <param name="type">type of photo</param> /// <returns>DataRow of photo</returns> public static DataRow GetPhoto(int id, PhotoType type) { return(DalHelper.GetRowById(id, type.ToString())); }
/// <summary> /// gets all photos of type /// </summary> /// <param name="type">type of photo</param> /// <returns>DataTable of photos</returns> public static DataTable AllPhotos(PhotoType type) { return(DalHelper.AllFromTable(type.ToString())); }
public IQueryable <image> GetImages(PhotoType type, long contextID) { return(db.images.Where(x => x.imageType == type.ToString() && x.contextID == contextID)); }
private static void DeletePhotoByOwnerIdAndType(int objId, PhotoType type) { SQLDataAccess.ExecuteNonQuery("Delete FROM [Catalog].[Photo] WHERE [ObjId] = @ObjId and type=@type", CommandType.Text, new SqlParameter("@objId", objId), new SqlParameter("@type", type.ToString())); }