public ActionResult CreatHome(HomeImageViewModel Input) { try { var Date = DateTime.Now.ToFileTimeUtc(); String[] Arr = Input.PicturePath.FileName.Split('.'); if (Input.PicturePath != null) { Input.PicturePath.SaveAs(HttpContext. Server.MapPath("~/Images/backgrounds/") + Arr[0] + Date + "_L." + Arr[1]); Bitmap b = new Bitmap(Input.PicturePath.InputStream); var resizedImage = Helpers.ImageResizeHelper.ResizeBitmap(b, 100, 100); resizedImage.Save(HttpContext. Server.MapPath("~/Images/backgrounds/SmallBackGround/") + Arr[0] + Date + "_S." + Arr[1]); } using (TouchContext touch = new TouchContext()) { touch.HomeImages.Add (new HomeImage() { Title = Input.Title, Description = Input.Description, Extention = Arr[1], PicturePath = Arr[0] + Date, IsActive = Input.IsActive }); touch.SaveChanges(); } } catch (Exception ex) { return(Json(false, JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult SaveHomeImages(HomeImageViewModel Input) { try { var Date = DateTime.Now.ToFileTimeUtc(); using (TouchContext touch = new TouchContext()) { var obj = touch.HomeImages.Where(a => a.Id == Input.Id).FirstOrDefault(); obj.Title = Input.Title; obj.Description = Input.Description; obj.IsActive = Input.IsActive; if (Input.PicturePath != null) { string[] Arr = Input.PicturePath.FileName.Split('.'); Input.PicturePath.SaveAs(HttpContext.Server.MapPath("~/Images/backgrounds/") + Arr[0] + Date + "_L." + Arr[1]); Bitmap b = new Bitmap(Input.PicturePath.InputStream); var resizedImage = Helpers.ImageResizeHelper.ResizeBitmap(b, 100, 100); resizedImage.Save(HttpContext.Server.MapPath("~/Images/backgrounds/SmallBackGround/") + Arr[0] + Date + "_S." + Arr[1]); obj.PicturePath = Arr[0] + Date; obj.Extention = Arr[1]; } touch.Entry(obj).State = EntityState.Modified; touch.SaveChanges(); } } catch (Exception ex) { return(Json(false, JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public async Task <FileResult> GetOneHomeImage(int HomeImageId) { HomeImageViewModel onePC = await IMR.GetOneHomeImage(HomeImageId); if (onePC == null) { return(null); } return(File(onePC.PictureContent, onePC.PictureType)); }
public async Task <HomeImageViewModel> GetOneHomeImage(int HomeImageId) { HomeImageViewModel ret = null; try { using (SqlConnection con = new SqlConnection(constr)) { var p = new DynamicParameters(); p.Add("@HomeImageId", HomeImageId, dbType: DbType.Int32, direction: ParameterDirection.Input); p.Add("@r", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); await con.OpenAsync(); IEnumerable <HomeImageViewModel> tmp = await con.QueryAsync <HomeImageViewModel>("sp_GetOneHomeImage", p, commandType : CommandType.StoredProcedure); ret = tmp.FirstOrDefault <HomeImageViewModel>(); } } catch (Exception) { ret = null; } return(ret); }