Example #1
0
        public async Task <ObjectResult> SignupEvent(EventSignupCall signup)
        {
            int ourUserId;

            //gets lookup of users for typeahead
            if (!CheckAdmin())
            {
                return(Unauthorized("You are not permitted to use this function."));
            }

            //run query to verify user can sign up - check the ban flag
            var existUser = _context.Users.Where(a => a.FbId == signup.FbId).FirstOrDefault();

            if (existUser == null)
            {
                return(BadRequest("I am sorry, you are not allowed to sign up for this event."));
            }
            else
            {
                ourUserId = existUser.Id;
            }

            //we passed all the checks, now lets do this thing. We don't assign an attendee number.
            var newEventSignup = new EventSignup()
            {
                TimeslotId  = signup.EventId,
                UserId      = ourUserId,
                SignupTms   = DateTime.Now,
                FlexibleInd = signup.FlexibleInd
            };

            await _context.EventSignup.AddAsync(newEventSignup);

            await _context.SaveChangesAsync();

            //update user table since these are now in the form from earlier.

            return(Ok("The user has been added to the event."));
        }
Example #2
0
        public async Task<ContentResult> SignupEvent(EventSignupCall signup)
        {
            int ourUserId;
            int? newEventId;
            bool autoClearInd = false;

            //Get auto-clear flag
            var autoclearSetting = _appSettings.Value;
            int autoClearLimit = autoclearSetting.AutoClear ?? 0;

            // Keyboard kid rule
            if (signup.Realname.ToLower().IndexOf("lewellen") >= 0) {
                _logger.LogInformation("Keyboard Kid rule activated");
                return Content("Your name is not allowed to sign up for an event.");
            }

            // Grant rule
            if ((signup.Realname.ToLower() == "matthew kisha") && signup.FirstNm != "Matthew" && signup.LastNm != "Kisha") {
                return Content("I'm sorry Dave. Only Matthew Kisha can sign up as Matthew Kisha. This is highly irregular.");
            }

            // run query to verify user can sign up - check the ban flag
            var existUser = _context.Users.Where( a => a.FbId == signup.FbId && a.BanFlag == false).FirstOrDefault();

            if (existUser == null) {
                _logger.LogInformation("Banned user signup attempted - " + signup.FbId);
                return Content("I am sorry, you are not allowed to sign up for this event.");
            } else {
                ourUserId = existUser.Id;
                if (existUser.EventCnt < autoClearLimit && existUser.EventCnt > 0) {
                    autoClearInd = true;
                }
            }

            // Don't allow signup if the user has signed up for this event already
            var existUserEvent = await _context.EventSignup.AnyAsync(u => u.DeleteInd == false 
                                                && u.TimeslotId == signup.EventId
                                                && u.UserId == ourUserId);

            if (existUserEvent) {
                return Content("It looks like you have already signed up for this event.");
            }

            //check for event count - new per Raymond. Will run as final verification.

            int currCount = await _context.EventSignup.Where(m => m.DeleteInd == false).CountAsync(m => m.TimeslotId == signup.EventId);
            var eventStats = await _context.Timeslot.Where(a => a.Id == signup.EventId)
                .FirstOrDefaultAsync();

            // If this event is private, check the GUID to see if it matches. If not, bounce away.
            var eventGuid = signup.EventKey != null ? new Guid(signup.EventKey) : new Guid();

            if (eventStats.EventKey != eventGuid && signup.EventKey != null && eventStats.PrivateEventInd)
            {
                return Content("I am unable to sign you up for this event.");
            }

            if (eventStats.EventClosed == true) {
                return Content("I am sorry, this event is full.");
            }

            if (currCount >= eventStats.SignupCnt) {
                //auto-close functionality
                eventStats.EventClosed = true;
                await _context.SaveChangesAsync();
                return Content("I'm sorry, but this event has filled up. Please select another event.");
            }

            //auto-clear functionality
            if (autoClearInd) {
                newEventId = GetSlotNumber(signup.EventId);
            } else {
                newEventId = null;
            }

            //we passed all the checks, now lets do this thing.
            var newEventSignup = new EventSignup(){
                TimeslotId = signup.EventId,
                UserId = ourUserId,
                SignupTms = DateTime.Now,
                FlexibleInd = signup.FlexibleInd,
                AttendNbr = newEventId
            };

            _context.EventSignup.Add(newEventSignup);
            await _context.SaveChangesAsync();

            //update user table since these are now in the form from earlier.
 
            existUser.CityNm = signup.CityNm;
            existUser.StateCd = signup.StateCd;
            existUser.CountryCd = signup.CountryCd;
            existUser.RealNm = signup.Realname;
            await _context.SaveChangesAsync();

            return Content("We have received your signup. Since we need to verify that you can attend the sale, please check your Facebook messages and message requests for confirmation from the volunteers.");
        }