public JsonResult SelectImgJson() { String id = Request["id"]; List <ImageModel> list = new List <ImageModel>(); if (!(id == null || id.Equals(""))) { list.Add(ImgService.selectImgById(Convert.ToInt64(id))); } else { DefaultConfig config = setConfig(); if (Request["limit"] != null) { config.limit = Convert.ToInt32(Request["limit"]); } if (config.order == StaticVal.Order.ORDER_BY_RANDOM) { list.AddRange(ImgService.random(config)); } else { list.Add(ImgService.selectImg(config)); } } DataTool.addHis("json", IPAddress(), list); return(Json(list, JsonRequestBehavior.AllowGet)); }
// GET: Main public ActionResult Index() { DefaultConfig con = new DefaultConfig(); con.fileSize = Convert.ToInt64(1.5 * 1024.0 * 1024.0); con.limit = 1; ViewBag.sss = con.fileSize; ViewBag.img = ImgService.random(con)[0].Kid; ViewBag.sum = DataTool.getSum(); ViewBag.count = DataTool.getCount(1); return(View()); }
public void SelectTest() { Dictionary <String, String> collection = new Dictionary <string, string>(); collection["tag"] = "girl"; collection["height"] = "1080"; collection["width"] = "1920"; collection["author"] = "1920"; DefaultConfig config = new DefaultConfig(); config.limit = 9; string[] AllTags = { }; if (collection["tags"] != null) { if (collection["tags"] != null) { AllTags = collection["tags"].Split(','); } else { } if (AllTags.Length != 0) { foreach (string tmp in AllTags) { config.tags.Add(tmp); } } } if (collection["height"] != null && collection["height"] != "") { string h = collection["height"]; config.h_max = Convert.ToInt32(collection["height"]); } if (collection["width"] != null && collection["width"] != "") { config.w_max = Convert.ToInt32(collection["width"]); } if (collection["author"] != null && collection["author"] != "") { config.author = collection["author"]; } var imgs = ImgService.selectImgList(config); Assert.IsNotNull(imgs); }
public async Task AddImgToAdTests() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()); var carRepository = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options)); var cloudinaryAccount = new CloudinaryDotNet.Account("name", "apiKey", "apiSecret"); var cloudinary = new Cloudinary(cloudinaryAccount); var service = new ImgService(cloudinary, carRepository); var newCar = new Car { Cc = 1, Color = 0, Condition = DimiAuto.Data.Models.CarModel.Condition.New, Door = Doors.Three, EuroStandart = EuroStandart.Euro1, Extras = "4x4", Fuel = Fuel.Diesel, Gearbox = Gearbox.Automatic, Horsepowers = 1, ImgsPaths = GlobalConstants.DefaultImgCar, Km = 100, Location = Location.Sofia, Make = Make.Audi, Model = "test", Modification = "test", MoreInformation = "test test", Price = 100, Type = Types.Convertible, TypeOfVeichle = TypeOfVeichle.Car, YearOfProduction = DateTime.ParseExact("01.1999", "mm.yyyy", CultureInfo.InvariantCulture), UserId = "1", }; var imgUrl = "someImgsUrls"; await carRepository.AddAsync(newCar); await carRepository.SaveChangesAsync(); var car = await carRepository.All().FirstAsync(); await service.AddImgToCurrentAdAsync(imgUrl, car.Id); Assert.Equal(imgUrl, car.ImgsPaths); }
public void SelectImgPng( ) { DefaultConfig config = new DefaultConfig(); String id = Request["id"]; List <ImageModel> list = new List <ImageModel>(); if (!(id == null || id.Equals(""))) { list.Add(ImgService.selectImgById(Convert.ToInt64(id))); } else { config = setConfig(); if (config.order == StaticVal.Order.ORDER_BY_RANDOM) { list.AddRange(ImgService.random(config)); } else { list.Add(ImgService.selectImg(config)); } } DataTool.addHis("png", IPAddress(), list[0].Kid); string pathh = "C:\\Onedrive\\OneDrive - ITBYCX\\pmcdn\\" + Convert.ToInt32(list[0].Kid) / 1000 + "\\" + list[0].Kid + getExt(list[0].File_url); FileStream fs = new FileStream(pathh, FileMode.Open);//可以是其他重载方法 byte[] byData = new byte[fs.Length]; fs.Read(byData, 0, byData.Length); fs.Close(); if (getExt(list[0].File_url).Equals(".png")) { Response.ContentType = "image/png"; Response.BinaryWrite(byData); } else { Response.ContentType = "image/jpeg"; Response.BinaryWrite(byData); } }
public string favor() { string uname = Request.Cookies["user"].Value.ToString(); string kid = Request["kid"]; int status = UserService.updateFavor(uname, kid); ImageModel image = ImgService.selectImgById(Convert.ToInt64(kid)); JavaScriptSerializer javaScript = new JavaScriptSerializer(); if (status == 1) { return("1"); } else if (status == -1) { return("-1"); } else { return("0"); } }
public ActionResult Select(FormCollection collection) { if (Request.Cookies["user"] == null) { return(Redirect("/Login")); } int page = 1; if (Request["page"] != null) { page = Convert.ToInt32(Request["page"].ToString()); } DefaultConfig config = new DefaultConfig(); config.username = Request.Cookies["user"].Value.ToString(); config.limit = 9; string[] AllTags = { }; if (collection["tags"] != null || Request["tags"] != null) { if (collection["tags"] != null) { AllTags = collection["tags"].Split(','); } else { AllTags = Request["tags"].Split(','); } if (AllTags.Length != 0) { foreach (string tmp in AllTags) { config.tags.Add(tmp); } } } else { } if (collection["height"] != null && collection["height"] != "") { string h = collection["height"]; config.h_max = Convert.ToInt32(collection["height"]); } if (collection["width"] != null && collection["width"] != "") { config.w_max = Convert.ToInt32(collection["width"]); } if (collection["author"] != null && collection["author"] != "") { config.author = collection["author"]; } if (collection["order"] != null && collection["order"] != "") { if (collection["order"] == "height") { config.order = StaticVal.Order.ORDER_BY_HEIGHT; } else if (collection["order"] == "width") { config.order = StaticVal.Order.ORDER_BY_WIDTH; } else if (collection["order"] == "width") { config.order = StaticVal.Order.ORDER_BY_WIDTH; } else if (collection["order"] == "time") { config.order = StaticVal.Order.ORDER_BY_CREATETIME; } else if (collection["order"] == "likes") { config.order = StaticVal.Order.ORDER_BY_LIKES; } } if (collection["desc"] != null && collection["desc"] != "") { if (collection["desc"] == "1") { config.sort = StaticVal.Sort.desc; } else { config.sort = StaticVal.Sort.asc; } } if (collection["ext"] != null && collection["ext"] != "") { config.ext = collection["ext"]; } List <string> t = new List <string>(); ViewBag.url = getUrl(config); string tagStr = ""; List <SelectListItem> tags = new List <SelectListItem>(); Dictionary <string, int> taglist = DataTool.getTags(2000); foreach (var item in taglist) { SelectListItem selectListItem = new SelectListItem { Text = item.Key.ToString(), Value = item.Key.ToString() }; foreach (string i in config.tags) { if (i == item.Key) { selectListItem.Selected = true; if (tagStr.Length > 0) { tagStr += ","; } tagStr += i; } } tags.Add(selectListItem); } ViewBag.height = config.h_max; ViewBag.width = config.w_max; ViewBag.taglist = tags; ViewBag.tagStr = tagStr; ViewBag.pageName = "map"; int number = ImgService.selectImgListCount(config); int pageNum = Convert.ToInt32(Math.Ceiling(number * 1.0 / 9.0).ToString()); ViewBag.pageNum = pageNum; ViewBag.page = page; var imgs = ImgService.selectImgList(config, 9 * (page - 1), 9, Request.Cookies["user"].Value.ToString()); List <SelectListItem> exts = new List <SelectListItem> { new SelectListItem { Text = "png", Value = "png" }, new SelectListItem { Text = "jpg", Value = "jpg" } }; List <SelectListItem> desc = new List <SelectListItem> { new SelectListItem { Text = "true", Value = "1" }, new SelectListItem { Text = "false", Value = "0" } }; List <SelectListItem> order = new List <SelectListItem> { new SelectListItem { Text = "time", Value = "time" }, new SelectListItem { Text = "height", Value = "height" }, new SelectListItem { Text = "width", Value = "width" }, new SelectListItem { Text = "likes", Value = "likes" } }; if (config.ext == "png") { exts[0].Selected = true; } else if (config.ext == "jpg") { exts[1].Selected = true; } if (!config.author.Equals(StaticVal.DEFAULT_AUTHOR)) { ViewBag.author = config.author; } else { ViewBag.author = ""; } switch (config.sort) { case StaticVal.Sort.desc: desc[0].Selected = true; break; case StaticVal.Sort.asc: desc[1].Selected = true; break; default: desc[0].Selected = true; break; } switch (config.order) { case StaticVal.Order.ORDER_BY_CREATETIME: order[0].Selected = true; break; case StaticVal.Order.ORDER_BY_HEIGHT: order[1].Selected = true; break; case StaticVal.Order.ORDER_BY_WIDTH: order[2].Selected = true; break; case StaticVal.Order.ORDER_BY_LIKES: order[3].Selected = true; break; default: order[0].Selected = true; break; } ViewBag.order = order; ViewBag.desc = desc; ViewBag.exts = exts; ViewBag.imgs = imgs; return(View()); }
public ImgController(ImgService imgService) { _imgService = imgService; }