public async Task <int> Add(MissionPhoto photo) { _context.Add(photo); var confrm = await _context.SaveChangesAsync(); return(confrm); }
public async Task <int> AddAMissionPhoto(List <string> urlList) { foreach (var data in urlList) { var photo = new MissionPhoto(); photo.UniquePhotoName = data; await _context.MissionPhotos.AddAsync(photo); } var numberCreated = _context.SaveChanges(); return(numberCreated); }
public async Task <IActionResult> UploadOne([FromBody] ImageUploadDto photoModel) { // var photoEntity = _mapper.Map<MissionPhoto>(photoModel); // Validations: if (photoModel.UploadedImage == null) { return(BadRequest("Null file")); } if (photoModel.UploadedImage.Length == 0) { return(BadRequest("Empty file")); } if (photoModel.UploadedImage.Length > MAX_BYTES) { return(BadRequest("Max file size exceeded")); // MAX_BYTES could be stored in a configuraton file } if (ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(photoModel.UploadedImage.FileName).ToLower())) { return(BadRequest("Invalid file type")); } if (ModelState.IsValid) { string uniqueFileName = UploadedFile(photoModel.UploadedImage); MissionPhoto photo = new MissionPhoto { UniquePhotoName = uniqueFileName, UploadDate = DateTime.Now, UploadedBy = photoModel.UploadedBy }; await _imageRepo.Add(photo); } return(Ok("Photo-Upload-Success")); }