public ActionResult OnGetPeriodsInfo(string sessionKey) { StatusReport sr = new StatusReport(); sr = PictureDal.GetPeriodsInfo(); return(Json(sr)); }
public static Picture PictureToOrm(PictureDal pictureDal) { return(new Picture() { Id = pictureDal.Id, Image = pictureDal.Image, Name = pictureDal.Name, Hash = pictureDal.Hash, }); }
public ActionResult OnSetPictureTaped(string picId) { StatusReport sr = new StatusReport(); if (string.IsNullOrEmpty(picId)) { sr.status = "Fail"; sr.result = "未提供图片ID"; return(Json(sr)); } sr = PictureDal.SetPictureTaped(picId); return(Json(sr)); }
public ActionResult OnGetPictures(string periodId, string sortType) { StatusReport sr = new StatusReport(); if (string.IsNullOrEmpty(periodId)) { sr.status = "Fail"; sr.result = "信息不完整"; return(Json(sr)); } sr = PictureDal.GetPictures(periodId, sortType); return(Json(sr)); }
public PictureBll GetPictureById(int id) { if (id <= 0) { throw new InvalidIdException(); } PictureDal foundPicture = repository.GetById(id); if (foundPicture == null) { return(null); } return(foundPicture.ToBll()); }
public ActionResult OnSetPictureVote(string id, string periodId, string sessionKey) { StatusReport sr = new StatusReport(); string openid = GetOpenid(sessionKey); int vote = PictureDal.GetUserVote(openid, periodId); if (vote >= 3) { sr.status = "fail"; sr.result = "投票次数超过限制"; return(Json(sr)); } sr = PictureDal.SetUserVote(id, openid, periodId); if (sr.status == "Fail") { return(Json(sr)); } sr = PictureDal.SetPictureVote(id); return(Json(sr)); }
public void UpdatePicture(PictureBll picture) { if (picture == null) { throw new ArgumentNullException("picture"); } PictureDal currentPicture = picture.ToDal(); PictureDal existedPicture = repository.GetById(picture.Id); if (existedPicture == null) { throw new EntityNotFoundException("picture", picture.Id); } existedPicture.Image = currentPicture.Image; existedPicture.Hash = currentPicture.Hash; existedPicture.Name = currentPicture.Name; repository.Update(existedPicture); uow.Commit(); }
public ActionResult OnSetPicture() { StatusReport sr = new StatusReport(); if (Request.Files.Count == 0) { sr.status = "Fail"; sr.result = "没有图片"; return(Json(sr)); } try { string mainPath = "D:\\wximages\\"; string imagePath = mainPath + Request.Files.AllKeys[0]; string sqlImagePath = Request.Files.AllKeys[0]; HttpPostedFileBase uploadImage = (Request.Files[0]); uploadImage.SaveAs(imagePath); string openid = GetOpenid(Request.Form["sessionKey"]); string nackname = Request.Form["nackname"]; string phone = Request.Form["phone"]; string picName = Request.Form["picName"]; string periodId = Request.Form["periodId"]; string periods = Request.Form["periods"]; string theme = Request.Form["theme"]; string submitTime = Request.Form["submitTime"]; string description = Request.Form["picDescription"]; sr = PictureDal.SetPicture(openid, nackname, phone, picName, periodId, periods, theme, sqlImagePath, submitTime, description); //sr = EquipmentDal.SetEquipmentImage(ID, func, sqlImagePath); return(Json(sr)); } catch (NotImplementedException exp) { sr.status = "Fail"; sr.result = exp.Message; return(Json(sr)); } }
public static List<PictureItemNoBufferData> GetImagesFromDbMin(LogOnModel user, string theme) { using (var db = (ArtGalleryDBContext)DependencyResolver.Current.GetService<DbContext>()) { var userId = user != null ? user.UserId : -1; var pictureDal = new PictureDal(db); var model = pictureDal.Enitities.Where(x => x.UserId == userId); if (theme != null) model = theme == string.Empty ? model.Where(x => x.Theme == string.Empty || x.Theme == null) : model.Where(x => x.Theme.ToLower().Contains(theme.ToLower())); var query = from c in model select new PictureItemNoBufferData() { Artist = c.Artist, Created = c.Created, ID = c.ID, Media = c.Media, Price = c.Price, Size = c.Size, Theme = c.Theme, Title = c.Title, UserId = c.UserId, DisplayOrder = c.DisplayOrder }; return query.OrderBy(x => x.DisplayOrder ?? 9999).ToList(); } }
public static void Refresh(string filePath, bool deleteFiles = false) { lock (_lockObj) { using (var db = new ArtGalleryDBContext()) { var pics = PictureEditorController.GetImagesFromDbMin(""); IPictureDal pictureDal = new PictureDal(db); //delete all disk files if (filePath != null && deleteFiles) { var files = Directory.GetFiles(filePath); foreach (var file in files) { File.Delete(file); } //re-write images foreach (var pic in pics) { try { string fullImagePath = filePath + pic.ID + ".jpg"; string smallImagePath = filePath + pic.ID + "_s.jpg"; var picWithData = pictureDal.Enitities.Find(pic.ID); ImageProcessor.ResizeAndSaveImage(1280, 720, fullImagePath, picWithData.ImageT); var pBuffer = ImageProcessor.CreateThumbnail(fullImagePath, 150, 150, ".jpg"); ImageProcessor.ResizeAndSaveImage(150, 150, smallImagePath, pBuffer); } catch (Exception ex) { Logger.Error("in Refresh cache", ex); } } } else { try { //re-write images foreach (var pic in pics) { string fullImagePath = filePath + pic.ID + ".jpg"; string smallImagePath = filePath + pic.ID + "_s.jpg"; if (!File.Exists(fullImagePath)) { var picWithData = pictureDal.Enitities.Find(pic.ID); ImageProcessor.ResizeAndSaveImage(1280, 720, fullImagePath, picWithData.ImageT); var pBuffer = ImageProcessor.CreateThumbnail(fullImagePath, 150, 150, ".jpg"); ImageProcessor.ResizeAndSaveImage(150, 150, smallImagePath, pBuffer); } } } catch (Exception ex) { Logger.Error("in Refresh cache", ex); } } } } }
//增加图片 public static int addpic(Picture pic) { return(PictureDal.addpic(pic)); }
//修改图片信息 public static int updatepic(Picture pic) { return(PictureDal.updatepic(pic)); }
//根据ID删除图片 public static int deleteid(int picid) { return(PictureDal.deleteid(picid)); }
//根据图片ID查询图片 public static SqlDataReader IDselcet(int ID) { return(PictureDal.Idselect(ID)); }
//查询最新5张玩家原画 public static DataTable yhTop5() { return(PictureDal.yhTop5()); }
//查询所有壁纸 public static DataTable bzAll() { return(PictureDal.bzAll()); }
//查询所有图片 public static DataTable all() { return(PictureDal.All()); }
//PictureItemNoBufferData public static List<LandingPageItemViewModel> GetImagesForLandingPage() { using (var db = (ArtGalleryDBContext)DependencyResolver.Current.GetService<DbContext>()) { var pictureDal = new PictureDal(db); var landingPageDal = new LandingPageDal(db); var fullList = landingPageDal.Enitities.ToList(); var list = fullList.Select(x => x.PictureId).ToList(); var selected = from p in pictureDal.Enitities from l in list where p.ID == l select new PictureItemNoBufferData() { Artist = p.Artist, Created = p.Created, ID = p.ID, Media = p.Media, Price = p.Price, Size = p.Size, Theme = p.Theme, Title = p.Title, UserId = p.UserId, DisplayOrder = p.DisplayOrder }; var ret = selected.ToList(); List<LandingPageItemViewModel> list2 = new List<LandingPageItemViewModel>(); foreach (var landingPageItem in fullList) { var pictureItemNoBufferData = ret.FirstOrDefault(x => x.ID == landingPageItem.PictureId); if (pictureItemNoBufferData == null) { //LogOnModel logOnModel = Permissions.GetCurrentUser(); //if(logOnModel!=null) { pictureItemNoBufferData = new PictureItemNoBufferData() { UserId = 1 }; } } if (pictureItemNoBufferData != null) { var landingPageItemViewModel = new LandingPageItemViewModel() { LandingPageItemId = landingPageItem.Id, Picture = pictureItemNoBufferData }; list2.Add(landingPageItemViewModel); } } return list2; } }
private static IQueryable<PictureItem> GetImagesQuery(ArtGalleryDBContext db, string searchName) { var pictureDal = new PictureDal(db); bool except = false; if (String.IsNullOrEmpty(searchName)) searchName = string.Empty; if (searchName.Length > 0 && searchName.Substring(0, 1) == "!") { searchName = searchName.Substring(1); except = true; } IQueryable<PictureItem> query = null; if (searchName.ToLower() == "anon") query = pictureDal.Enitities.Where(x => (x.Artist == null) || (x.Artist.ToLower() == "anon")); if (searchName.ToLower() == "untitled") query = pictureDal.Enitities.Where(x => (x.Title == null) || (x.Title.ToLower() == "untitled")); if (query == null) if (searchName != string.Empty) { searchName = searchName.ToLower(); query = pictureDal.Enitities.Where(x => (x.Title != null && x.Title.ToLower().Contains(searchName)) || (x.Artist != null && x.Artist.ToLower().Contains(searchName)) || (x.Media != null && x.Media.ToLower().Contains(searchName)) || (x.Theme != null && x.Theme.ToLower().Contains(searchName))); } else query = pictureDal.Enitities; if (except) return pictureDal.Enitities.Except(query); return query; }
public static PictureBll ToBll(this PictureDal pictureDal) { return(Mapper.Map <PictureDal, PictureBll>(pictureDal)); }
public void ProcessRequest(HttpContext context) { try { HttpPostedFile hpf = context.Request.Files["file"]; // if (hpf.ContentLength > 0 && FileIsPicture(hpf)) if (hpf.ContentLength > 0) { int chunk = context.Request["chunk"] != null ? int.Parse(context.Request["chunk"]) : 0; int totalChunks = context.Request["chunks"] != null ? int.Parse(context.Request["chunks"]) : 1; string fileName = context.Request["name"] ?? string.Empty; string filePath = context.Server.MapPath("MyFiles"); using (var fs = new FileStream(Path.Combine(filePath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append)) { var buffer = new byte[hpf.InputStream.Length]; hpf.InputStream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, buffer.Length); } //only do this part when chunk complete if (chunk == totalChunks-1) { byte[] bufferFinal = ImageProcessor.ImageAsByteArray(Path.Combine(filePath, fileName), System.Drawing.Imaging.ImageFormat.Jpeg); using (ArtGalleryDBContext db = new ArtGalleryDBContext()) { var currentUser = UserDal.AllUsers.FirstOrDefault(x => x.UserName.ToLower() == context.User.Identity.Name.ToLower()); if (currentUser == null) { currentUser = new LogOnModel() { UserId = 99999, UserName = context.User.Identity.Name }; Logger.Info("user could not be found for upload", null); } var picture = new PictureItem { ImageT = bufferFinal, Created = DateTime.Now, Artist = currentUser.UserName, UserId = currentUser.UserId }; IPictureDal pictureDal = new PictureDal(db); //saveto db pictureDal.Enitities.Add(picture); pictureDal.SaveChanges(); } } } //save any old file to myFiles... //else //{ // string filePath = context.Server.MapPath("MyFiles") + "\\" + // System.IO.Path.GetFileName(hpf.FileName); // hpf.SaveAs(filePath); //} context.Response.Write("1"); } catch (Exception ex) { Logger.Error("In upload.ashx", ex); } }