//post photo api //should return rp public ActionResult <PhotoAddRp> AddPhoto(PhotoAddRt rt) { var photo = _mapper.Map <Photo>(rt); _photoRepository.AddPhoto(photo); _photoRepository.SaveChanges(); return(Ok(_mapper.Map <PhotoAddRp>(photo))); }
// POST: Photo/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. public ActionResult SaveDropzoneJsUploadedFiles(int tripId) { foreach (string fileName in Request.Files) { var file = Request.Files[fileName]; db.AddPhoto(new Photo { Image = GetBytesFromFile(file), TripId = tripId }); } return(null); }
//public IActionResult Create(string Title, string Description) public IActionResult Create(PhotoViewModel viewModel) { //azon a controller/action-on ami modelt fogad kötelező a validálás és eredményének ellenőrzése //méghozzá a ModellState állapotának ellenőrzése, itt jelenik meg a validálás végeredménye if (!ModelState.IsValid) { //A View-t fel kell készíteni a hibainformációk megjelenítésére return(View(viewModel)); } var model = mapper.Map <PhotoModel>(viewModel); //Több profil betöltése //var autoMapperCfg = new AutoMapper.MapperConfiguration( // cfg => { // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // }); //viewModel.ContentType = viewModel.PictureFormBrowser.ContentType; repository.AddPhoto(model); //a kép elmentése után térjen vissza az index oldalra return(RedirectToAction("Index")); }
//public IActionResult Create(string Title, string Description) public IActionResult Create(PhotoViewModel viewModel) //Itt az MVC modelbindere a bejövő paramétereket egyezteti a várt osztály propertyjeivel és ki is tölti { //Azon a Controller/Action-ön, ami model-t fogad, kötelező a validálás és eredményének az ellenőrzése //méghozzá a ModelState állapotának ellenőrzése, itt jelenik meg a validálás végeredménye //+ha tudjuk, akkor ValidationAttrubute-okon keresztül ellenőrizzünk if (!ModelState.IsValid) { //A View-t fel kell készíteni a hibainformációk //megjelenítésére return(View(viewModel)); } //több profile betöltése //var autoMapperCfg = new AutoMapper.MapperConfiguration( // cfg => // { // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // }); //El kell végezni a ViewModel=>Model transzformációt //////////////////////////////////////////////////// var model = mapper.Map <PhotoModel>(viewModel); repository.AddPhoto(model); //A kép elmentése után térjen vissza az Index oldalra return(RedirectToAction("Index")); }
public async Task <IActionResult> AddPhotoForUser(Guid userId, int idCategory, [FromForm] PhotoForCreationDto photoForCreationDto) { var file = photoForCreationDto.File; var uploadResult = new ImageUploadResult(); if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.Name, stream), Transformation = new Transformation().Width(500).Height(500) }; uploadResult = _cloudinary.Upload(uploadParams); } } photoForCreationDto.Url = uploadResult.Url.ToString(); photoForCreationDto.PublicId = uploadResult.PublicId; photoForCreationDto.Description = ""; var photo = await _photoRepository.AddPhoto(userId, idCategory, photoForCreationDto); var photoToReturn = _mapper.Map <PhotoForReturnDto>(photo); return(CreatedAtRoute("GetPhoto", new { id = photo.Id }, photoToReturn)); }
public async Task <ActionResult <PhotoDto> > AddPhoto(IFormFile file) { var user = await _userRepository.GetUserByUsername(User.GetUserName()); var result = await _photoService.AddPhoto(file); if (result.Error != null) { return(BadRequest(result.Error.Message)); } ; var photo = new Photo { Url = result.SecureUrl.AbsoluteUri, PublicId = result.PublicId }; if (user.Photos.Count == 0) { photo.IsMain = true; } await _photoRepository.AddPhoto(User.GetUserName(), photo); if (photo != null) { return(CreatedAtRoute("GetUserByName", new { username = user.UserName }, _mapper.Map <PhotoDto>(photo))); } return(BadRequest("Problem adding photo")); }
public IActionResult UploadPhoto(HomeViewModel model) { if (ModelState.IsValid) { _photoRepository.AddPhoto(model); } return(RedirectToAction("Index", "Home")); }
public ActionResult Create([Bind(Include = "AlbumId, Title, Image, CreationDate")] NewPhotoViewModel photoViewModel) { if (ModelState.IsValid) { _photoRepository.AddPhoto(photoViewModel.ToPhotoEntity()); return(RedirectToAlbumBrowse(photoViewModel.AlbumId)); } photoViewModel.Albums = CreateAlbumSelectList(); return(View(photoViewModel)); }
public async Task AddPhoto(AddPhotoDto photoDto) { DateTime dateTime = DateTime.Now; byte[] bytesPhoto = Convert.FromBase64String(photoDto.ImageBytes); await _photoRepository.AddPhoto(new Photo { Title = photoDto.Title, ImageBytes = bytesPhoto, UpdateDateTime = dateTime }); }
public async Task <IActionResult> PostPhoto([FromForm] PhotoCreateRequest request) { if (request.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value) || User.FindFirst(ClaimTypes.Role).Value != "1") { return(Unauthorized()); } User user = await _userRepo.GetUser(request.UserId); if (user == null) { return(Unauthorized()); } var uploadResult = new ImageUploadResult(); if (request.File.Length > 0) { using (var stream = request.File.OpenReadStream()) { var uploadParams = new ImageUploadParams() { File = new FileDescription(request.File.Name, stream), Folder = "Writers/" + request.UserId }; uploadResult = await _cloudinary.UploadAsync(uploadParams); } } try { if (uploadResult != null) { var photo = new Photo() { PhotoUrl = uploadResult.Url.ToString(), PublicId = uploadResult.PublicId, User = user }; await _repo.AddPhoto(photo); return(Ok(Newtonsoft.Json.JsonConvert.SerializeObject(photo.PublicId))); } } catch (System.Exception ex) { Extensions.ReportError(ex); throw; } return(BadRequest()); }
public async Task <bool> UploadPhoto(string tripId, byte[] file, string fileName) { var photoId = Guid.NewGuid().ToString(); var baseUrl = Environment.GetEnvironmentVariable("STORAGE_BLOB_BASE_URL"); await _photoStorageRepository.UploadPhotoToBlob(fileName, file); var newPhoto = await _photoRepository.AddPhoto(new Photo { PhotoId = photoId, TripId = tripId, Url = $"{baseUrl}/{fileName}" }); return(newPhoto != null); }
public async Task <IActionResult> UploadFiles(List <IFormFile> files) { if (files == null || files.Count == 0) { return(Content("files not selected")); } if (ModelState.IsValid) { foreach (var file in files) { //var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\uploads", file.GetFilename()); var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.ToString().Trim('"'); using (var fileStream = new FileStream(Path.Combine(path, fileName), FileMode.Create)) { using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream); var photo = new Photo { PropertyId = null, BuildingId = null, BuildingSeq = null, MasterPhoto = null, FrontPhoto = null, PublicPhoto = null, DateTaken = null, ImageName = file.GetFilename(), ImageSize = file.Length / 1024, ImageData = memoryStream.ToArray(), UserId = 1, UploadedBy = User.Identity.Name.ToLower(), UploadedDate = DateTime.Now, Status = "Pending", Active = false, }; _photoRepo.AddPhoto(photo); } } } } return(RedirectToAction("Files")); }
public async Task <GenericResponse <bool> > AddPhoto(Photo photo) { var vloResponse = new GenericResponse <bool>(); try { vloResponse.Status = HttpStatusCode.OK; vloResponse.Response = await _photoRepository.AddPhoto(photo); } catch (Exception ex) { vloResponse.Status = HttpStatusCode.BadRequest; vloResponse.Response = false; } return(vloResponse); }
public async Task <IActionResult> AddArticle([FromForm] Article article) { try { if (!ModelState.IsValid) { return(BadRequest()); } if (article.Image != null && article.Image.ContentType.Contains("image") && article.Image.Length < fileSize) { var image = await photoRepo.AddPhoto(article.Image); article.PhotoId = image.PhotoId; } await repo.AddArticle(article); return(new CreatedAtRouteResult(nameof(GetArticle), new { id = article.AuthorId }, article)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Error: {e.Message}")); } }
public IActionResult Create(PhotoViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var model = mapper.Map <PhotoModel>(viewModel); // Több profile betöltése //var autoMApperCfg = new AutoMapper.MapperConfiguration( // cfg => // { // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // cfg.AddProfile(new PhotoProfile()); // }); repository.AddPhoto(model); //return View(model); return(RedirectToAction("Index")); }
/// <summary> /// 增加图片 /// </summary> /// <param name="photoModel"></param> /// <returns></returns> public bool AddPhoto(PhotoModel photoModel) { return(_photoRepository.AddPhoto(photoModel)); }
public void AddPhoto(Photo photo) { photoRepository.AddPhoto(photo); uow.Commit(); }
public Response <PhotoViewModel> AddPhoto(PhotoViewModel photo) { return(photoRepository.AddPhoto(photo)); }
public async Task <IActionResult> UploadPhoto([FromForm] PhotoFile file) { var photo = file.Photo; var sizeMB = photo.Length / 1024 / 1000; if (sizeMB > 10) { return(StatusCode(400, new ErrorDetails() { errorId = ErrorList.WrongSize.Id, errorMessage = ErrorList.WrongSize.Description })); } int userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(c => c.Type == claimTypes.Id.ToString()).Value); int?albumId = file.AlbumId; if (albumId > 0) { if (!db.CheckAlbumExists((int)albumId, userId)) { return(StatusCode(403, new ErrorDetails() { errorId = ErrorList.UnauthorizedAction.Id, errorMessage = ErrorList.UnauthorizedAction.Description }.ToString())); } } var extension = Path.GetExtension(photo.FileName).Replace(".", ""); if (!AllowedExtensions.Contains(extension)) { return(BadRequest(new ErrorDetails() { errorId = ErrorList.InputDataError.Id, errorMessage = ErrorList.InputDataError.Description }.ToString())); } ; var imageName = Guid.NewGuid().ToString().Replace("-", ""); var newFilename = $"{imageName}.{extension}"; var thumbName = $"{imageName}_thumb.{extension}"; var additionalPath = $"/{userId}"; var newImagePath = $"{additionalPath}/{newFilename}"; var newThumbPath = $"{additionalPath}/{thumbName}"; db.AddPhoto(newFilename, userId, albumId, newImagePath, newThumbPath, thumbName); var path = storage + newImagePath; var thumbPath = storage + newThumbPath; if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } using (var fileStream = new FileStream(path, FileMode.Create)) { await photo.CopyToAsync(fileStream); } var resizedThumb = helper.ResizeImage(Image.FromStream(photo.OpenReadStream())); if (!Directory.Exists(Path.GetDirectoryName(thumbPath))) { Directory.CreateDirectory(Path.GetDirectoryName(thumbPath)); } helper.SaveImage(resizedThumb, thumbPath); return(Ok(new { response = new { fileName = newFilename } })); }