public async Task <IActionResult> Create([Bind("Id,Name,Path")] PictureModel pictureModel) { if (ModelState.IsValid) { _context.Add(pictureModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pictureModel)); }
public async Task <IActionResult> Create([Bind("Id,Score,FaceId,Type")] EmotionModel emotionModel) { if (ModelState.IsValid) { _context.Add(emotionModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FaceId"] = new SelectList(_context.Faces, "Id", "Id", emotionModel.FaceId); return(View(emotionModel)); }
public async Task <IActionResult> Create([Bind("Id,PictureId,Top,Left,Width,Height")] FaceModel faceModel) { if (ModelState.IsValid) { _context.Add(faceModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PictureId"] = new SelectList(_context.Pictures, "Id", "Id", faceModel.PictureId); return(View(faceModel)); }
public async Task <IActionResult> Index(IFormFile file) { if (file?.Length > 0) { string folderPath = _config.GetValue <string>("UploadImageDirectory"); var pictureName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName).ToLower(); string webRootPath = _webHostEnvironment.WebRootPath; string route = Path.Combine(webRootPath, folderPath, pictureName); using (var stream = new FileStream(route, FileMode.Create)) { await file.CopyToAsync(stream); } using (var fs = new FileStream(route, FileMode.Open)) { var picture = await _faceHelper.DetectAndExtractFaceAsync(fs); using (var image = Image.FromStream(file.OpenReadStream())) { picture.Width = image.Width; picture.Height = image.Height; } picture.Name = file.FileName; picture.Path = $"{folderPath}/{pictureName}"; _context.Pictures.Add(picture); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Pictures", new { Id = picture.Id })); } } return(View()); }