public Show Add(Show show) { var addedShow = _context.Shows.Add(show); _context.SaveChanges(); return(addedShow.Entity); }
//admin related tasks public void add(string name, double price) { using (var db = new ShowContext()) { Show s = new Show { Name = name, Price = price }; db.Shows.Add(s); showsList.Add(s); db.SaveChanges(); } }
public ActionResult Post([FromBody] Movie movie) { if (movie == null) { return(BadRequest()); } else { _context.Movies.Add(movie); _context.SaveChanges(); return(Ok("success")); } }
public void delete(string name, double price) { using (var db = new ShowContext()) { Show s = new Show { Name = name, Price = price }; var oldShow = from b in db.Shows where b.Name == name select b; if (avShow.ShowID != oldShow.First().ShowID) { db.Shows.Remove((Show)oldShow.First()); db.SaveChanges(); showsList = db.Shows.ToList(); } else { MessageBox.Show("Cannot delete the current available show.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void Create(Show show) { db.Add(show); db.SaveChanges(); }
static void Main(string[] args) { using (var context = new ShowContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var Show1 = new Show { Name = "Lions Show", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(30) }; var Show2 = new Show { Name = "Elephants Show", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(30) }; var Show3 = new Show { Name = "Monkeys Show", StartDate = DateTime.Now.AddDays(15), EndDate = DateTime.Now.AddDays(45) }; var Show4 = new Show { Name = "Parrots Show", StartDate = DateTime.Now.AddDays(15), EndDate = DateTime.Now.AddDays(45) }; var Show5 = new Show { Name = "Acrobats Show", StartDate = DateTime.Now.AddDays(30), EndDate = DateTime.Now.AddDays(60) }; var Show6 = new Show { Name = "Jugglers Show", StartDate = DateTime.Now.AddDays(30), EndDate = DateTime.Now.AddDays(60) }; List <Show> showList = new List <Show>(); showList.Add(Show1); showList.Add(Show2); showList.Add(Show3); showList.Add(Show4); showList.Add(Show5); showList.Add(Show6); List <Room> roomList = GenerateRoom(2); context.AddRange(roomList); List <Person> personList = new List <Person>(); var manyPersons = (from i in Enumerable.Range(0, 3) select new Person { Name = "Bob" + i, Password = "******" }).ToList(); personList.AddRange(manyPersons); var manyPersons2 = (from i in Enumerable.Range(0, 3) select new Person { Name = "Emy" + i, Password = "******" }).ToList(); personList.AddRange(manyPersons2); context.AddRange(personList); List <Presentation> presList = new List <Presentation>(); for (int i = 0; i < showList.Count(); i++) { if (i % 2 == 0) { showList[i].Presentations = GeneratePresentation(showList[i], 6, roomList[0]); presList.AddRange(showList[i].Presentations); } else { showList[i].Presentations = GeneratePresentation(showList[i], 6, roomList[1]); presList.AddRange(showList[i].Presentations); } } Random random = new Random(); List <Order> orderList = new List <Order>(); foreach (Person person in personList) { int numberRdm = random.Next(0, 35); int numberRdm2 = random.Next(1, 5); List <Order> orderList1 = GenerateOrder(person, 6, numberRdm2); orderList.AddRange(orderList1); } for (int i = 0; i < orderList.Count; i++) { orderList[i].Presentation = presList[i]; } context.AddRange(orderList); for (int i = 0; i < presList.Count; i++) { presList[i].Orders.Add(orderList[i]); } context.AddRange(presList); context.AddRange(showList); context.SaveChanges(); } }