public async Task <IActionResult> Create([Bind("Id,RestaurantGoerId,RestaurantId,Time,MaxMembers,Isopen,AllCommitted")] PlateTime plateTime) { int resGoerId = await roleRepo.GetCurrentRestrauntGoerId(await GetCurrentUserAsync()); if (resGoerId != 0) { plateTime.RestaurantGoerId = resGoerId; } int resId = await roleRepo.GetCurrentRestrauntId(await GetCurrentUserAsync()); if (resId != 0) { plateTime.RestaurantId = resId; plateTime.RestaurantGoerId = null; } if (ModelState.IsValid) { ptRepo.CreateNewPlateTime(plateTime); return(RedirectToAction(nameof(Index))); } ViewBag.ErrorMessage = "Please make sure all fields have valid entries."; ViewData["RestaurantId"] = new SelectList(_context.Restaurant, "Id", "Name", plateTime.RestaurantId); ViewData["RestaurantGoerId"] = new SelectList(_context.RestaurantGoer, "Id", "Name", resGoerId); return(View(plateTime)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } PlateTime plateTime = await ptRepo.GetCurrentPlateTime(id); if (plateTime == null) { return(NotFound()); } if (plateTime.RestaurantGoerId != await roleRepo.GetCurrentRestrauntGoerId(await GetCurrentUserAsync()) && plateTime.RestaurantId != await roleRepo.GetCurrentRestrauntId(await GetCurrentUserAsync())) { return(NotFound()); } int resId = 0; resId = await roleRepo.GetCurrentRestrauntId(await GetCurrentUserAsync()); if (resId != 0) { ViewBag.isRestaurant = true; } List <SelectListItem> tfList = new List <SelectListItem>(); tfList.Add(new SelectListItem { Text = "Open", Value = true.ToString() }); tfList.Add(new SelectListItem { Text = "Closed", Value = false.ToString() }); ViewData["TrueFalse"] = tfList; ViewData["RestaurantId"] = new SelectList(_context.Restaurant, "Id", "Name", plateTime.RestaurantId); ViewData["RestaurantGoerId"] = new SelectList(_context.RestaurantGoer, "Id", "Name", plateTime.RestaurantGoerId); return(View(plateTime)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,RestaurantGoerId,RestaurantId,Time,MaxMembers,Isopen,AllCommitted")] PlateTime plateTime) { if (id != plateTime.Id) { return(NotFound()); } int resGoerId = await roleRepo.GetCurrentRestrauntGoerId(await GetCurrentUserAsync()); if (resGoerId != 0) { plateTime.RestaurantGoerId = resGoerId; } if (ModelState.IsValid) { try { await ptRepo.UpdateEntry(plateTime); } catch (DbUpdateConcurrencyException) { if (!ptRepo.PlateTimeExists(plateTime.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["RestaurantId"] = new SelectList(_context.Restaurant, "Id", "Name", plateTime.RestaurantId); ViewData["RestaurantGoerId"] = new SelectList(_context.RestaurantGoer, "Id", "Name", plateTime.RestaurantGoerId); return(View(plateTime)); }
public void CreateNewPlateTime(PlateTime plateTime) { db.Add(plateTime); db.SaveChanges(); }
public async Task UpdateEntry(PlateTime pt) { db.Update(pt); await db.SaveChangesAsync(); }