//on the index page, it makes it so it will "for each" x in the resturaunt it will add what we had created in the cs page to this form public IActionResult Index() { List <string> ResList = new List <string>(); foreach (Resturaunt r in Resturaunt.GetResturaunts()) { ResList.Add(string.Format($"Rank #{r.Rank}: {r.ResName}, {r.FavDish}, {r.ResPhone}, {r.Address}, {r.Link}")); } return(View(ResList)); }
public async Task <IActionResult> OnPostAsync() { int id = (int)HttpContext.Session.GetInt32("current_resturaunt"); Resturaunt R = await _context.Resturaunt.Include(m => m.ResturauntPage).ThenInclude(m => m.Days).FirstOrDefaultAsync(m => m.id == id); foreach (var i in R.ResturauntPage.Days) { _context.Entry(i) .Collection(s => s.Deals) .Load(); } var file = Request.Form.Files.First(); using (var reader = file.OpenReadStream()) { TextReader tr = new StreamReader(reader); using (var csv = new CsvReader(tr, CultureInfo.InvariantCulture)) { csv.Configuration.HasHeaderRecord = false; var deals = csv.GetRecords <CSVDeal>(); foreach (var d in deals) { Deal deal = new Deal() { ItemName = d.DealName, Desription = d.DealDescription, StartTime = d.StartTime, EndTime = d.EndTime }; _context.Deal.Add(deal); if (deal != null) { R.ResturauntPage.Days.Where(n => n.DayName.ToLower() == d.DayOfWeek.ToLower()).FirstOrDefault().Deals.Add(deal); } } _context.Attach(R).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { } } } return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Resturaunt = await _context.Resturaunt.FirstOrDefaultAsync(m => m.id == id); if (Resturaunt == null) { return(NotFound()); } return(Page()); }
public async Task OnGetAsync(int id) { Byte[] OutVal; if (!HttpContext.Session.TryGetValue("current_resturaunt", out OutVal)) { HttpContext.Session.SetInt32("current_resturaunt", id); } else { id = (int)HttpContext.Session.GetInt32("current_resturaunt"); } Resturaunt = await _context.Resturaunt.Include(m => m.ResturauntPage).FirstOrDefaultAsync(m => m.id == id); ResturauntPage = Resturaunt.ResturauntPage; }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Resturaunt = await _context.Resturaunt.FindAsync(id); if (Resturaunt != null) { _context.Resturaunt.Remove(Resturaunt); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Resturaunt = await _context.Resturaunt.Include(m => m.ResturauntPage).ThenInclude(m => m.Days).Include(m => m.ResturauntPage).ThenInclude(m => m.Image).FirstOrDefaultAsync(m => m.id == id); ResturauntPage = Resturaunt.ResturauntPage; Tags = await _context.Tags.Select(m => m).ToListAsync(); Day[] days = Resturaunt.ResturauntPage.Days.ToArray <Day>(); Deals = new List <Deal>(); for (int i = 0; i < days.Length; i++) { days[i] = await _context.Day.Include(d => d.Deals).FirstOrDefaultAsync(m => m.id == days[i].id); Deals.AddRange(days[i].Deals); } Monday = days[0]; Tuesday = days[1]; Wednesday = days[2]; Thursday = days[3]; Friday = days[4]; Saturday = days[5]; Sunday = days[6]; if (Resturaunt == null) { return(NotFound()); } if (ResturauntPage.Image.ImageVal != null) { Image img = ResturauntPage.Image; string imageBase64Data = Convert.ToBase64String(img.ImageVal); imageDataURL = string.Format("data:image/jpg;base64,{0}", imageBase64Data); } return(Page()); }
public async Task OnGetAsync(int id, int day) { Tags = new List <Tags>(); Byte[] OutVal; if (!HttpContext.Session.TryGetValue("current_resturaunt", out OutVal)) { HttpContext.Session.SetInt32("current_resturaunt", id); } else { id = (int)HttpContext.Session.GetInt32("current_resturaunt"); } Resturaunt R = await _context.Resturaunt.Include(m => m.ResturauntPage).ThenInclude(m => m.Days).FirstOrDefaultAsync(m => m.id == id); Tags = _context.Tags.ToList(); SelectedTags = new int[Tags.Count]; switch (day) { case 1: Day = await _context.Day.Include(m => m.Deals).FirstOrDefaultAsync(m => m.id == R.ResturauntPage.Days.ElementAt(0).id); Deals = Day.Deals; Day.DayName = "Monday"; break; case 2: Day = await _context.Day.Include(m => m.Deals).FirstOrDefaultAsync(m => m.id == R.ResturauntPage.Days.ElementAt(1).id); Deals = Day.Deals; Day.DayName = "Tuesday"; break; case 3: Day = await _context.Day.Include(m => m.Deals).FirstOrDefaultAsync(m => m.id == R.ResturauntPage.Days.ElementAt(2).id); Deals = Day.Deals; Day.DayName = "Wednesday"; break; case 4: Day = await _context.Day.Include(m => m.Deals).FirstOrDefaultAsync(m => m.id == R.ResturauntPage.Days.ElementAt(3).id); Deals = Day.Deals; Day.DayName = "Thursday"; break; case 5: Day = await _context.Day.Include(m => m.Deals).FirstOrDefaultAsync(m => m.id == R.ResturauntPage.Days.ElementAt(4).id); Deals = Day.Deals; Day.DayName = "Friday"; break; case 6: Day = await _context.Day.Include(m => m.Deals).FirstOrDefaultAsync(m => m.id == R.ResturauntPage.Days.ElementAt(5).id); Deals = Day.Deals; Day.DayName = "Saturday"; break; case 7: Day = await _context.Day.Include(m => m.Deals).FirstOrDefaultAsync(m => m.id == R.ResturauntPage.Days.ElementAt(6).id); Deals = Day.Deals; Day.DayName = "Sunday"; break; } //preperation for tags foreach (var x in Day.Deals) { _context.Entry(x) .Collection(s => s.TagsInter) .Load(); } }