コード例 #1
0
ファイル: EventsController.cs プロジェクト: ChesterSA/ThAmCo
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Duration")] EventEdit eventEdit)
        {
            if (id != @eventEdit.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                Event @event = _context.Events.Find(id);

                @event.Title    = eventEdit.Title;
                @event.Duration = eventEdit.Duration;

                try
                {
                    @event.IsActive = true;
                    _context.Update(@event);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventExists(@event.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(eventEdit));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Surname,FirstName,Email")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // Saves changes to the customer information to the database.
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //returns to the custome rlist.
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Surname,FirstName,Email")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _eventContext.Update(customer);
                    await _eventContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_eventContext.Customers.Any(e => e.Id == id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(CustomerIndex)));
            }
            return(View(customer));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int staffid, [Bind("StaffId,Surname,FirstName,Email,FirstAider")] Staff staff)
        {
            if (staffid != staff.StaffId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _eventContext.Update(staff);
                    await _eventContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_eventContext.Staff.Any(e => e.StaffId == staffid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(StaffIndex)));
            }
            return(View(staff));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Date,Duration,TypeId")] Event @event)
        {
            if (id != @event.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(@event);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventExists(@event.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }
コード例 #6
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var @event = await _context.Events.FindAsync(id);

            @event.isDeleted = false;

            _context.Guests.RemoveRange(_context.Guests.Where(g => g.EventId == id));
            _context.Staffing.RemoveRange(_context.Staffing.Where(g => g.EventId == id));

            HttpClient client = new HttpClient();

            client.BaseAddress = new System.Uri("http://localhost:23652");
            client.DefaultRequestHeaders.Accept.ParseAdd("application/json");

            HttpResponseMessage delete = await client.DeleteAsync("api/reservations/" + @event.Reference);

            @event.Reference = null;

            _context.Update(@event);

            //_context.Events.Remove(@event);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Surname,FirstName,FirstAider, Email")] Staff staff)
        {
            if (id != staff.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(staff);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffExists(staff.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(staff));
        }
コード例 #8
0
        public async Task <IActionResult> UpdateStaff(int id, [Bind("Id,Title,Date,Duration,TypeId,Staffing")] Event @event)
        {
            if (id != @event.Id)
            {
                return(NotFound());
            }
            var selectedValue = Request.Form["Staff"];

            var   staff  = _context.Staff.Where(m => m.Id == int.Parse(selectedValue[0].ToString())).ToList();
            Staff staff3 = await _context.Staff
                           .FirstOrDefaultAsync(m => m.Id == int.Parse(selectedValue[0].ToString()));


            @event.Staffing.Add(staff3);


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(@event);

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventExists(@event.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //Event result = await _context.Events.FirstOrDefaultAsync(m => m.Id == id);
                //if(result != null)
                //{
                //    result.Staffing.Add(staff3);
                //    _context.Entry(result).State = EntityState.Modified;
                //    _context.Events.Update(result);
                //    await _context.SaveChangesAsync();
                //}

                return(RedirectToAction(nameof(Index)));
            }



            return(RedirectToAction(nameof(Index)));
        }
コード例 #9
0
        public async Task <IActionResult> BookVenuePost([Bind("EventId,VenueCode,VenueName")] VenuesViewModel postVenue)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var @event = await _dataAccess.GetEvents().FirstOrDefaultAsync(e => e.Id == postVenue.EventId);

                    if (@event == null)
                    {
                        return(NotFound());
                    }

                    if (@event.ReservationRef != null)
                    {
                        var r = await _venuesClient.DeleteReservation(@event);
                    }

                    ReservationPostDto postReservation = new ReservationPostDto
                    {
                        VenueCode = postVenue.VenueCode,
                        StaffId   = "s",
                        EventDate = @event.Date,
                    };
                    var reserveVenue = await _venuesClient.AddReservation(postReservation);

                    @event.ReservationRef = reserveVenue.Reference;
                    @event.VenueName      = postVenue.VenueName;

                    _context.Update(@event);
                    await _context.SaveChangesAsync();
                }
                catch
                {
                    if (!EventExists(postVenue.EventId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(postVenue));
        }
コード例 #10
0
        public async Task <IActionResult> Edit(int id, [Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking)
        {
            if (id != guestBooking.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(guestBooking);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuestBookingExists(guestBooking.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Email", guestBooking.CustomerId);
            ViewData["EventId"]    = new SelectList(_context.Events, "Id", "Title", guestBooking.EventId);
            return(View(guestBooking));
        }
コード例 #11
0
ファイル: ArtistsController.cs プロジェクト: s20015/kolokwium
        public IActionResult UpdateArtistEvent([FromRoute] int idArtist, [FromRoute] int idEvent, [FromBody] ArtistEvent request)
        {
            var artistEvent = _context.ArtistEvent
                              .Where(ae => ae.IdArtist == idArtist)
                              .Where(ae => ae.IdEvent == idEvent)
                              .Include(ae => ae.Event)
                              .FirstOrDefault();

            if (artistEvent == null)
            {
                return(NotFound());
            }

            if (artistEvent.Event.StartDate > DateTime.Now)
            {
                return(BadRequest($"event (id: {idEvent}) already started "));
            }

            if (request.PerformanceDate > artistEvent.Event.EndDate || request.PerformanceDate < artistEvent.Event.StartDate)
            {
                // TODO detailed error msg
                return(BadRequest("new performanceDate must be set within event startTime and endTime limits"));
            }

            artistEvent.PerformanceDate = request.PerformanceDate;
            _context.Update(artistEvent);
            _context.SaveChanges();

            return(Ok(artistEvent));
        }
コード例 #12
0
        public async Task <IActionResult> Edit(int eventid, int customerid, [Bind("CustomerId, EventId, Attended")] GuestBooking GuestBooking)
        {
            if (eventid != GuestBooking.EventId || customerid != GuestBooking.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(GuestBooking);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuestExists(GuestBooking.EventId, GuestBooking.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "Events", new { id = eventid }));
            }
            return(View(GuestBooking));
        }
コード例 #13
0
        public async Task <IActionResult> Edit(int customerid, int eventid, [Bind("CustomerId,Customer,EventId,Event,Attended")] GuestBooking guest)
        {
            if (eventid != guest.EventId || customerid != guest.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _eventContext.Update(guest);
                    await _eventContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_eventContext.Guests.Any(e => e.CustomerId == guest.CustomerId && e.EventId == guest.EventId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(GuestIndex)));
            }
            ViewData["CustomerId"] = new SelectList(_eventContext.Customers, "Id", "Fullname", guest.CustomerId);
            ViewData["EventId"]    = new SelectList(_eventContext.Events, "Id", "Title", guest.EventId);
            return(View(guest));
        }
コード例 #14
0
ファイル: BaseRepository.cs プロジェクト: jozsef13/Events
        public T Update(T item)
        {
            var entity = context.Update <T>(item);

            context.SaveChanges();
            return(entity.Entity);
        }
コード例 #15
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Location,Date")] StaffBookings staffBooking)
        {
            if (id != staffBooking.StaffId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(staffBooking);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffBookingExists(staffBooking.StaffId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(staffBooking));
        }
コード例 #16
0
        public async Task <IActionResult> Edit(int customerid, int eventid, [Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking)
        {
            //Checks to see if the guest booking exists.
            if (customerid != guestBooking.CustomerId || eventid != guestBooking.EventId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(guestBooking);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuestBookingExists(guestBooking.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            //Loads the viewbag with data that is to be used in the view, i used this method so that different data could be displayed based on the database even if it changes.
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Email", guestBooking.CustomerId);
            ViewData["EventId"]    = new SelectList(_context.Events, "Id", "Title", guestBooking.EventId);
            return(View(guestBooking));
        }
        public async Task <IActionResult> Edit(int id, [Bind("StaffId,EventId")] Staffing staffing)
        {
            if (id != staffing.StaffId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(staffing);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffingExists(staffing.StaffId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffing.EventId);
            ViewData["StaffId"] = new SelectList(_context.Staff, "Id", "Id", staffing.StaffId);
            return(View(staffing));
        }
コード例 #18
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Surname,FirstName,Email,FirstAid")] Staff staff)
        {
            //Checks if the staff member exists.
            if (id != staff.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //If they do then updates the record based off the data inputted in the view.
                    _context.Update(staff);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffExists(staff.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(staff));
        }
コード例 #19
0
        public async Task <IActionResult> UpdateAttendance(int?id, int?eventId)
        {
            var guestBooking = await _context.Guests.FindAsync(id, eventId);

            if (guestBooking.Attended == true)
            {
                guestBooking.Attended = false;
            }
            else
            {
                guestBooking.Attended = true;
            }
            _context.Update(guestBooking);
            await _context.SaveChangesAsync();

            return(Ok());
        }
コード例 #20
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            //finds event that is trying to be deleted.
            var @event = await _context.Events.FindAsync(id);


            if (@event.reservations != null)
            {
                //Building query to message the venues database.
                HttpClient clientWhenDeletingFirst = new HttpClient();
                var        RequestBuilder          = new UriBuilder("http://localhost");
                RequestBuilder.Port = 23652;
                RequestBuilder.Path = "api/Reservations/" + @event.reservations;
                String url = RequestBuilder.ToString();

                //Checks if query was recieved.
                clientWhenDeletingFirst.DefaultRequestHeaders.Accept.ParseAdd("application/json");
                HttpResponseMessage responseWhenDeleting = await clientWhenDeletingFirst.DeleteAsync(url);

                if (!responseWhenDeleting.IsSuccessStatusCode)
                {
                    //If unsuccessful it then it returns an error and returns to the events index.
                    ModelState.AddModelError("", "Previous reservation could not be removed.");
                    return(RedirectToAction(nameof(Index), "Events"));
                }

                //If successful it then deletes the booking
                @event.reservations = null;
                _context.Update(@event);
                await _context.SaveChangesAsync();
            }

            _context.Events.Remove(@event);
            await _context.SaveChangesAsync();

            //Removes any staff bookings that are related to the event freeing up staff.
            var @event2 = await _context.StaffBookings.FindAsync(id);

            _context.StaffBookings.RemoveRange(_context.StaffBookings.Where(s => s.EventId == id));
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #21
0
        public async Task <IActionResult> Edit(int id, string Title, TimeSpan Duration, Event @event)
        {
            if (id != @event.Id)
            {
                return(NotFound());
            }

            if (string.IsNullOrEmpty(Title) || Duration == null)
            {
                return(NotFound());
            }
            else
            {
                /** This updates the event with the new information from the edit view.
                 */
                try
                {
                    Event e = await _context.Events.FindAsync(id);

                    e.Title    = Title;
                    e.Duration = Duration;
                    await _context.SaveChangesAsync();

                    _context.Update(e);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventExists(@event.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
        }
コード例 #22
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Date,Duration,TypeId")] Event @event)
        {
            /*if (@event.Date != DBevent.Date)
             * {
             *  return View(@event);
             * }*/

            if (id != @event.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //Variable DBevent created to access database based upon id given.
                    var @DBevent = await _context.Events.FindAsync(id);

                    //Assigning event date and event type to the same as the current DB values
                    //This is to further prevent changes being saved to a venue's date and type. See event/Edit for initial security.
                    DBevent.Title    = @event.Title;
                    DBevent.Duration = @event.Duration;
                    _context.Update(DBevent);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventExists(@event.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }
コード例 #23
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Duration,VenueToReserve")] EventEditViewModel @event)
        {
            if (id != @event.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(@event));
            }

            try
            {
                Event e = await _context.Events
                          .FirstOrDefaultAsync(dbEvent => dbEvent.Id == @event.Id);

                if (e == null)
                {
                    return(BadRequest());
                }

                e.Duration = @event.Duration;
                e.Title    = @event.Title;
                _context.Update(e);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventExists(@event.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
コード例 #24
0
ファイル: EventsController.cs プロジェクト: t7099806/ICA
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Duration")] EventsEditViewModel @event)
        {
            var @eventVM = await _context.Events.FindAsync(id);

            if (@eventVM == null)
            {
                return(NotFound());
            }

            if (id != @event.Id)
            {
                return(NotFound());
            }

            @eventVM.Duration = @event.Duration;
            @eventVM.Title    = @event.Title;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(@eventVM);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventExists(@event.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(@eventVM));
        }
コード例 #25
0
 public async Task <IActionResult> Edit([Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(guestBooking);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!GuestBookingExists(guestBooking.CustomerId))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(EventIndex), new { id = guestBooking.EventId }));
     }
     return(RedirectToAction(nameof(EventIndex), new { id = guestBooking.EventId }));
 }
コード例 #26
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Surname,FirstName,Email")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (_context.Customers.Any(c => c.Email == customer.Email))
                {
                    ModelState.AddModelError("Email", "Customer with that email already exists");

                    return(View(customer));
                }

                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
コード例 #27
0
        public async Task <IActionResult> Edit([Bind("Id,Surname,FirstName,Email,FirstAider,IsActive")] StaffVM staffVM)
        {
            if (staffVM == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    Staff staff = await _context.Staff.FirstOrDefaultAsync(m => m.Id == staffVM.Id);

                    staff.Surname    = staffVM.Surname;
                    staff.FirstName  = staffVM.FirstName;
                    staff.Email      = staffVM.Email;
                    staff.FirstAider = staffVM.FirstAider;
                    staff.IsActive   = staffVM.IsActive;
                    _context.Update(staff);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffExists(staffVM.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        staffVM.Message = "Something went wrong.  Please ensure all fields are completed and try again";
                        return(View(staffVM));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(staffVM));
        }
コード例 #28
0
        //To actually reserve a venue with check for if a venue is already booked.
        //Done this way as i have the best udnerstanding of this method and i feel it allows for easier checking when attempting to reserve the venue.
        public async Task <ActionResult> Reservations(int id, string reservations)
        {
            //Checks if the vent is valid.
            var @event = await _context.Events.FirstOrDefaultAsync(a => a.Id == id);

            if (@event == null)
            {
                return(BadRequest());
            }


            if (@event.reservations != null)
            {
                //Builds the url to find the avlability table in the venues project, this time filtering based on the reservation.
                HttpClient clientWhenDeletingFirst = new HttpClient();
                var        RequestBuilder          = new UriBuilder("http://localhost");
                RequestBuilder.Port = 23652;
                RequestBuilder.Path = "api/Reservations/" + @event.reservations;
                String url = RequestBuilder.ToString();

                clientWhenDeletingFirst.DefaultRequestHeaders.Accept.ParseAdd("application/json");
                HttpResponseMessage responseWhenDeleting = await clientWhenDeletingFirst.DeleteAsync(url);

                if (!responseWhenDeleting.IsSuccessStatusCode)
                {
                    //If failed then displays an error.
                    ModelState.AddModelError("", "Previous reservation could not be removed.");
                    return(RedirectToAction(nameof(Index), "Events"));
                }
                //Updates the reservations.
                @event.reservations = null;
                _context.Update(@event);
                await _context.SaveChangesAsync();
            }

            var client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:23652");
            client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
            //client.Timeout = TimeSpan.FromSeconds(5);

            //USes the post model using the data passed.
            ReservationPostDto reg = new ReservationPostDto
            {
                EventDate = @event.Date,
                VenueCode = reservations,
                StaffId   = "staff"
            };
            //Checks if the response is successful and if it is then it updates the database.
            HttpResponseMessage response = await client.PostAsJsonAsync("api/Reservations", reg);

            if (response.IsSuccessStatusCode)
            {
                var isSuccess = await response.Content.ReadAsAsync <ReservationGetDto>();

                @event.reservations = isSuccess.Reference;
                _context.Update(@event);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction(nameof(Index), "Events"));
        }
コード例 #29
0
        public async Task <IActionResult> GetVenues(int?id, string toReserve)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var @event = await _context.Events
                         .FirstOrDefaultAsync(m => m.Id == id);

            if (@event == null)
            {
                return(NotFound());
            }

            if (toReserve == null)
            {
                return(RedirectToAction("GetVenues", new { id }));
            }

            HttpClient client = new HttpClient();

            client.BaseAddress = new System.Uri("http://localhost:23652");
            client.DefaultRequestHeaders.Accept.ParseAdd("application/json");

            var uri = "/api/reservations/";

            if (@event.Reference == null)
            {
                var reservedPost = new ReservationPostDto
                {
                    EventDate = @event.Date,
                    VenueCode = toReserve,
                    StaffId   = "NULL"
                };
                if (reservedPost.VenueCode == null || reservedPost.StaffId == null)
                {
                    return(RedirectToAction(nameof(Index)));
                }

                HttpResponseMessage response = await client.PostAsJsonAsync(uri, reservedPost);

                if (response.IsSuccessStatusCode)
                {
                    @event.Reference = $"{toReserve}{@event.Date:yyyyMMdd}";

                    _context.Update(@event);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                if (@event.Reference != $"{toReserve}{@event.Date:yyyyMMdd}")
                {
                    var referenceDelete = @event.Reference;

                    HttpResponseMessage responseDelete = await client.DeleteAsync(uri + referenceDelete);

                    if (responseDelete.IsSuccessStatusCode)
                    {
                        var reservedPost = new ReservationPostDto
                        {
                            EventDate = @event.Date,
                            VenueCode = toReserve,
                            StaffId   = "NULL"
                        };

                        HttpResponseMessage response = await client.PostAsJsonAsync(uri, reservedPost);

                        if (response.IsSuccessStatusCode)
                        {
                            @event.Reference = $"{toReserve}{@event.Date:yyyyMMdd}";

                            _context.Update(@event);
                            await _context.SaveChangesAsync();

                            RedirectToAction(nameof(Index));
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }