//[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([Bind("StaffId,EventId,Attended")] StaffBookingVM staffAttendance)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Staffing staff = await _context.Staffing.FindAsync(staffAttendance.StaffId, staffAttendance.EventId);

                    if (staff != null && staffAttendance.Attended == false)
                    {
                        _context.Remove(staff);
                        await _context.SaveChangesAsync();

                        return(Ok());
                    }
                    if (staff == null && staffAttendance.Attended == true)
                    {
                        _context.Add(new Staffing(staffAttendance.EventId, staffAttendance.StaffId));
                        await _context.SaveChangesAsync();

                        return(Ok());
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                }
            }
            return(NotFound());
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,Title,Date,Duration,TypeId,VenueCode,StaffId")] CreateEventsViewModel @event)
        {
            if (ModelState.IsValid)
            {
                Models.EventsViewModel tempEvent = new Models.EventsViewModel
                {
                    Id        = @event.Id,
                    Title     = @event.Title,
                    Date      = @event.Date,
                    Duration  = @event.Duration,
                    TypeId    = @event.TypeId,
                    VenueCode = @event.VenueCode
                };

                Reservations resdto = new Reservations
                {
                    EventDate = @event.Date.Date,
                    VenueCode = @event.VenueCode,
                    StaffId   = @event.StaffId.ToString()
                };

                _context.Add(tempEvent);
                await _context.SaveChangesAsync();

                HttpClient client   = new HttpClient();
                var        response = client.PostAsync("http://localhost:22263/api/Reservations", new StringContent(JsonConvert.SerializeObject(resdto), Encoding.UTF8, "application/json"));

                Debug.WriteLine(await response.Result.Content.ReadAsStringAsync());

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

            return(View(@event));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking)
        {
            if (ModelState.IsValid)
            {
                //Check if guest booking already exists
                if (_context.Guests.Any(g => g.CustomerId == guestBooking.CustomerId && g.EventId == guestBooking.EventId))
                {
                    ModelState.AddModelError(string.Empty, "Booking already exists");
                }
                else
                {
                    _context.Add(guestBooking);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Details", "Events", new { id = guestBooking.EventId }));
                }
            }

            var @event = await _context.Events.FindAsync(guestBooking.EventId);

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

            guestBooking.Customer.Bookings.Add(guestBooking);
            guestBooking.Event.Bookings.Add(guestBooking);

            ViewData["EventId"] = guestBooking.EventId;
            return(View(guestBooking));
        }
        public async Task <IActionResult> Create([Bind("StaffId,Staff,EventId,Event")] Staffing staff)
        {
            var selectedStaff = _eventContext.Staffing
                                .Include(a => a.Event)
                                .Include(a => a.Staff)
                                .FirstOrDefault(a => a.StaffId == staff.StaffId && a.EventId == staff.EventId);

            if (ModelState.IsValid)
            {
                try
                {
                    _eventContext.Add(staff);
                    await _eventContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(StaffingIndex)));
                }
                catch (InvalidOperationException)
                {
                    TempData["msg"] = $"Error : {selectedStaff.Staff.Fullname} and {selectedStaff.Event.Title} already existed!";
                }
                catch (Exception ex)
                {
                    TempData["msg"] = ex.Message;
                }
            }
            else
            {
                TempData["msg"] = "ModelState is not valid, please verify guestbooking model";
            }

            ViewData["StaffId"] = new SelectList(_eventContext.Staff, "StaffId", "Fullname", staff.Staff);
            ViewData["EventId"] = new SelectList(_eventContext.Events, "Id", "Title", staff.Event);
            return(View(staff));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking)
        {
            if (ModelState.IsValid)
            {
                if (GuestBookingExists(guestBooking.CustomerId, guestBooking.EventId))
                {
                    ModelState.AddModelError(String.Empty, "This customer is already a guest at the event.");
                    return(View(guestBooking));
                }

                _context.Add(guestBooking);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = guestBooking.EventId }));
            }

            var OnEvent = _context.Guests.Include(c => c.Customer).Where(e => e.EventId == guestBooking.EventId).Select(c => new Customer()
            {
                Id        = c.CustomerId,
                Surname   = c.Customer.Surname,
                FirstName = c.Customer.FirstName,
                Email     = c.Customer.Email,
                Bookings  = c.Customer.Bookings
            }).ToList();

            var ToShow = _context.Customers.Where(x => !OnEvent.Contains(x)).ToList();

            ViewData["CustomerCheck"] = ToShow == null || ToShow.Count == 0;

            ViewData["CustomerId"] = new SelectList(ToShow, "Id", "Email");
            ViewData["EventId"]    = guestBooking.EventId;

            return(View(guestBooking));
        }
Beispiel #6
0
        public async Task <IActionResult> Create([Bind("Id,Surname,FirstName,Email,FirstAider,IsActive")] StaffVM staffVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Staff staff = new Staff();
                    staff.Surname    = staffVM.Surname;
                    staff.FirstName  = staffVM.FirstName;
                    staff.Email      = staffVM.Email;
                    staff.FirstAider = staffVM.FirstAider;
                    staff.IsActive   = true;
                    _context.Add(staff);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    staffVM.Message = "Something went wrong.  Please ensure all fields are completed and try again";
                    return(View(staffVM));
                }
            }
            return(View(staffVM));
        }
Beispiel #7
0
        public async Task <IActionResult> Create(CreateRegistrationModel model)
        {
            var evt = await _dbContext.Events.FindAsync(model.EventId);

            if (evt == null)
            {
                return(BadRequest("Invalid event"));
            }

            var session = await _dbContext.Sessions.FindAsync(model.SessionId);

            if (session == null || session.EventId != evt.Id)
            {
                return(BadRequest("Invalid session"));
            }

            var currentUser = await _userManager.GetUserAsync(User);

            try
            {
                var existing = await _dbContext.Registrations
                               .AnyAsync(x => x.EventId == model.EventId &&
                                         x.SessionId == model.SessionId &&
                                         x.UserId == currentUser.Id);

                if (existing)
                {
                    return(BadRequest("User is already registered for session"));
                }

                var hasSameSectionReg = await _dbContext.Registrations
                                        .AnyAsync(x => x.Session.SectionId == session.SectionId &&
                                                  x.UserId == currentUser.Id);

                if (hasSameSectionReg)
                {
                    return(BadRequest("User is already registered for session in the time section"));
                }

                var registration = new Registration
                {
                    Event     = evt,
                    Session   = session,
                    User      = currentUser,
                    CreatedOn = DateTime.UtcNow
                };

                _dbContext.Registrations.Add(registration);
                await _dbContext.SaveChangesAsync();

                var result = registration.ToModel();
                return(Created("", result));
            }
            catch (Exception ex)
            {
                _logger.LogError(2, ex, "Error creating registration", model.EventId, model.SessionId, model.UserId);

                return(StatusCode((int)HttpStatusCode.InternalServerError, "Error creating registration"));
            }
        }
Beispiel #8
0
        public async Task <IActionResult> Create([Bind("Id,Title,Date,Duration,TypeId")] Event @event)
        {
            var etInfo = new List <EventListDto>().AsEnumerable();

            if (ModelState.IsValid)
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new System.Uri("http://localhost:23652");
                client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
                HttpResponseMessage response = await client.GetAsync("api/EventTypes");

                if (response.IsSuccessStatusCode)
                {
                    etInfo = await response.Content.ReadAsAsync <IEnumerable <EventListDto> >();
                }
                else
                {
                    throw new Exception();
                }

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

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


            ViewData["TypeId"] = new SelectList(etInfo.ToList(), "id", "title");

            return(View(@event));
        }
        public async Task OnPost(string?id)
        {
            var newRole = _context.Attendees
                          .Where(m => m.Id == id)
                          .FirstOrDefault();
            var test = _userManager.IsInRoleAsync(newRole, "Organizer").Result;

            if (!_userManager.IsInRoleAsync(newRole, "Organizer").Result)
            {
                await _userManager.AddToRoleAsync(newRole, "Organizer");

                await _userManager.RemoveFromRoleAsync(newRole, "Attendee");

                await _context.SaveChangesAsync();
            }
            else
            {
                await _userManager.RemoveFromRoleAsync(newRole, "Organizer");

                await _userManager.AddToRoleAsync(newRole, "Attendee");

                await _context.SaveChangesAsync();
            }

            await OnGetAsync();
        }
        public async Task <IActionResult> Create([Bind("CustomerId,EventId,Attended")] GuestBookingCreateViewModel guestBooking)
        {
            if (ModelState.IsValid)
            {
                GuestBooking existing = await _context.Guests.FindAsync(guestBooking.EventId, guestBooking.CustomerId);

                if (existing != null)
                {
                    // Exists
                    ViewData["CustomerId"] = new SelectList(await _context.Customers.Where(x => !x.Deleted).ToListAsync(), "Id", "FullName", guestBooking.CustomerId);
                    ViewData["EventId"]    = new SelectList(await _context.Events.Where(x => !x.Cancelled).ToListAsync(), "Id", "Title", guestBooking.EventId);
                    ModelState.AddModelError(string.Empty, "The chosen guest is already booked into the chosen event.");
                    return(View(guestBooking));
                }
                GuestBooking booking = new GuestBooking()
                {
                    CustomerId = guestBooking.CustomerId,
                    EventId    = guestBooking.EventId,
                    Attended   = guestBooking.Attended
                };
                _context.Add(booking);
                await _context.SaveChangesAsync();

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

            ViewData["CustomerId"] = new SelectList(await _context.Customers.Where(x => !x.Deleted).ToListAsync(), "Id", "FullName", guestBooking.CustomerId);
            ViewData["EventId"]    = new SelectList(await _context.Events.Where(x => !x.Cancelled).ToListAsync(), "Id", "Title", guestBooking.EventId);
            return(View(guestBooking));
        }
Beispiel #11
0
        public async Task <IActionResult> Create([Bind("StaffId,EventId")] Staffing staffing)
        {
            if (ModelState.IsValid)
            {
                //Check if staffing already exists
                if (_context.Workers.Any(w => w.StaffId == staffing.StaffId && w.EventId == staffing.EventId))
                {
                    ModelState.AddModelError(string.Empty, "Booking already exists");
                }
                else
                {
                    _context.Add(staffing);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Details", "Events", new { id = staffing.EventId }));
                }
            }

            var @event = await _context.Events.FindAsync(staffing.EventId);

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

            ViewData["EventTitle"] = @event.Title;

            staffing.Staff.Jobs.Add(staffing);
            staffing.Event.Staff.Add(staffing);

            return(View(staffing));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,Customer,EventId,Event,Attended")] GuestBooking guest)
        {
            var selectedGuest = _eventContext.Guests
                                .Include(a => a.Event)
                                .Include(a => a.Customer)
                                .FirstOrDefault(a => a.CustomerId == guest.CustomerId && a.EventId == guest.EventId);

            if (ModelState.IsValid)
            {
                try
                {
                    _eventContext.Add(guest);
                    await _eventContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(GuestIndex)));
                }
                catch (InvalidOperationException)
                {
                    TempData["msg"] = $"Error : {selectedGuest.Customer.Fullname} and {selectedGuest.Event.Title} already exist!";
                }
                catch (Exception ex)
                {
                    TempData["msg"] = ex.Message;
                }
            }
            else
            {
                TempData["msg"] = "ModelState is not valid, please verify guestbooking model";
            }

            ViewData["CustomerId"] = new SelectList(_eventContext.Customers, "Id", "Fullname", guest.Customer);
            ViewData["EventId"]    = new SelectList(_eventContext.Events, "Id", "Title", guest.Event);
            return(View(guest));
        }
        public async Task <IActionResult> Create([Bind("StaffId,EventId")] StaffBooking staffBooking)
        {
            if (ModelState.IsValid)
            {
                if (StaffBookingExists(staffBooking.StaffId, staffBooking.EventId))
                {
                    ModelState.AddModelError(String.Empty, "This staff member is already at the event.");
                    return(View(staffBooking));
                }

                _context.Add(staffBooking);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = staffBooking.EventId }));
            }

            var OnEvent = _context.StaffBooking.Include(c => c.Staff).Where(e => e.EventId == staffBooking.EventId).Select(c => new Staff()
            {
                Id         = c.StaffId,
                Surname    = c.Staff.Surname,
                FirstName  = c.Staff.FirstName,
                FirstAider = c.Staff.FirstAider,
                Bookings   = c.Staff.Bookings
            }).ToList();

            var ToShow = _context.Staff.Where(x => !OnEvent.Contains(x)).ToList();

            ViewData["StaffCheck"] = ToShow == null || ToShow.Count == 0;

            ViewData["StaffId"] = new SelectList(ToShow, "Id", "FirstName");
            ViewData["EventId"] = staffBooking.EventId;

            return(View(staffBooking));
        }
Beispiel #14
0
        public async Task <IActionResult> GuestsAtEvent(int CustomerId, int EventId, [Bind("CustomerId,EventId,Attended")] GuestBookingAttendanceVM guestBooking)
        {
            if (CustomerId != guestBooking.CustomerId || EventId != guestBooking.EventId)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var dbGuestBooking = await _context.Guests.FindAsync(guestBooking.CustomerId, guestBooking.EventId);

                    dbGuestBooking.Attended = guestBooking.Attended;
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuestBookingExists(guestBooking.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(Ok());
        }
Beispiel #15
0
        public async Task <int> Create(EventDto obj)
        {
            Event created = AplyDtoToEntity(obj);

            _eventsDbContext.Events.Add(created);
            await _eventsDbContext.SaveChangesAsync();

            return(created.Id);
        }
Beispiel #16
0
        public async Task <IActionResult> Create([Bind("Id,Surname,FirstName,Email,FirstAider")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staff);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(staff));
        }
Beispiel #17
0
        public async Task <IActionResult> Create([Bind("Id,Surname,FirstName,Email")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Beispiel #18
0
        public async Task <IActionResult> Create([Bind("Id,Title,Date,Duration,TypeId")] Event @event)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }
Beispiel #19
0
        public async Task <IActionResult> Create([Bind("StaffId,EventId,Attended")] StaffBookings staffBooking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staffBooking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(staffBooking));
        }
        public async Task <IActionResult> Create([Bind("Id,Surname,FirstName,Email,FirstAid")] Staff staff)
        {
            //If the member of staff does not already exist then creates it.
            if (ModelState.IsValid)
            {
                _context.Add(staff);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(staff));
        }
        public async Task <IActionResult> JoinEvent(int id, JoinEventViewModel model)
        {
            var evt = await _dbContext.Events.FindAsync(id);

            if (evt == null)
            {
                _logger.LogInformation($"Event ID {id} not found");

                // TODO: Display error
                return(RedirectToAction(nameof(Index)));
            }

            model.Event = evt.ToModel();

            var currentUser = await _userManager.GetUserAsync(User);

            var userIsMember = await _dbContext.EventMembers.AnyAsync(x => x.EventId == evt.Id && x.UserId == currentUser.Id);

            if (userIsMember)
            {
                _logger.LogInformation($"User ID {currentUser.Id} is already member of Event ID {evt.Id}");

                return(RedirectToAction(nameof(Details), new { slug = evt.Slug }));
            }

            if (evt.RequirePassword && model.Password != evt.JoinPassword)
            {
                ModelState.AddModelError(nameof(model.Password), "Event password is invalid");
                return(View(model));
            }

            try
            {
                var member = new EventMember
                {
                    EventId    = evt.Id,
                    UserId     = currentUser.Id,
                    JoinDate   = DateTime.UtcNow,
                    JoinMethod = EventMemberJoinMethod.Password
                };

                _dbContext.EventMembers.Add(member);
                await _dbContext.SaveChangesAsync();

                // TODO: show success message
                return(RedirectToAction(nameof(Details), new { slug = evt.Slug }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error joining user ID {currentUser.Id} to event ID {evt.Id}");
                return(View(model));
            }
        }
Beispiel #22
0
        public async Task <IActionResult> Create([Bind("StaffId,EventId")] Staffing staffing)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staffing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"] = new SelectList(_dataAccess.GetEvents(), "Id", "Title", staffing.EventId);
            ViewData["StaffId"] = new SelectList(await _context.Staff.ToListAsync(), "Id", "Id", staffing.StaffId);
            return(View(staffing));
        }
Beispiel #23
0
        public async Task <IActionResult> Create([Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(guestBooking);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Events"));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Email", guestBooking.CustomerId);
            ViewData["EventId"]    = new SelectList(_context.Events, "Id", "Title", guestBooking.EventId);
            return(RedirectToAction("Index", "Events"));
        }
Beispiel #24
0
        public async Task <IActionResult> Create([Bind("StaffId,EventId")] Staffing staffing)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staffing);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", nameof(Event)));
            }
            ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffing.EventId);
            ViewData["StaffId"] = new SelectList(_context.Staff, "Id", "FirstName", staffing.StaffId);
            return(RedirectToAction("Index", nameof(Event)));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(guestBooking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers.Where(c => c.FirstName != "anon"), "Id", "Email", guestBooking.CustomerId);
            ViewData["EventId"]    = new SelectList(_dataAccess.GetEvents(), "Id", "Title", guestBooking.EventId);
            return(View(guestBooking));
        }
Beispiel #26
0
        public async Task <IActionResult> Create([Bind("EventID,StaffID")] Staffing staffing)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staffing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventID"] = new SelectList(_context.Events, "Id", "Title", staffing.EventID);
            ViewData["StaffID"] = new SelectList(_context.Staffs, "StaffID", "StaffEmail", staffing.StaffID);
            return(View(staffing));
        }
Beispiel #27
0
        public async Task <IActionResult> Create([Bind("Id,StaffId,EventId")] EventStaffing eventStaffing)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eventStaffing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(EventIndex) + "/" + eventStaffing.EventId));
            }
            ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", eventStaffing.EventId);
            ViewData["StaffId"] = new SelectList(_context.Staff, "Id", "Email", eventStaffing.StaffId);
            return(RedirectToAction(nameof(EventIndex) + "/" + eventStaffing.EventId));
        }
        public async Task <IActionResult> Create([Bind("id,StaffId,EventId,Date")] StaffBookings staffBookings)
        {
            //If the booking exists then it adds the booking that is created based off the data inputted in the view.
            if (ModelState.IsValid)
            {
                _context.Add(staffBookings);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //Adds the eventID and event title to the view bag to be displayed in the view, I used viewbag as it is easier to populat e adrop down box using this method.
            ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffBookings.EventId);
            return(View(staffBookings));
        }
        public async Task <IActionResult> Create(int eventId, EditSectionViewModel model)
        {
            var evt = await _dbContext.Events.FindAsync(eventId);

            if (evt == null)
            {
                // TODO: Diplay error
                return(RedirectToAction("Index", "Events"));
            }

            if (model.StartOn < evt.StartOn || model.StartOn > evt.EndOn)
            {
                ModelState.AddModelError(nameof(model.StartOn), "Must be during event times");
            }

            if (model.EndOn < evt.StartOn || model.EndOn > evt.EndOn)
            {
                ModelState.AddModelError(nameof(model.EndOn), "Must be during event times");
            }

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

            try
            {
                var section = new Section
                {
                    Event       = evt,
                    Name        = model.Name,
                    Description = model.Description,
                    StartOn     = model.StartOn,
                    EndOn       = model.EndOn
                };

                _dbContext.Sections.Add(section);
                await _dbContext.SaveChangesAsync();

                return(RedirectToAction("Details", "Events", new { slug = evt.Slug }));
            }
            catch (Exception ex)
            {
                _logger.LogError(2, ex, "Error creating section");

                ModelState.AddModelError("", "There was an error creating the section.  Try again.");
                return(View(model));
            }
        }
Beispiel #30
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Participant).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ParticipantExists(Participant.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Redirect(Request.Headers["Referer"].ToString()));
        }