public async Task <IActionResult> PutActivityBooking(int id, ActivityBooking activityBooking) { if (id != activityBooking.Id) { return(BadRequest()); } _context.Entry(activityBooking).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActivityBookingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> CreateActivityBooking(string name, int num, int aId) { System.Diagnostics.Debug.WriteLine("<-- CreateActivityBooking -->"); System.Diagnostics.Debug.WriteLine("name: " + name); System.Diagnostics.Debug.WriteLine("num: " + num); System.Diagnostics.Debug.WriteLine("aId: " + aId); var newAB = new ActivityBooking(); newAB.CustomerName = name; newAB.NumParticipants = num; newAB.ActivityId = aId; var response = "<-- CreateActivityBooking was called -->"; /// Fungerar, MEN måste fixa så att när den får null att det inte crashar. // var s = RestHelper.PrintObjProps<ActivityBooking>(newAB); // System.Diagnostics.Debug.WriteLine($"<-- {s} -->"); await RestHelper.ApiCreate <ActivityBooking>("ActivityBookings/", newAB); return(Json(response)); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var user = await _userManager.FindByNameAsync(_userAccessor.GetCurrentUsername()); var booking = new ActivityBooking { ActivityBookingId = request.ActivityBookingId, BookingDate = DateTime.Now, ProductId = Guid.Parse(request.ProductId), ClientName = user != null ? user.UserName : request.ClientName, ActivityDate = DateTime.Parse(request.ActivityDate), Adults = request.Adults, Kids = request.Kids }; _context.ActivityBookings.Add(booking); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new System.Exception("Problem saving changes"); }
public async Task <ActionResult <ActivityBooking> > PostActivityBooking(ActivityBooking activityBooking) { var temp = _context.Activities.Find(activityBooking.ActivityId); activityBooking.Activity = temp; _context.ActivityBooking.Add(activityBooking); await _context.SaveChangesAsync(); return(CreatedAtAction("GetActivityBooking", new { id = activityBooking.Id }, activityBooking)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,CustomerName,NumParticipants,ActivityId")] ActivityBooking activityBooking) { _logger.LogInformation("<-- Returned to Edit/httppost-->"); if (id != activityBooking.Id) { return(NotFound()); } if (ModelState.IsValid) { await RestHelper.ApiEdit(api + id, activityBooking); return(RedirectToAction(nameof(Index))); } ViewData["ActivityId"] = new SelectList(_context.Activity, "Id", "Id", activityBooking.ActivityId); return(View(activityBooking)); }
public async Task <IActionResult> Edit(int?id) { var activityBooking = new ActivityBooking(); try { activityBooking = await RestHelper.ApiGet <ActivityBooking>(api, id); var acts = await RestHelper.ApiGet <Activity>("Activities/"); System.Diagnostics.Debug.WriteLine(acts); //_context går inte att använda då den inte har en koppling till databasen //ViewData["ActivityId"] = new SelectList(_context.Activity, "Id", "Id", activityBooking.ActivityId); ViewData["ActivityId"] = new SelectList(acts, "Id", "Description"); } catch (Exception e) { _logger.LogError("<-- Error was caught when getting object to be edited --> \n " + e); } return(View(activityBooking)); }
public async Task <IActionResult> Create([Bind("Id,CustomerName,NumParticipants,ActivityId")] ActivityBooking activityBooking) { await RestHelper.ApiCreate <ActivityBooking>(api, activityBooking); return(RedirectToAction("Index")); }