public ActionResult Upload(HttpPostedFileBase upload) { if (upload == null) { return(View("Error")); } using (var context = new ProfileSampleEntities()) { using (var stream = upload.InputStream) { byte[] buff = new byte[stream.Length]; stream.Read(buff, 0, (int)stream.Length); var entity = new ImgSource() { Name = upload.FileName, Data = buff, }; context.ImgSources.Add(entity); context.SaveChanges(); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Convert() { var files = Directory.GetFiles(Server.MapPath("~/Content/Img"), "*.jpg"); using (var context = new ProfileSampleEntities()) { foreach (var file in files) { using (var stream = new FileStream(file, FileMode.Open)) { byte[] buff = new byte[stream.Length]; stream.Read(buff, 0, (int)stream.Length); var entity = new ImgSource() { Name = Path.GetFileName(file), Data = buff, }; context.ImgSources.Add(entity); context.SaveChanges(); } } } return(RedirectToAction("Index")); }
public ActionResult Index() { var context = new ProfileSampleEntities(); var sources = context.ImgSources.Take(20).Select(x => new ImageModel { Name = x.Name }); //var model = new List<ImageModel>(); //foreach (var id in sources) //{ // var item = context.ImgSources.Find(id); // var obj = new ImageModel() // { // Name = item.Name, // Data = item.Data // }; // model.Add(obj); //} return(View(sources.ToList())); }
//public ActionResult Index() //{ // var context = new ProfileSampleEntities(); // var sources = context.ImgSources.Take(20).Select(x => x.Id); // var model = new List<ImageModel>(); // foreach (var id in sources) // { // var item = context.ImgSources.Find(id); // var obj = new ImageModel() // { // Name = item.Name, // Data = item.Data // }; // model.Add(obj); // } // return View(model); //} public ActionResult Index() { var context = new ProfileSampleEntities(); var sources = context.ImgSources.Take(20).Select(x => new ImageModel { Name = x.Name, Data = x.Data }).ToList(); return(View(sources)); }
public ActionResult Index() { var context = new ProfileSampleEntities(); var models = context.ImgSources //have done some optimization here .Select(x => new ImageModel { Data = x.Data, Name = x.Name }) .Take(20) .ToList(); return(View(models)); }
public ActionResult Index() { using (var context = new ProfileSampleEntities()) { var sources = context.ImgSources.Take(20); var model = sources.Select(item => new ImageModel() { Name = item.Name, Data = item.Data }).ToList(); return(View(model)); } }
public ActionResult Get(string searchPhrase) { IEnumerable <ImageModel> sources; using (var context = new ProfileSampleEntities()) { sources = context.ImgSources.Where(item => item.Name.StartsWith(searchPhrase)) .Select(item => new ImageModel() { Name = item.Name, Data = item.Data }).ToList(); } return(PartialView(sources)); }
public async Task <ActionResult> IndexOptimized() { var model = new List <NewImageModel>(); using (var context = new ProfileSampleEntities()) { var source = await context.ImgSources.Take(20).ToArrayAsync(); model = source.Select(x => new NewImageModel() { Name = x.Name, Data = string.Format("data:image/jpg;base64,{0}", System.Convert.ToBase64String(x.Data)) }).ToList(); } return(View(model)); }
public ActionResult Convert() { using (var context = new ProfileSampleEntities()) { foreach (var file in Directory.EnumerateFiles(Server.MapPath("~/Content/Img"), "*.jpg")) { var buff = System.IO.File.ReadAllBytes(file); context.ImgSources.Add(new ImgSource() { Name = Path.GetFileName(file), Data = buff, }); context.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult Convert() { var files = Directory.GetFiles(Server.MapPath("~/Content/Img"), "*.jpg"); using (var context = new ProfileSampleEntities()) { foreach (var contextImgSource in context.ImgSources.ToList()) { context.ImgSources.Remove(contextImgSource); } files.ForEach(file => context.ImgSources.Add(new ImgSource() { Name = Path.GetFileName(file), Data = LowerImageQuality(System.IO.File.ReadAllBytes(file), 10) })); context.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Index() { var context = new ProfileSampleEntities(); var sources = context.ImgSources.Take(20); var model = new List <ImageModel>(); foreach (var item in sources) { var obj = new ImageModel() { Name = item.Name, Data = item.Data }; model.Add(obj); } return(View(model)); }
public ActionResult Original() { var context = new ProfileSampleEntities(); var sources = context.ImgSources.Take(20).Select(x => x.Id); var model = new List <ImageModel>(); foreach (var id in sources) { var item = context.ImgSources.Find(id); var obj = new ImageModel() { Name = item.Name, Data = item.Data }; model.Add(obj); } return(View("Index", model)); }
public HomeController() { _context = new ProfileSampleEntities(); }