public async Task <ActionResult> IndexAsync(HttpPostedFileBase file)
        {
            //if(file != null && file.ContentLength > 0)
            if (file?.ContentLength > 0)
            {
                var pictureName = Guid.NewGuid().ToString();
                pictureName += Path.GetExtension(file.FileName);

                var route = Server.MapPath(serverFolderPath);

                route = route + "/" + pictureName;
                file.SaveAs(route);

                var emoPicture = await emoHelper.DetectAndExtractFacesAsync(file.InputStream);

                emoPicture.Name = file.FileName;
                //emoPicture.Path = serverFolderPath + "/" + pictureName;
                emoPicture.Path = $"{serverFolderPath}/{pictureName}";



                try {
                    db.EmoPictures.Add(emoPicture);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Details", "EmoPictures", new { Id = emoPicture.Id }));
                } catch (Exception ex)
                {
                    Console.Write(ex.StackTrace);
                }
            }

            return(View());
        }
        public async Task <ActionResult> IndexAsync(HttpPostedFileBase file)
        {
            if (file?.ContentLength > 0)
            {
                var pictureName = Guid.NewGuid().ToString();
                pictureName += Path.GetExtension(file.FileName);

                var route = Server.MapPath(serverFolderPath);//optiene la ruta absoluta de la carpeta
                if (!Directory.Exists(route))
                {
                    Directory.CreateDirectory(route);
                }
                route = route + "/" + pictureName;


                file.SaveAs(@route);

                var emoPicture = await emoHelper.DetectAndExtractFacesAsync(file.InputStream);

                emoPicture.Name = file.FileName;
                emoPicture.Path = $"{serverFolderPath}/{pictureName}";
                using (EmotionWebContext database = new EmotionWebContext())
                {
                    db.EmoPictures.Add(emoPicture);
                    await db.SaveChangesAsync();
                }


                return(RedirectToAction("Details", "EmoPictures", new { Id = emoPicture.Id }));
            }
            return(View());
        }
Beispiel #3
0
        public async Task <ActionResult> Index(HttpPostedFile file)
        {
            if (file?.ContentLength > 0)
            {
                var pictureName = Guid.NewGuid().ToString();
                pictureName += Path.GetExtension(file.FileName);

                var route = Server.MapPath(serverFolderPath);

                route = route + "/" + pictureName;

                file.SaveAs(route);

                var emoPicture = await emoHelper.DetectAndExtractFacesAsync(file.InputStream);

                emoPicture.Name = file.FileName;
                emoPicture.Path = serverFolderPath + "/" + pictureName;

                db.EmoPictures.Add(emoPicture);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "EmoPictures", new { Id = emoPicture.Id }));
            }
            return(View());
        }