예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("State,Id")] EventAttendanceState eventAttendanceState)
        {
            if (id != eventAttendanceState.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try {
                    _context.Update(eventAttendanceState);
                    await _context.SaveChangesAsync();
                } catch (DbUpdateConcurrencyException) {
                    if (!EventAttendanceStateExists(eventAttendanceState.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(eventAttendanceState));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("State,Id")] EventAttendanceState eventAttendanceState)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eventAttendanceState);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(eventAttendanceState));
        }
예제 #3
0
        public async Task <IActionResult> AddNewAttendee(string userId, int eventId)
        {
            ApplicationUser user = await _userManager.FindByIdAsync(userId);

            Event eventSelected = await _context.Events.FirstOrDefaultAsync(e => e.Id == eventId);

            EventAttendanceState eventAttendaceState = await _context.EventAttendanceStates.Where(ea => ea.State == WILL_ATTEND).FirstOrDefaultAsync();

            if ((user is null) || (eventSelected is null))
            {
                return(Ok(new { success = false }));
            }

            EventAttendance eventAttendance = new EventAttendance {
                ApplicationUser        = user,
                ApplicationUserId      = user.Id,
                Event                  = eventSelected,
                EventId                = eventSelected.Id,
                EventAttendanceState   = eventAttendaceState,
                EventAttendanceStateId = eventAttendaceState.Id
            };

            try {
                if (_context.EventAttendances.Any(ea => ((ea.ApplicationUserId == userId) && (ea.EventId == eventSelected.Id))))
                {
                    EventAttendance actualEventAttendace = await _context.EventAttendances.Where(ea => ((ea.ApplicationUserId == userId) && (ea.EventId == eventSelected.Id))).AsNoTracking().FirstOrDefaultAsync();

                    eventAttendance.Id = actualEventAttendace.Id;
                    _context.EventAttendances.Update(eventAttendance);
                }
                else
                {
                    _context.EventAttendances.Add(eventAttendance);
                }
                await _context.SaveChangesAsync();

                _logger.LogInformation($"Usuario {userId} inscrito en evento {eventId}.");
            } catch (Exception e) {
                _logger.LogCritical($"EXCEPCIÓN: {e.Message}");
                return(Ok(new { success = false }));
            }

            var dictionay = new Dictionary <string, string>();

            dictionay.Add("Event New Attendee", eventAttendance.ApplicationUser.Name);
            _telemetryClient.TrackEvent("UserInteraction", dictionay);

            return(Ok(new { success = true }));
        }