Ejemplo n.º 1
0
        private string UploadedFile(ReportCaseViewModel model)
        {
            string uniqueFileName = null;

            if (model.UploadPicture != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.UploadPicture.FileName);
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.UploadPicture.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ReportCase(ReportCaseViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model);

                Case myCase = new Case
                {
                    Description  = model.Description,
                    AccidentDate = model.AccidentDate,
                    CaseNumber   = model.CaseNumber,
                    //User = model.User,
                    Picture = uniqueFileName,
                    UserId  = model.UserId
                };

                _context.Add(myCase);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }