Create(String Title, String CreateDate, IFormFile ImagePath, String Description) { News news = new News(); //CultureInfo culture = new CultureInfo("en-US"); DateTime createdDate = DateTime.Parse(CreateDate); news.Title = Title; news.CreateDate = createdDate; news.Description = Description; string upLoadFolder = Path.Combine(hostingEnviroment.WebRootPath, "images"); var uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(ImagePath.FileName); string filePath = Path.Combine(upLoadFolder, uniqueFileName); news.ImagePath = "/images/" + uniqueFileName; using (var stream = System.IO.File.Create(filePath)) { await ImagePath.CopyToAsync(stream); } if (ModelState.IsValid) { _context.Add(news); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(news)); }
//public List<Student> GetStudents() //{ // using (GlobalDBContext dBContext = new GlobalDBContext()) // { // return dBContext.Student().ToList(); // } //} public void Write(string name, string lastname, string address, string phone) { using (GlobalDBContext dBContext = new GlobalDBContext()) { Student student = new Student() { Name = name, LastName = lastname, Address = address, Phone = phone }; dBContext.Add(student); dBContext.SaveChanges(); } }