public IActionResult Invite(int id) { var x = (from d in _donorService.GetDonors() join e in _eventService.GetEventDonors() on d.Id equals e.DonorId where d.Id == e.DonorId && id == e.EventId select d).ToList(); ViewBag.Donors = _donorService.GetDonors().Except(x); ViewBag.EventInfo = _eventService.GetEvent(id); // Get the event information to be shown on invitation page ViewBag.InvitedDonor = (from d in _donorService.GetDonors() join e in _eventService.GetEventDonors() on d.Id equals e.DonorId where d.Id == e.DonorId && id == e.EventId select d).ToList(); return(View(_eventService.GetEvent(id))); // Return event to get the event information on the Invite page }
public IActionResult Import(IFormFile file) { string firstName; string lastName; string email; // Read all the lines from file using var reader = new StreamReader(file.OpenReadStream()); List <string> lines = new List <string>(); string line; while ((line = reader.ReadLine()) != null) { string[] column = line.Split(","); firstName = column[0]; lastName = column[1]; email = column[2]; var obj = (from d in _donorService.GetDonors() where d.FirstName == firstName && d.LastName == lastName && d.Email1 == email select d).FirstOrDefault(); if (obj == null) // If the donor DOES NOT exist in the database { var newDonor = new Donor { FirstName = firstName, LastName = lastName, Email1 = email, MemberSince = DateTime.Now }; _donorService.AddDonor(newDonor); _donorService.SaveChanges(); } else { continue; } } return(RedirectToAction("Index", "Home")); }