public ActionResult CreateCompany(EditModel m) { EventDbContext db = new EventDbContext(); var company = db.GetCompanies().FirstOrDefault(x => x.EventId == m.SelectedEventId && x.Id == m.Company.Id); if (company == null) { var newCompany = new Company { Name = m.Company.Name, RegistryNumber = m.Company.RegistryNumber, NumberOfParticipants = m.Company.NumberOfParticipants, PaymentMethodId = m.SelectedPaymentMethodId, Info = m.Company.Info, EventId = m.SelectedEventId, RegisterDate = DateTime.Now, Active = true }; db.Companies.Add(newCompany); db.SaveChanges(); } else { var dbCompany = db.Companies.FirstOrDefault(x => x.EventId == m.SelectedEventId && x.Id == m.Company.Id); dbCompany.Name = m.Company.Name; dbCompany.RegistryNumber = m.Company.RegistryNumber; dbCompany.NumberOfParticipants = m.Company.NumberOfParticipants; dbCompany.PaymentMethodId = m.SelectedPaymentMethodId; dbCompany.Info = m.Company.Info; dbCompany.EventId = m.SelectedEventId; UpdateModel(dbCompany); db.SaveChanges(); } return(RedirectToAction("Participants", new { id = m.SelectedEventId })); }
public ActionResult DeactivateCompany(int id, int eventId) { EventDbContext db = new EventDbContext(); var xd = db.Companies; var y = db.GetCompanies(); var dbCompany = db.Companies.FirstOrDefault(x => x.Id == id && x.EventId == eventId); dbCompany.Active = false; UpdateModel(dbCompany); db.SaveChanges(); return(RedirectToAction("Participants", new { id = eventId })); }
public ActionResult Participants(int id) { var db = new EventDbContext(); m.PaymentMethods = db.GetPaymentMethods(); var events = db.GetEvents(); foreach (Event e in events) { if (e.Id == id) { m.SelectedEventId = id; m.Event = e; break; } } m.Companies = db.GetCompanies(); m.Persons = db.GetPersons(); m.Participants = new List <Participant>(); foreach (Company c in m.Companies) { if (c.Active == false || c.EventId != m.SelectedEventId) { continue; } Participant p = new Participant(); p.TypeName = "Company"; p.Name = c.Name; p.Number = c.RegistryNumber; p.RegisterDate = c.RegisterDate; p.ParticipantId = c.Id; m.Participants.Add(p); } foreach (Person n in m.Persons) { if (n.Active == false || n.EventId != m.SelectedEventId) { continue; } Participant p = new Participant(); p.TypeName = "Person"; p.Name = n.FirstName + " " + n.LastName; p.Number = n.PersonalCode; p.RegisterDate = n.RegisterDate; p.ParticipantId = n.Id; m.Participants.Add(p); } m.Participants = m.Participants.OrderByDescending(o => o.RegisterDate).ToList(); return(View(m)); }
public ActionResult CompanyEditor(int id, int eventId) { var db = new EventDbContext(); m.SelectedEventId = eventId; m.PaymentMethods = db.GetPaymentMethods(); foreach (Company c in db.GetCompanies()) { if (c.Id == id) { m.Company = c; m.Company.PaymentMethod = db.PaymentMethods.FirstOrDefault(x => x.Id == m.Company.PaymentMethodId); m.SelectedPaymentMethodId = m.Company.PaymentMethod.Id; break; } } return(View(m)); }