public void SaveVolenteer(Volenteer volenteer) { if (volenteer.ID == 0) { context.Volenteers.Add(volenteer); } else { Volenteer dbEntry = context.Volenteers .FirstOrDefault(v => v.ID == volenteer.ID); if (dbEntry != null) { dbEntry.FirstName = volenteer.FirstName; dbEntry.LastName = volenteer.LastName; dbEntry.UserName = volenteer.UserName; dbEntry.Password = volenteer.Password; dbEntry.Center = volenteer.Center; dbEntry.Skills = volenteer.Skills; dbEntry.Availalibity = volenteer.Availalibity; dbEntry.Address = volenteer.Address; dbEntry.Phone = volenteer.Phone; dbEntry.Email = volenteer.Email; dbEntry.Education = volenteer.Education; dbEntry.Lincense = volenteer.Lincense; dbEntry.EmergencyContact = volenteer.EmergencyContact; dbEntry.EmergencyPhone = volenteer.EmergencyPhone; dbEntry.EmergencyEmail = volenteer.EmergencyEmail; dbEntry.EmergencyAddress = volenteer.EmergencyAddress; dbEntry.Drivers = volenteer.Drivers; dbEntry.Ssn = volenteer.Ssn; dbEntry.ApprovalStatus = volenteer.ApprovalStatus; } } context.SaveChanges(); }
public Volenteer DeleteVolenteer(int ID) { Volenteer dbEntry = context.Volenteers.FirstOrDefault(v => v.ID == ID); if (dbEntry != null) { context.Volenteers.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public static void EnsurePopulated(IApplicationBuilder app) { ApplicationDbContext context = app.ApplicationServices .GetRequiredService <ApplicationDbContext>(); if (!context.Volenteers.Any()) { StartingData startingData = new StartingData(); Volenteer volenteers; Volenteer[] volenteersList = new Volenteer[30]; for (int index = 0; index < 30; index = index + 1) { volenteers = new Volenteer { FirstName = startingData.GetFirstName(index), LastName = startingData.GetLastName(index), UserName = startingData.GetUserName(index), Password = startingData.GetPassword(index), Center = startingData.GetCenter(index), Skills = startingData.GetSkills(index), Availalibity = startingData.GetAvailalibity(index), Address = startingData.GetAddress(index), Phone = startingData.GetPhone(index), Email = startingData.GetEmail(index), Education = startingData.GetEducation(index), Lincense = startingData.GetLincense(index), EmergencyContact = startingData.GetEmergencyContact(index), EmergencyPhone = startingData.GetEmergencyPhone(index), EmergencyEmail = startingData.GetEmergencyEmail(index), EmergencyAddress = startingData.GetEmergencyAddress(index), Drivers = startingData.GetDrivers(index), Ssn = startingData.GetSsn(index), ApprovalStatus = startingData.GetApprovalStatus(index) }; volenteersList[index] = volenteers; } context.Volenteers.AddRange(volenteersList); context.SaveChanges(); } }