Exemplo n.º 1
0
        public async Task <IActionResult> DownloadMyMasterQrCodeAsync(Guid eventId)
        {
            Guid         userId       = User.GetUserId();
            MasterQrCode masterQrCode = await _context.MasterQrCodes
                                        .Where(e => e.EventId == eventId &&
                                               e.OwnerId == userId &&
                                               e.RevokedAt == null)
                                        .FirstOrDefaultAsync();

            if (masterQrCode == null)
            {
                masterQrCode = new MasterQrCode
                {
                    EventId   = eventId,
                    OwnerId   = userId,
                    CreatedAt = DateTime.UtcNow
                };
                _context.Add(masterQrCode);
                await _context.SaveChangesAsync();
            }

            string loginUrl = Url.ActionAbsoluteUrl <MasterQrCodeLoginController>(
                nameof(MasterQrCodeLoginController.LoginAsync),
                new { token = masterQrCode.Id.ToString() });

            return(new QrCodeResult(loginUrl));
        }
        //[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());
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking)
        {
            if (ModelState.IsValid)
            {
                var existingGuest = _context.Guests.Where(g => g.CustomerId == guestBooking.CustomerId && g.EventId == guestBooking.EventId).ToList();
                if ((existingGuest == null || existingGuest.Count == 0) && guestBooking.Attended == true)
                {
                    var     allGuests = _context.Guests.Where(g => g.EventId == guestBooking.EventId).ToList();
                    EventVM eventVM   = new EventVM(await _context.Events.FindAsync(guestBooking.EventId));
                    if (allGuests.Count >= eventVM.VenueCapacity)
                    {
                        return(BadRequest());
                    }
                    guestBooking.Attended = false;
                    _context.Add(guestBooking);
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
                else if (existingGuest != null && existingGuest.Count != 0 && guestBooking.Attended == false)
                {
                    _context.Remove(existingGuest.FirstOrDefault());
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
            }
            return(BadRequest());
        }
        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));
        }
Exemplo n.º 6
0
        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("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));
        }
Exemplo n.º 8
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));
        }
        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));
        }
Exemplo n.º 10
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 <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));
        }
Exemplo n.º 12
0
        public ActionResult <Ticket> CreateTicket(Ticket model)
        {
            if (model.Id > 0)
            {
                return(BadRequest(
                           new ProblemDetails {
                    Detail = "This method can't be used to update tickets."
                }));
            }
            var evt = _context.Events.Find(model.EventId);

            if (evt == null)
            {
                return(BadRequest(
                           new ProblemDetails {
                    Detail = $"There's no event with id {model.EventId}."
                }));
            }
            var entity = new DataAccess.Models.Ticket();

            _mapper.Map(model, entity);
            entity.TicketGuid   = Guid.NewGuid();
            entity.TicketNumber = entity.TicketNumber
                                  ?? TicketNumberHelper.GenerateTicketNumber(evt);
            SetAuthorInfo(entity);
            _context.Add(entity);
            _context.SaveChanges();
            model = _mapper.Map <Ticket>(entity);
            return(CreatedAtAction(nameof(GetById), new { id = model.Id }, model));
        }
Exemplo n.º 13
0
        public T Add(T item)
        {
            var entity = context.Add <T>(item);

            context.SaveChanges();
            return(entity.Entity);
        }
        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));
        }
Exemplo n.º 15
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));
        }
Exemplo n.º 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));
        }
        public async Task <IActionResult> BookEvent([Bind("Id,VenueRef,Date,VenueName,VenueDescription,VenueCapacity,VenueCost,Title,Duration,TypeId,Type,Existing,OldRef")] EventVM booking)
        {
            var                client    = setupVenueClient();
            string             uri       = "/api/Reservations";
            string             uriOldRef = uri + "/" + booking.OldRef;
            ReservationPostDto res       = new ReservationPostDto(booking.Date, booking.VenueRef);

            try
            {
                if ((await client.GetAsync(uriOldRef)).IsSuccessStatusCode)
                {
                    var deleteResponse = await client.DeleteAsync(uriOldRef);

                    deleteResponse.EnsureSuccessStatusCode();
                }
                var postResponse = await client.PostAsJsonAsync(uri, res);

                postResponse.EnsureSuccessStatusCode();
                if (booking.Existing)  // need the ID!
                {
                    var @event = await _context.Events.FindAsync(booking.Id);

                    @event.Title            = booking.Title;
                    @event.Duration         = booking.Duration;
                    @event.VenueRef         = booking.VenueRef;
                    @event.VenueName        = booking.VenueName;
                    @event.VenueDescription = booking.VenueDescription;
                    @event.VenueCapacity    = booking.VenueCapacity;
                    @event.VenueCost        = booking.VenueCost;
                    await _context.SaveChangesAsync();
                }
                else
                {
                    // all relevant venue data saved locally to prevent the alternative of having to query the API constantly to display venue information
                    Event @event = new Event();
                    @event.Date             = booking.Date;
                    @event.Title            = booking.Title;
                    @event.Duration         = booking.Duration;
                    @event.TypeId           = booking.TypeId;
                    @event.Type             = booking.Type;
                    @event.VenueRef         = booking.VenueRef;
                    @event.VenueName        = booking.VenueName;
                    @event.VenueDescription = booking.VenueDescription;
                    @event.VenueCapacity    = booking.VenueCapacity;
                    @event.VenueCost        = booking.VenueCost;
                    _context.Add(@event);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception)
            {
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 18
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));
        }
Exemplo n.º 19
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));
        }
Exemplo n.º 20
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));
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Create([Bind("StaffId,EventId")] StaffBooking staffBooking)
        {
            if (ModelState.IsValid)
            {
                if (!StaffBookingExists(staffBooking.StaffId, staffBooking.EventId))
                {
                    _context.Add(staffBooking);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    Debug.WriteLine("Guest Booking already Exists");
                }
            }

            ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffBooking.EventId);
            ViewData["StaffId"] = new SelectList(_context.Staff, "Id", "Email", staffBooking.StaffId);
            return(View(staffBooking));
        }
Exemplo n.º 23
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));
        }
Exemplo n.º 24
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"));
        }
Exemplo n.º 25
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)));
        }
Exemplo n.º 26
0
        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));
        }
Exemplo n.º 27
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));
        }
Exemplo n.º 28
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));
        }
Exemplo n.º 29
0
        public ActionResult <Event> CreateEvent([FromBody] Event model)
        {
            if (model.Id > 0)
            {
                return(BadRequest());
            }
            var entity = new DataAccess.Models.Event();

            _mapper.Map(model, entity);
            _context.Add(entity);
            _context.SaveChanges();
            model = _mapper.Map <Event>(entity);
            return(CreatedAtAction(nameof(GetEvent), new { id = model.Id }, model));
        }
Exemplo n.º 30
0
        public async Task <IActionResult> Create([Bind("Id,Title,Date,Duration,TypeId")] Event @event)
        {
            /** This adds the new event to the the DB Context, and after creating the event returns the user to the index page.
             * If the new event is not valid, it is returned to the create view with all of the details filled in for usability.
             */
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }