public IActionResult MultipleCreate(MultiplePhotoUploadViewModel model) { if (ModelState.IsValid) { foreach (var item in model.Photos) { var isFormatCorrect = SD.IsImage(item); if (isFormatCorrect == true) { string uniqueFileName = MProcessUploadedFile(item); var pic = new pic { Address = uniqueFileName, }; _db.pics.Add(pic); _db.SaveChanges(); } else { ModelState.AddModelError("", "Wrong Format File Uploaded"); return(View(model)); } } } return(RedirectToAction(nameof(Index))); }
public IHttpActionResult Upload([FromBody] MultiplePhotoUploadViewModel model) { var userId = Request.GetUserId(); if (userId < 0) { return(Unauthorized()); } if (model == null) { return(BadRequest("Model cannot be null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (var photoModel in model.Photos) { var photo = new Photo { AlbumId = model.AlbumId, FileId = photoModel.FileId, Name = photoModel.Name, Privacy = photoModel.Privacy, RowState = RowState.Created, UploadedAt = DateTime.Now, UploadedBy = userId }; _photoManager.Add(photo); } return(Ok()); }
public IActionResult MultipleCreate() { var model = new MultiplePhotoUploadViewModel(); return(View(model)); }