예제 #1
0
        public IActionResult Create(Customer customer, IFormFile postedFile)
        {
            if (postedFile != null && postedFile.Length > 0) //arquivo não está vazio
            {
                string wwwPath     = this.Environment.WebRootPath;
                string contentPath = this.Environment.ContentRootPath;

                string path = Path.Combine(this.Environment.WebRootPath, "Uploads");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string fileName = Path.GetFileName(postedFile.FileName);
                using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Create))
                {
                    postedFile.CopyTo(stream);
                    customer.Picture = fileName;
                }
            }
            DAL.AppContext appContext = new DAL.AppContext();
            customer.Salt = Guid.NewGuid().ToString();
            customer.Hash = Util.Cryptography.CreateMD5(customer.Hash + customer.Salt);
            appContext.Customers.Add(customer);
            appContext.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
예제 #2
0
 public void Save()
 {
     context.SaveChanges();
 }