public async Task <IActionResult> Index(IFormFile postedFile) { using (var reader = new StreamReader(postedFile.OpenReadStream())) { CsvReader csvReader = new CsvReader(reader); csvReader.Configuration.MissingFieldFound = null; csvReader.Configuration.HeaderValidated = null; csvReader.Configuration.BadDataFound = null; IEnumerable <Organization> records = csvReader.GetRecords <Organization>(); foreach (Organization organization in records) { _context.Add(organization); } } await _context.SaveChangesAsync(); return(View(await _context.Organizations.ToListAsync())); }
public async Task <IActionResult> Create([Bind("Id,Name")] VolunteerType volunteerType) { if (ModelState.IsValid) { _context.Add(volunteerType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(volunteerType)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create(OpportunityView opportunityView) { if (ModelState.IsValid) { Opportunity newOpportunity = new Opportunity() { Name = opportunityView.Name, Description = opportunityView.Description, SkillRequired = _context.Skills.Find(opportunityView.SkillRequiredId), Category = _context.Categories.Find(opportunityView.CategoryId), Organization = _context.Organizations.Find(opportunityView.OrganizationId), VolunteerType = _context.VolunteerTypes.Find(opportunityView.VolunteerTypeId), DateTime = opportunityView.DateTime }; _context.Add(newOpportunity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(opportunityView)); }