public ActionResult Create(Movie c) { c.Picture = "~/UploadedFiles/" + c.Picture.ToString(); using (MovieDal mdb = new MovieDal()) { foreach (Movie movie in mdb.Movies.ToList <Movie>()) { if (movie.Hall == c.Hall && DateTime.Compare(movie.Date, c.Date) == 0) { ViewBag.x = "This DateTime and Hall is choosen allready !"; return(View()); } } } try { using (MovieDal mdb = new MovieDal()) { mdb.Movies.Add(c); mdb.SaveChanges(); using (MostDal modb = new MostDal()) { if (modb.Mosts.ToList <Most>().Where(x => x.Title == c.Title).Count() == 0) { Most m = new Most(); m.Title = c.Title; modb.Mosts.Add(m); modb.SaveChanges(); } } } ViewBag.x = " Movie has been added Succecfully!"; return(RedirectToAction("Index", "User")); } catch { ViewBag.x = "Wrong input!"; return(View()); } }
void LadujMost() { int wys = 5; int szer = 5; foreach (DataRow m in twDataSet.pokazMosty.Rows) { float p = (float)(Convert.ToDouble(m["pozycja"].ToString())); string name = m["nazwa"].ToString(); int vmax = Convert.ToInt32(m["predkosc_max"].ToString()); int id = Convert.ToInt32(m["idmost"].ToString()); float kd = (float)(Convert.ToDouble(m["krancowa_dol"].ToString())); float kg = (float)(Convert.ToDouble(m["krancowa_gora"].ToString())); int przych = Convert.ToInt32(m["przychamowanie"].ToString()); if (szer < 700) { most = new Most(id, name, p, vmax, przych); most.Kg = kg; most.Kd = kd; most.Parent = panelMosty; most.Width = 225; most.Top = wys; most.Left = szer; szer += 230; if (szer == 925) { szer = 5; wys = 320; } } else { most = new Most(id, name, p, vmax, przych); most.Kg = kg; most.Kd = kd; most.Parent = panelMosty; most.Top = wys; most.Left = szer; szer += 230; } } }
public ActionResult seats(int id, Movie m, int seat = -1) { MovieDal mdb = new MovieDal(); Movie m1 = mdb.Movies.ToList <Movie>().Where(x => x.mid == id).FirstOrDefault(); //out of range seats HallDal hd = new HallDal(); Hall h = hd.Halls.ToList <Hall>().Where(x => x.HallNumber == m1.Hall).FirstOrDefault(); if (h.number_of_seats < seat || seat < 1) { ViewBag.check = "Out of range seat! , please choose a seat from 1 to " + h.number_of_seats.ToString(); return(View(m1)); } //check if the seat is in occupied TicketDal tdb = new TicketDal(); List <Ticket> t = tdb.Tickets.ToList <Ticket>(); int count = 0; foreach (Ticket t1 in t) { if (t1.Seat == seat && t1.Hall == m1.Hall && t1.Date.Equals(m1.Date)) { count++; } } //create ticket if (count == 0) { Ticket tt = new Ticket(); tt.Hall = m1.Hall; if (m1.Sale == null) { tt.Price = m1.Price; } else { tt.Price = (int)m1.Sale; } tt.Id = m1.mid; tt.Movietitle = m1.Title; tt.Date = m1.Date; tt.Seat = seat; tt.Userid = (int)Session["idUser"]; tdb.Tickets.Add(tt); tdb.SaveChanges(); ViewBag.check = "added to cart succefully !"; //add rating to most popular MostDal ms = new MostDal(); Most most = ms.Mosts.ToList <Most>().Where(x => x.Title == m1.Title).FirstOrDefault(); most.rate += 1; ms.Entry(most).State = EntityState.Modified; ms.SaveChanges(); } else { ViewBag.check = "this seat in occupied !"; } return(View(m1)); }