public async Task <ActionResult> ShowRecension(Guid rezervacija) { ApplicationDbContext dbCtx = ApplicationDbContext.Create(); Ticket rezKarta = dbCtx.Reservations.Include(x => x.Projection).FirstOrDefault(x => x.Id == rezervacija); HallTimeProjection projekcija = dbCtx.HallTimeProjection.Include(x => x.Projection).FirstOrDefault(x => x.Id == rezKarta.Projection.Id); string id = User.Identity.GetUserId(); Guid idproj = projekcija.Projection.Id; List <Recension> recenzije = dbCtx.Recensions.ToList(); foreach (Recension r in recenzije) { Recension re = dbCtx.Recensions.Include(x => x.RecensionUser).FirstOrDefault(x => x.Id == r.Id); if (re.projection != null) { if (re.projection.Id.Equals(idproj) && re.RecensionUser.Id.Equals(id)) { return(View("AlreadyGaveRecensionProjection", r)); } } } return(View("ShowRecension", projekcija.Projection)); }
public async Task <ActionResult> DeleteFastReserveTicket(Guid projekcija) { ApplicationDbContext dbCtx = ApplicationDbContext.Create(); string id = User.Identity.GetUserId(); var projection = dbCtx.Database.SqlQuery <Projection>("select * from Projections where Id = '" + projekcija + "'").FirstOrDefault(); var projWithHalls = await dbCtx.Projections.Include(x => x.ProjHallsTimeList).FirstOrDefaultAsync(x => x.Id == projekcija); List <Ticket> tickets = new List <Ticket>(); foreach (HallTimeProjection h in projWithHalls.ProjHallsTimeList) { HallTimeProjection htp = new HallTimeProjection(); var reservations = dbCtx.Database.SqlQuery <Ticket>("select * from Tickets where ApplicationUser_Id = '" + id + "' and Projection_Id = '" + h.Id + "'").ToList(); foreach (Ticket res in reservations) { Ticket tic = new Ticket(); tic = dbCtx.Reservations.Include(x => x.Projection).FirstOrDefault(x => x.Id == res.Id); htp = dbCtx.HallTimeProjection.Include(x => x.Hall).FirstOrDefault(x => x.Id == tic.Projection.Id); tic.Projection = htp; tickets.Add(tic); } } dbCtx.SaveChanges(); ViewBag.projekcija = projekcija; return(View("DeleteFastReserveTicket", tickets)); }
public ActionResult EditProjection(Guid idProj) { List <Projection> allProjections = new List <Projection>(); ApplicationDbContext dbCtx = ApplicationDbContext.Create(); allProjections = dbCtx.Projections.ToList(); Projection projectionForEdit = new Projection(); foreach (Projection p in allProjections) { if (p.Id.Equals(idProj)) { projectionForEdit = p; } } var projHalls = new List <HallTimeProjection>(); Projection proj = new Projection(); proj = dbCtx.Projections.Include(x => x.ProjHallsTimeList).FirstOrDefault(x => x.Id == projectionForEdit.Id); foreach (HallTimeProjection htp in proj.ProjHallsTimeList) { HallTimeProjection projHall = new HallTimeProjection(); projHall = dbCtx.HallTimeProjection.Include(x => x.Hall).FirstOrDefault(x => x.Id == htp.Id); projHall = dbCtx.HallTimeProjection.Include(x => x.Seats).FirstOrDefault(x => x.Id == htp.Id); projHalls.Add(projHall); } proj.ProjHallsTimeList = projHalls; return(View("ChangeProjection", proj)); }
public ActionResult ViewRepertoar(Guid locationId) { ApplicationDbContext dbCtx = ApplicationDbContext.Create(); var locationToShow = new Location(); var projections = dbCtx.Database.SqlQuery <Projection>("select * from Projections where Location_Id = '" + locationId + "'").ToList(); List <Location> allLocations = new List <Location>(); allLocations = dbCtx.Locations.ToList(); foreach (Location loc in allLocations) { if (loc.Id.Equals(locationId)) { locationToShow = loc; break; } } var projs = new List <Projection>(); var projHalls = new List <HallTimeProjection>(); List <int> freeSeats = new List <int>(); foreach (Projection p in projections) { Projection proj = new Projection(); proj = dbCtx.Projections.Include(x => x.ProjHallsTimeList).FirstOrDefault(x => x.Id == p.Id); foreach (HallTimeProjection htp in proj.ProjHallsTimeList) { HallTimeProjection projHall = new HallTimeProjection(); projHall = dbCtx.HallTimeProjection.Include(x => x.Hall).FirstOrDefault(x => x.Id == htp.Id); projHall = dbCtx.HallTimeProjection.Include(x => x.Seats).FirstOrDefault(x => x.Id == htp.Id); int brojac = 0; for (int i = 0; i < projHall.Seats.Count; i++) { brojac += projHall.Seats[i].Seats.Count(f => f == 'e'); } freeSeats.Add(brojac); projHalls.Add(projHall); } proj.ProjHallsTimeList = projHalls; projs.Add(proj); projHalls = new List <HallTimeProjection>(); } string id = User.Identity.GetUserId(); ViewBag.user = id; locationToShow.ProjectionsList = projs; LocationWithNumberOfSeats locationWithSeats = new LocationWithNumberOfSeats { location = locationToShow, NumberOfFreeSeats = freeSeats }; return(View("ShowRepertoar", locationWithSeats)); }
public async Task <ActionResult> ShowIncome(GraphicViewModel model) { ApplicationDbContext ctx = ApplicationDbContext.Create(); string id = User.Identity.GetUserId(); var locationToShow = new Location(); var locationId = ctx.Database.SqlQuery <String>("select MyLocationId from AspNetUsers where id = '" + id + "'").FirstOrDefault(); Guid idLoc = new Guid(locationId); List <Location> allLocations = new List <Location>(); var projections = ctx.Database.SqlQuery <Projection>("select * from Projections where Location_Id = '" + idLoc + "'").ToList(); allLocations = ctx.Locations.ToList(); foreach (Location loc in allLocations) { if (loc.Id.Equals(locationId)) { locationToShow = loc; } } locationToShow.ProjectionsList = projections; List <Ticket> tickets = new List <Ticket>(); List <Ticket> ticketsToCalculate = new List <Ticket>(); tickets = ctx.Reservations.ToList(); Ticket ticket = new Ticket(); string time = "00:00 PM"; string vreme1 = model.DatumOd + " " + time; DateTime datum1 = DateTime.Parse(vreme1); string vreme2 = model.DatumDo + " " + time; DateTime datum2 = DateTime.Parse(vreme2); foreach (Ticket t in tickets) { ticket = await ctx.Reservations.Include(x => x.Projection).FirstOrDefaultAsync(x => x.Id == t.Id); HallTimeProjection pr = new HallTimeProjection(); pr = await ctx.HallTimeProjection.Include(x => x.Hall).FirstOrDefaultAsync(x => x.Id == ticket.Projection.Id); if (pr.Hall.ParentLocation.Id.Equals(new Guid(locationId)) && DateTime.Compare(pr.Time, datum1) > 0 && DateTime.Compare(pr.Time, datum2) < 0) { ticketsToCalculate.Add(ticket); } } double prihod = 0; foreach (Ticket t in ticketsToCalculate) { prihod += t.Price * t.DiscountMultiplier; } ViewBag.prihod = prihod; return(await ShowStatistics()); }
public async Task <ActionResult> AddFastReserveTicket(Guid projekcija) { ApplicationDbContext dbCtx = ApplicationDbContext.Create(); var projection = dbCtx.Database.SqlQuery <Projection>("select * from Projections where Id = '" + projekcija + "'").FirstOrDefault(); var projWithHalls = await dbCtx.Projections.Include(x => x.ProjHallsTimeList).FirstOrDefaultAsync(x => x.Id == projekcija); var projHalls = new List <HallTimeProjection>(); foreach (HallTimeProjection htp in projWithHalls.ProjHallsTimeList) { HallTimeProjection projHall = new HallTimeProjection(); projHall = dbCtx.HallTimeProjection.Include(x => x.Hall).FirstOrDefault(x => x.Id == htp.Id); projHalls.Add(projHall); } projWithHalls.ProjHallsTimeList = projHalls; return(View("FastReserveTicket", projWithHalls)); }
public async Task <ActionResult> CallFriends(string logUser, int brRezKarata, Guid idProjekcije) { ApplicationDbContext dbCtx = ApplicationDbContext.Create(); var userWithRes = dbCtx.Users.Include(x => x.ReservationsList).FirstOrDefault(x => x.Id == logUser); var userWithFriends = dbCtx.Users.Include(x => x.FriendList).FirstOrDefault(x => x.Id == userWithRes.Id); HallTimeProjection projectionWithHall = new HallTimeProjection(); var mama = await dbCtx.HallTimeProjection.Include(x => x.Seats).FirstOrDefaultAsync(x => x.Id == idProjekcije); var saHalom = await dbCtx.HallTimeProjection.Include(x => x.Hall).FirstOrDefaultAsync(x => x.Id == mama.Id); var saProjekcijom = await dbCtx.HallTimeProjection.Include(x => x.Projection).FirstOrDefaultAsync(x => x.Id == mama.Id); CallFriendsViewModel model = new CallFriendsViewModel { user = userWithFriends, brKarata = brRezKarata, projectionHallTime = saProjekcijom }; return(View("CallFriends", model)); }
public async Task <ActionResult> ViewReservation(Guid projectionId, Guid projHall) { ApplicationDbContext dbCtx = ApplicationDbContext.Create(); List <HallTimeProjection> timeProjections = new List <HallTimeProjection>(); HallTimeProjection hallTimeProj = new HallTimeProjection(); foreach (HallTimeProjection htp in timeProjections) { if (htp.Id.Equals(projHall)) { hallTimeProj = htp; break; } } // rezervacija sa halom i sedistima var mama = await dbCtx.HallTimeProjection.Include(x => x.Seats).FirstOrDefaultAsync(x => x.Id == projHall); var saHalom = await dbCtx.HallTimeProjection.Include(x => x.Hall).FirstOrDefaultAsync(x => x.Id == mama.Id); var saProjekcijom = await dbCtx.HallTimeProjection.Include(x => x.Projection).FirstOrDefaultAsync(x => x.Id == mama.Id); return(View("Seats", saProjekcijom)); }
public async Task <ActionResult> ShowStatistics() { ApplicationDbContext ctx = ApplicationDbContext.Create(); string id = User.Identity.GetUserId(); var locationToShow = new Location(); var locationId = ctx.Database.SqlQuery <String>("select MyLocationId from AspNetUsers where id = '" + id + "'").FirstOrDefault(); Guid idLoc = new Guid(locationId); List <Location> allLocations = new List <Location>(); var projections = ctx.Database.SqlQuery <Projection>("select * from Projections where Location_Id = '" + idLoc + "'").ToList(); allLocations = ctx.Locations.ToList(); foreach (Location loc in allLocations) { if (loc.Id.Equals(locationId)) { locationToShow = loc; } } locationToShow.ProjectionsList = projections; List <Ticket> tickets = new List <Ticket>(); List <Ticket> ticketsToCalculate = new List <Ticket>(); tickets = ctx.Reservations.ToList(); Ticket ticket = new Ticket(); foreach (Ticket t in tickets) { ticket = await ctx.Reservations.Include(x => x.Projection).FirstOrDefaultAsync(x => x.Id == t.Id); HallTimeProjection pr = new HallTimeProjection(); pr = await ctx.HallTimeProjection.Include(x => x.Hall).FirstOrDefaultAsync(x => x.Id == ticket.Projection.Id); if (pr.Hall.ParentLocation.Id.Equals(new Guid(locationId))) { ticketsToCalculate.Add(ticket); } } List <Pair> parovi = new List <Pair>(); foreach (Ticket t in ticketsToCalculate) { Pair par = new Pair(); par.date = t.Projection.Time.ToString(); par.date = par.date.Split(' ')[0]; DateTime dt = DateTime.Now; int trenutnidan = dt.DayOfYear; int trenutnagod = dt.Year; par.numberofday = t.Projection.Time.DayOfYear; par.year = t.Projection.Time.Year; par.number = 0; if (t.Projection.Time.DayOfYear < 105) { int k = 8; } int ima = 1; for (int i = 0; i < parovi.Count; i++) { if (parovi[i].numberofday.Equals(par.numberofday) && parovi[i].year.Equals(par.year) && trenutnidan - par.numberofday < 7 && trenutnagod - par.year == 0) { ima = 0; } } if (ima == 1) { if (trenutnidan - par.numberofday < 7) { parovi.Insert(0, par); } } ima = 1; } foreach (Ticket t in ticketsToCalculate) { for (int i = 0; i < parovi.Count; i++) { if (t.Projection.Time.DayOfYear.Equals(parovi[i].numberofday) && t.Projection.Time.Year.Equals(parovi[i].year)) { parovi[i].number++; break; } } } List <Pair> nedeljno = new List <Pair>(); int b = 0; for (int i = 0; i < 12; i++) { Pair par = new Pair(); int p = b + 2; par.date = b + "-" + p; par.number = 0; DateTime now = DateTime.Now; par.year = now.Year; par.numberofday = now.DayOfYear; nedeljno.Add(par); b += 2; } foreach (Ticket t in ticketsToCalculate) { for (int i = 0; i < nedeljno.Count; i++) { if (t.Projection.Time.DayOfYear.Equals(nedeljno[i].numberofday) && t.Projection.Time.Year.Equals(nedeljno[i].year)) { int donja = 44; int.TryParse(nedeljno[i].date.Split('-')[0], out donja); int gornja = 44; int.TryParse(nedeljno[i].date.Split('-')[1], out gornja); if (t.Projection.Time.Hour >= donja && t.Projection.Time.Hour < gornja) { nedeljno[i].number++; break; } } } } List <Pair2> mesecno = new List <Pair2>(); foreach (Ticket t in ticketsToCalculate) { Pair2 par = new Pair2(); par.date = t.Projection.Time.ToString(); par.date = par.date.Split(' ')[0]; DateTime dt = DateTime.Now; int trenutnidan = dt.DayOfYear; int trenutnagod = dt.Year; par.numberofday = t.Projection.Time.DayOfYear; par.numberofmonth = t.Projection.Time.Month; int trenutnimesec = dt.Month; par.year = t.Projection.Time.Year; par.number = 0; int ima = 1; for (int i = 0; i < mesecno.Count; i++) { if (mesecno[i].numberofday.Equals(par.numberofday) && mesecno[i].year.Equals(par.year) && trenutnimesec - par.numberofmonth == 0 && trenutnagod - par.year == 0) { ima = 0; } } if (ima == 1) { if (trenutnimesec - par.numberofmonth == 0) { mesecno.Insert(0, par); } } ima = 1; } foreach (Ticket t in ticketsToCalculate) { for (int i = 0; i < mesecno.Count; i++) { if (t.Projection.Time.DayOfYear.Equals(mesecno[i].numberofday) && t.Projection.Time.Year.Equals(mesecno[i].year)) { mesecno[i].number++; break; } } } GraphicViewModel graph = new GraphicViewModel { loc = locationToShow, pairs = parovi, nedeljni = nedeljno, mesecni = mesecno }; if (ViewBag.prihod == null) { ViewBag.prihod = 0; } return(View("ShowStatistics", graph)); }
public async Task <ActionResult> HallTimeSubmit(Models.HallTimeViewModel model, Guid MyLocation, Guid projekcija) { List <SelectListItem> items = new List <SelectListItem>(); ApplicationDbContext dbCtx = ApplicationDbContext.Create(); var location = await dbCtx.Locations.Include(x => x.HallsList).FirstOrDefaultAsync(x => x.Id == MyLocation); if (model.TicketPrice <= 0) { List <string> halls = new List <string>(); foreach (Hall h1 in location.HallsList) { items.Add(new SelectListItem { Text = h1.Name }); halls.Add(h1.Name); } model.Hale = halls; ViewBag.projekcija = projekcija; ViewBag.location = MyLocation; ViewBag.Halls = items; ModelState.AddModelError("", "Ticket price can't be 0 or less than 0."); ViewBag.location = MyLocation; return(View("AddHallTimeProjection", model)); } Hall h = new Hall(); h = location.HallsList[0]; var rows = h.RowsCount; var columns = h.ColsCount; string imehale = model.Hall; foreach (Hall hall in location.HallsList) { if (hall.Name.Equals(imehale)) { h = hall; } } var hallWithSeats = await dbCtx.Halls.Include(x => x.Seats).FirstOrDefaultAsync(x => x.Id == h.Id); List <Row> seats = new List <Row>(); string konfiguracija = ""; for (int br = 0; br < hallWithSeats.RowsCount; br++) { Row row = new Models.Row(); for (int br2 = 0; br2 < hallWithSeats.Seats[br].Seats.Length; br2++) { konfiguracija += hallWithSeats.Seats[br].Seats[br2]; } row.Seats = konfiguracija; seats.Add(row); dbCtx.Rows.Add(row); konfiguracija = ""; } string date = model.Date; string time = model.Time; string datetime = date + " " + time; /*List<Row> seats = new List<Row>(); * * string praznic = ""; * for(int i = 0; i< rows; i++) * { * Row row = new Row(); * for (int j = 0; j< columns; j++) * { * praznic += "e"; * * } * row.Seats = praznic; * seats.Add(row); * dbCtx.Rows.Add(row); * praznic = ""; * }*/ DateTime datum = DateTime.Parse(datetime); var projection = await dbCtx.Projections.Include(x => x.ProjHallsTimeList).FirstOrDefaultAsync(x => x.Id == projekcija); HallTimeProjection ToAdd = new HallTimeProjection { Hall = h, Time = datum, Seats = seats, Projection = projection, TicketPrice = model.TicketPrice }; projection.ProjHallsTimeList.Add(ToAdd); dbCtx.HallTimeProjection.Add(ToAdd); dbCtx.SaveChanges(); var mama = await dbCtx.HallTimeProjection.Include(x => x.Seats).FirstOrDefaultAsync(x => x.Id == x.Id); ViewBag.location = MyLocation; List <Projection> allProjections = new List <Projection>(); allProjections = dbCtx.Projections.ToList(); Projection projectionForEdit = new Projection(); foreach (Projection p in allProjections) { if (p.Id.Equals(projekcija)) { projectionForEdit = p; } } var projHalls = new List <HallTimeProjection>(); Projection proj = new Projection(); proj = dbCtx.Projections.Include(x => x.ProjHallsTimeList).FirstOrDefault(x => x.Id == projectionForEdit.Id); foreach (HallTimeProjection htp in proj.ProjHallsTimeList) { HallTimeProjection projHall = new HallTimeProjection(); projHall = dbCtx.HallTimeProjection.Include(x => x.Hall).FirstOrDefault(x => x.Id == htp.Id); projHall = dbCtx.HallTimeProjection.Include(x => x.Seats).FirstOrDefault(x => x.Id == htp.Id); projHalls.Add(projHall); } proj.ProjHallsTimeList = projHalls; return(View("../Location/ChangeProjection", proj)); }