private void SavePoster(HttpPostedFileBase[] files, int filmId) { if (files == null || filmId == 0) { return; } var image = files[0]; if (image != null) { DirectoryTools.CheckDirectoryExist(ImageOptions.PATH); var posters = posterSrv[filmId]; DeletePoster(posters); var poster = new PosterImageEntity { FilmId = filmId, MaxImage = ImageResize .Resize(image, ImageOptions.PATH, ImageOptions.IMAGE_WIDTH_MAX_VERTICAL, ImageOptions.IMAGE_HEIGHT_MAX_VERTICAL), MinImage = ImageResize .Resize(image, ImageOptions.PATH, ImageOptions.IMAGE_WIDTH_MIN_VERTICAL, ImageOptions.IMAGE_HEIGHT_MIN_VERTICAL) }; posterSrv.Add(poster); } }
public JsonResult EditorUpload(HttpPostedFileBase file) { Random rnd = new Random(1); int num = rnd.Next(); string fileName = "", mapPath = "", filePath = ""; if (file != null && file.ContentLength > 0) { FileInfo fileInfo = new FileInfo(file.FileName); fileName = Guid.NewGuid().ToString() + fileInfo.Extension; mapPath = HttpContext.Server.MapPath(AppConstants.dirNewsPics); filePath = Path.Combine(mapPath, Path.GetFileName(fileName)); //Welocme! This Induss code! =) if (file.ContentLength > 1024 * 1024 * 2) { throw new HttpException(500, "Размер файла превышает 2 MB!"); } DirectoryTools.CheckDirectoryExist(mapPath); try { file.SaveAs(filePath); } catch { } } string target = Path.Combine(AppConstants.dirNewsPics, fileName); return(Json(new { location = target })); }
public string UploadAvatar() { HttpPostedFileBase file = Request.Files["Avatar"]; DirectoryTools.CheckDirectoryExist(AppConstants.directoryProfileAvatar); string ownerId = User.Identity.GetUserId(); var path = ImageResize.Resize(file, AppConstants.directoryProfileAvatar, 135, 135); var smallPath = ImageResize.Resize(file, AppConstants.directoryProfileAvatar, 40, 40); if (UserManager.IsInRole(ownerId, RoleConstant.RoleCompany)) { var company = orgSrv.GetById(GetCurrentUser().Id); if (company != null) { if (!string.IsNullOrEmpty(company.LargePathImage)) { DirectoryTools.DeleteFile(HttpContext, company.LargePathImage, AppConstants.directoryProfileAvatar); } if (!string.IsNullOrEmpty(company.SmallPathImage)) { DirectoryTools.DeleteFile(HttpContext, company.SmallPathImage, AppConstants.directoryProfileAvatar); } company.LargePathImage = path; company.SmallPathImage = smallPath; orgSrv.Edit(company); } } else { var userPicture = userSrv.Get(GetCurrentUser().Id); if (!string.IsNullOrEmpty(userPicture.PicturePath)) { DirectoryTools.DeleteFile(HttpContext, userPicture.PicturePath, AppConstants.directoryProfileAvatar); } userSrv.UploadAvatar(path, GetCurrentUser()); } return(AppConstants.directoryProfileAvatar + path); }
public ActionResult Edit(OrganizationViewModel model) { model.IsInRole = User.IsInRole; if (ModelState.IsValid) { if (model.ImgFile != null) { DirectoryTools.CheckDirectoryExist(AppConstants.directoryProfileAvatar); var entity = orgService.GetById(model.Id); if (entity != null) { if (entity.SmallPathImage != null) { DirectoryTools.DeleteFile(HttpContext, entity.SmallPathImage); } if (entity.LargePathImage != null) { DirectoryTools.DeleteFile(HttpContext, entity.LargePathImage); } } model.SmallPathImage = ImageResize.Resize(model.ImgFile, AppConstants.directoryProfileAvatar, 50, 50); model.LargePathImage = ImageResize.Resize(model.ImgFile, AppConstants.directoryProfileAvatar, 250, 250); } var result = orgService.Edit(OrganizationMapper.ToEntity(model)); if (result != null) { return(RedirectToAction("Index", "Organization")); } } ViewBag.ListСlassifikate = new SelectList(classifierService.GetAll.ToList(), "Id", "Name"); return(View(model)); }
private void SavePreviewPictrures(HttpPostedFileBase[] files, int articleId, string alt, bool isHeader = false) { if (files != null && files.Length <= 4) { if (files[0] != null) { int smWidth = 150, smHeight = 150, lgWidth = 280, lgHeight = 280; DirectoryTools.CheckDirectoryExist(AppConstants.dirNewsPreview); var pics = newsSrv.GetPictures.Where(x => x.ArticleId == articleId); DeletePreviewPictures(pics, articleId); foreach (HttpPostedFileBase pic in files) { lgHeight = 280; lgWidth = 280; if (isHeader) { lgWidth = 1920; lgHeight = 720; smWidth = 450; smHeight = 290; } isHeader = false; string smSize = ImageResize.Resize(pic, AppConstants.dirNewsPreview, smWidth, smHeight, true), lgSize = ImageResize.Resize(pic, AppConstants.dirNewsPreview, lgWidth, lgHeight, true); newsSrv.SavePicture(articleId, smSize, lgSize, $"{alt}"); } } } }