Exemple #1
0
        protected void gKiosk_Delete(object sender, RowEventArgs e)
        {
            var          rockContext  = new RockContext();
            KioskService kioskService = new KioskService(rockContext);
            Kiosk        kiosk        = kioskService.Get(e.RowKeyId);

            if (kiosk != null)
            {
                int kioskId = kiosk.Id;

                string errorMessage;
                if (!kioskService.CanDelete(kiosk, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                kioskService.Delete(kiosk);
                rockContext.SaveChanges();

                DeviceService deviceService = new DeviceService(rockContext);
                var           devices       = deviceService.Queryable().Where(d => d.Name == kiosk.Name).ToList();
                foreach (var device in devices)
                {
                    KioskDeviceHelpers.FlushItem(device.Id);
                }
            }

            BindGrid();
        }
        protected void btnSelectKiosk_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            var kioskTypeService = new KioskTypeService(rockContext);
            var kioskType        = kioskTypeService.Get(ddlManualKioskType.SelectedValue.AsInteger());

            if (kioskType == null)
            {
                return;
            }


            var kioskService = new KioskService(rockContext);
            var kiosk        = kioskService.GetByClientName(CurrentUser.UserName);

            if (kiosk == null)
            {
                kiosk             = new Kiosk();
                kiosk.Name        = CurrentUser.UserName;
                kiosk.Description = "Automatically created personal Kiosk";
                kioskService.Add(kiosk);
            }
            kiosk.KioskTypeId = kioskType.Id;
            kiosk.CategoryId  = CategoryCache.GetId(Constants.KIOSK_CATEGORY_STAFFUSER.AsGuid());
            rockContext.SaveChanges();

            SetBlockUserPreference("KioskTypeId", kioskType.Id.ToString());

            ActivateKiosk(kiosk, false);
        }
Exemple #3
0
        protected void btnSelectKiosk_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            var kioskTypeService = new KioskTypeService(rockContext);
            var kioskType        = kioskTypeService.Get(ddlKioskType.SelectedValue.AsInteger());

            if (kioskType == null)
            {
                return;
            }


            var kioskService = new KioskService(rockContext);
            var kiosk        = kioskService.GetByClientName(CurrentUser.UserName);

            if (kiosk == null)
            {
                kiosk             = new Kiosk();
                kiosk.Name        = CurrentUser.UserName;
                kiosk.Description = "Automatically created personal Kiosk";
                kioskService.Add(kiosk);
            }
            kiosk.KioskTypeId = kioskType.Id;
            rockContext.SaveChanges();
            GetKioskType(kiosk, rockContext);
        }
Exemple #4
0
        public static void Clear(List <int> groupTypeIds)
        {
            RockContext      rockContext      = new RockContext();
            KioskTypeService kioskTypeService = new KioskTypeService(rockContext);
            KioskService     kioskService     = new KioskService(rockContext);
            DeviceService    deviceService    = new DeviceService(rockContext);



            var kioskTypeIds = kioskTypeService.Queryable()
                               .Where(k => k.GroupTypes.Select(gt => gt.Id).Where(i => groupTypeIds.Contains(i)).Any())
                               .Select(kt => kt.Id)
                               .ToList();

            var deviceNames = kioskService.Queryable()
                              .Where(k => kioskTypeIds.Contains(k.KioskTypeId ?? 0)).Select(k => k.Name)
                              .ToList();

            var devices = deviceService.Queryable().Where(d => deviceNames.Contains(d.Name)).ToList();

            foreach (var device in devices)
            {
                FlushItem(device.Id);
            }
        }
        protected void gKiosk_Delete(object sender, RowEventArgs e)
        {
            var          rockContext  = new RockContext();
            KioskService KioskService = new KioskService(rockContext);
            Kiosk        Kiosk        = KioskService.Get(e.RowKeyId);

            if (Kiosk != null)
            {
                int kioskId = Kiosk.Id;

                string errorMessage;
                if (!KioskService.CanDelete(Kiosk, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                KioskService.Delete(Kiosk);
                rockContext.SaveChanges();

                Rock.CheckIn.KioskDevice.Clear();
            }

            BindGrid();
        }
        private Kiosk GetOrCreateKiosk(string kioskName, int kioskTypeId)
        {
            var rockContext = new RockContext();

            var kioskService = new KioskService(rockContext);
            var kiosk        = kioskService.GetByClientName(kioskName);

            if (kiosk == null)
            {
                kiosk = new Kiosk
                {
                    Name        = kioskName,
                    Description = "Automatically created Kiosk"
                };
                kioskService.Add(kiosk);
            }
            if (kioskTypeId != 0)
            {
                kiosk.KioskTypeId = kioskTypeId;
            }
            kiosk.CategoryId = CategoryCache.GetId(Constants.KIOSK_CATEGORY_STATION.AsGuid());
            rockContext.SaveChanges();

            //Fresh version with new context.
            kiosk = new KioskService(new RockContext()).Get(kiosk.Id);

            return(kiosk);
        }
        private void SetCookie(Kiosk kiosk)
        {
            var kioskNameCookie = this.Page.Request.Cookies[Constants.COOKIE_KIOSK_NAME];

            if (kioskNameCookie == null)
            {
                kioskNameCookie = new System.Web.HttpCookie(Constants.COOKIE_KIOSK_NAME);
            }

            if (kiosk.AccessKey.IsNullOrWhiteSpace())
            {
                RockContext  rockContext  = new RockContext();
                KioskService kioskService = new KioskService(rockContext);
                kiosk           = kioskService.Get(kiosk.Id);
                kiosk.AccessKey = Guid.NewGuid().ToString();
                rockContext.SaveChanges();
            }

            kioskNameCookie.Expires = RockDateTime.Now.AddYears(1);

            string encryptedAccessKey;

            if (Encryption.TryEncryptString(kiosk.AccessKey, out encryptedAccessKey))
            {
                kioskNameCookie.Value = encryptedAccessKey;
                Page.Response.Cookies.Set(kioskNameCookie);
            }
        }
Exemple #8
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="DeviceId">The device identifier.</param>
        public void ShowDetail(int kioskId)
        {
            pnlDetails.Visible = true;
            Kiosk kiosk = null;

            var rockContext = new RockContext();

            if (!kioskId.Equals(0))
            {
                kiosk             = new KioskService(rockContext).Get(kioskId);
                lActionTitle.Text = ActionTitle.Edit(Kiosk.FriendlyTypeName).FormatAsHtmlTitle();
            }

            if (kiosk == null)
            {
                kiosk = new Kiosk {
                    Id = 0
                };
                lActionTitle.Text = ActionTitle.Add(Kiosk.FriendlyTypeName).FormatAsHtmlTitle();
            }

            hfKioskId.Value = kiosk.Id.ToString();

            tbName.Text        = kiosk.Name;
            tbDescription.Text = kiosk.Description;
            tbIPAddress.Text   = kiosk.IPAddress;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized(Authorization.EDIT))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Kiosk.FriendlyTypeName);
            }

            pCategory.SetValue(kiosk.CategoryId);

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(Kiosk.FriendlyTypeName);
                btnCancel.Text    = "Close";
            }

            tbName.ReadOnly        = readOnly;
            tbDescription.ReadOnly = readOnly;

            tbAccessKey.Text = kiosk.AccessKey;
            if (tbAccessKey.Text.IsNullOrWhiteSpace())
            {
                tbAccessKey.Text = Guid.NewGuid().ToString();
            }

            btnSave.Visible = !readOnly;
            BindDropDownList(kiosk);
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var kioskService = new KioskService(new RockContext());
            var kiosks       = kioskService.Queryable()
                               .Select(k => k)
                               .OrderBy(k => k.Name)
                               .ToList();

            gKiosks.DataSource = kiosks;
            gKiosks.DataBind();
        }
Exemple #10
0
        private void SetKiosk(string clientName)
        {
            var rockContext = new RockContext();

            var kioskService = new KioskService(rockContext);
            var kiosk        = kioskService.GetByClientName(clientName);

            if (kiosk == null)
            {
                kiosk             = new Kiosk();
                kiosk.Name        = clientName;
                kiosk.Description = "Automatically created Kiosk";
                kioskService.Add(kiosk);
                rockContext.SaveChanges();
            }
            GetKioskType(kiosk, rockContext);
        }
Exemple #11
0
        private void SetKiosk(string clientName)
        {
            var rockContext = new RockContext();

            var kioskService = new KioskService(rockContext);
            var kiosk        = kioskService.GetByClientName(clientName);

            if (kiosk == null)
            {
                kiosk             = new Kiosk();
                kiosk.Name        = clientName;
                kiosk.Description = "Automatically created Kiosk";
                kioskService.Add(kiosk);
            }
            kiosk.CategoryId = CategoryCache.GetId(Constants.KIOSK_CATEGORY_STATION.AsGuid());
            rockContext.SaveChanges();
            GetKioskType(kiosk, rockContext);
        }
         /// <summary>
        /// Get the player Information
        /// </summary>
        /// <param name="strConnect"></param>
        /// <returns>dictionary</returns>
        public PlayerInfoDTO GetPlayerInfoDTO(string AccountNumber)
        {
            Dictionary<string, string> CMPDetails = playerInformationDataAccess.GetCMPCredentials(CommonDataAccess.ExchangeConnectionString);


            if (CMPDetails.Count > 0)
            {
                kioskService = new KioskService(CMPDetails["CMPURL"].ToString());
            }

            playerInfo = kioskService.RetrievePlayerInfo(AccountNumber);

            PlayerInfoDTO PlayerInfo = new PlayerInfoDTO();
            PlayerInfo.AccountNumber = playerInfo.AccountNumber;
            PlayerInfo.ClubState = playerInfo.ClubState;
            PlayerInfo.ClubStatus = playerInfo.ClubStatus;
            PlayerInfo.DisplayName = playerInfo.DisplayName;
            PlayerInfo.FirstName = playerInfo.FirstName;
            PlayerInfo.LastName = playerInfo.LastName;
            PlayerInfo.PlayerID = playerInfo.PlayerId;
            PlayerInfo.PointsBalance = playerInfo.PointsBalance;

            return PlayerInfo;
        }
Exemple #13
0
        private Kiosk ConfigureKiosk()
        {
            var rockContext = new RockContext();
            var kioskTypeId = ddlCampus.SelectedValue.AsInteger();

            var kioskType = KioskTypeCache.Get(kioskTypeId);

            var kioskName = "Mobile:" + kioskType.Name.RemoveAllNonAlphaNumericCharacters();

            var mobileUserCategory = CategoryCache.Get(org.secc.FamilyCheckin.Utilities.Constants.KIOSK_CATEGORY_MOBILEUSER);

            var kioskService = new KioskService(rockContext);
            var kiosk        = kioskService.Queryable("KioskType")
                               .Where(k => k.Name == kioskName)
                               .FirstOrDefault();

            if (kiosk == null)
            {
                kiosk = new Kiosk
                {
                    Name        = kioskName,
                    CategoryId  = mobileUserCategory.Id,
                    Description = "Automatically created mobile Kiosk"
                };
                kioskService.Add(kiosk);
            }

            kiosk.KioskTypeId = kioskType.Id;
            rockContext.SaveChanges();

            DeviceService deviceService = new DeviceService(rockContext);


            //Load matching device and update or create information
            var device = deviceService.Queryable("Location").Where(d => d.Name == kioskName).FirstOrDefault();

            var dirty = false;

            //create new device to match our kiosk
            if (device == null)
            {
                device = new Device();
                device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id;
                device.Name = kioskName;
                deviceService.Add(device);
                device.PrintFrom       = PrintFrom.Client;
                device.PrintToOverride = PrintTo.Default;
                dirty = true;
            }

            var deviceLocationIds = device.Locations.Select(l => l.Id);
            var ktLocationIds     = kioskType.Locations.Select(l => l.Id);

            var unmatchedDeviceLocations = deviceLocationIds.Except(ktLocationIds).Any();
            var unmatchedKtLocations     = ktLocationIds.Except(deviceLocationIds).Any();

            if (unmatchedDeviceLocations || unmatchedKtLocations)
            {
                LocationService locationService = new LocationService(rockContext);
                device.Locations.Clear();
                foreach (var loc in kioskType.Locations.ToList())
                {
                    var location = locationService.Get(loc.Id);
                    device.Locations.Add(location);
                }
                dirty = true;
            }

            if (this.IsUserAuthorized(Rock.Security.Authorization.ADMINISTRATE))
            {
                device.LoadAttributes();

                if (PageParameter("datetime").IsNotNullOrWhiteSpace())
                {
                    device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime"));
                }
                else
                {
                    device.SetAttributeValue("core_device_DebugDateTime", "");
                }
            }

            if (dirty)
            {
                rockContext.SaveChanges();
                device.SaveAttributeValues(rockContext);
                KioskDevice.Remove(device.Id);
            }

            LocalDeviceConfig.CurrentKioskId       = device.Id;
            LocalDeviceConfig.CurrentGroupTypeIds  = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList();
            LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId;

            CurrentCheckInState = null;
            CurrentWorkflow     = null;

            var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"];

            if (kioskTypeCookie == null)
            {
                kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId");
            }

            kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1);
            kioskTypeCookie.Value   = kiosk.KioskType.Id.ToString();

            this.Page.Response.Cookies.Set(kioskTypeCookie);

            Session["KioskTypeId"] = kioskType.Id;
            SaveState();
            return(kiosk);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Kiosk Kiosk = null;

            var rockContext      = new RockContext();
            var kioskService     = new KioskService(rockContext);
            var attributeService = new AttributeService(rockContext);

            int KioskId = int.Parse(hfKioskId.Value);

            if (KioskId != 0)
            {
                Kiosk = kioskService.Get(KioskId);
            }

            if (Kiosk == null)
            {
                // Check for existing
                var existingDevice = kioskService.Queryable()
                                     .Where(k => k.Name == tbName.Text)
                                     .FirstOrDefault();
                if (existingDevice != null)
                {
                    nbDuplicateKiosk.Text    = string.Format("A kiosk already exists with the name '{0}'. Please use a different device name.", existingDevice.Name);
                    nbDuplicateKiosk.Visible = true;
                }
                else
                {
                    Kiosk = new Kiosk();
                    kioskService.Add(Kiosk);
                }
            }


            if (Kiosk != null)
            {
                Kiosk.Name        = tbName.Text;
                Kiosk.Description = tbDescription.Text;
                Kiosk.IPAddress   = tbIPAddress.Text;

                if (!Kiosk.IsValid || !Page.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                //Save kiosk's checkin type
                Kiosk.KioskTypeId = ddlKioskType.SelectedValue.AsInteger();

                Kiosk.PrintToOverride = ( PrintTo )System.Enum.Parse(typeof(PrintTo), ddlPrintTo.SelectedValue);
                Kiosk.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
                Kiosk.PrintFrom       = ( PrintFrom )System.Enum.Parse(typeof(PrintFrom), ddlPrintFrom.SelectedValue);


                rockContext.SaveChanges();

                Rock.CheckIn.KioskDevice.FlushAll( );

                NavigateToParentPage();
            }
        }
        /// <summary>
        /// Redeem Points for Player.
        /// </summary>
        /// <param name="AccountNumber"></param>
        /// 
        /// <returns>List of prizes available</returns>
        public bool UpdateRedeempoints(string AcctNumber, string PrizeID, int PrizeQty, int redeempoints,LoginInfoDTO loginInfo,PlayerInfoDTO playerInfo)
        {
            bool IsReedemed = false;
            try
            {
                Dictionary<string, string> CMPDetails = playerInformationDataAccess.GetCMPCredentials(CommonDataAccess.ExchangeConnectionString);

                if (CMPDetails.Count > 0)
                {
                    kioskService = new KioskService(CMPDetails["CMPURL"].ToString());
                }

                RedeemPrizeInfo redeemPrizeInfo = new RedeemPrizeInfo();
                redeemPrizeInfo.AccountNumber = AcctNumber;
                redeemPrizeInfo.ComputerName = Environment.MachineName;
                redeemPrizeInfo.GamingDate = new DateTime(2001,1,1);
                redeemPrizeInfo.LocationCode = loginInfo.LocationCode;
                redeemPrizeInfo.PrintedRemarks = null;
                redeemPrizeInfo.PrivateRemarks = null;
                redeemPrizeInfo.PlayerId = playerInfo.PlayerID;
                redeemPrizeInfo.Password = CMPDetails["CMPPWD"];
                redeemPrizeInfo.Shift = 1;

                redeemPrizeInfo.UserName = CMPDetails["CMPUSER"];

                if (!String.IsNullOrEmpty(PrizeID))
                {
                    redeemPrizeInfo.PrizeId = PrizeID;
                }
                redeemPrizeInfo.PrizeQty = PrizeQty;
                redeemPrizeInfo.RedeemPoints = redeempoints * redeemPrizeInfo.PrizeQty;

                ServiceResult objServiceResult = (ServiceResult)kioskService.RedeemPoints(redeemPrizeInfo);

                if (MethodResult.Success == objServiceResult.Result)
                    IsReedemed = true;
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                IsReedemed = false;
            }
            return IsReedemed;
        }
        /// <summary>
        /// Get Login Information for the player
        /// </summary>
        /// 
        /// <returns>Login information for the player</returns>
        /// 
        public LoginInfoDTO GetLoginInformation()
        {
            Dictionary<string, string> CMPDetails = playerInformationDataAccess.GetCMPCredentials(CommonDataAccess.ExchangeConnectionString);

            loginInfo = new LoginInfo();
            loginInfo.ComputerName = Environment.MachineName;
            
            loginInfo.GamingDate = new DateTime(2001,01,01,0,0,0);
            
            loginInfo.LocationCode = null;
            loginInfo.Password = CMPDetails["CMPPWD"];
            loginInfo.Shift = 1;
            loginInfo.UserName = CMPDetails["CMPUSER"];

            if (CMPDetails.Count > 0)
            {
                kioskService = new KioskService(CMPDetails["CMPURL"].ToString());
            }

            serviceResult = kioskService.EmployeeLogin(loginInfo);

            if (MethodResult.Success == serviceResult.Result)
            {
                loginInfo.LocationCode = serviceResult.Data[0].ToString();
                DateTime gamingdate = DateTime.Today;
                if (true == DateTime.TryParse(serviceResult.Data[1].ToString(), out gamingdate))
                    loginInfo.GamingDate = gamingdate;
                else
                    loginInfo.GamingDate = DateTime.Today;

                loginInfo.Shift = int.Parse(serviceResult.Data[2].ToString());
            }
     
            List<LoginInfoDTO> LoginInfoList = new List<LoginInfoDTO>();

           
                LoginInfoDTO loginInfoDTO = new LoginInfoDTO();
                loginInfoDTO.ComputerName = loginInfo.ComputerName;
                loginInfoDTO.GamingDate = loginInfo.GamingDate;
                loginInfoDTO.LocationCode = loginInfo.LocationCode;
                loginInfoDTO.Password = loginInfo.Password;
                loginInfoDTO.Shift = loginInfo.Shift;
                loginInfoDTO.UserName = loginInfo.UserName;
            return loginInfoDTO;
        }
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var isMobile          = GetAttributeValue(action, "IsMobile").AsBoolean();
            var mobileDidAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_DID_ATTEND).Id;
            var mobileNotAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_NOT_ATTEND).Id;

            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                KioskService kioskService = new KioskService(rockContext);
                var          kioskTypeId  = kioskService.GetByClientName(checkInState.Kiosk.Device.Name).KioskTypeId;
                var          kioskType    = KioskTypeCache.Get(kioskTypeId.Value);
                var          campusId     = kioskType.CampusId;
                if (campusId == null)
                {
                    var compatableKioskType = KioskTypeCache.All().Where(kt => kt.CampusId.HasValue && kt.CheckinTemplateId == kioskType.CheckinTemplateId).FirstOrDefault();
                    if (compatableKioskType != null)
                    {
                        campusId = compatableKioskType.CampusId;
                    }
                    else
                    {
                        campusId = 0;
                    }
                }

                campusId = GetCampusOrFamilyCampusId(campusId, checkInState.CheckIn.CurrentFamily.Group.CampusId);


                AttendanceCode attendanceCode = null;
                DateTime       startDateTime  = Rock.RockDateTime.Now;
                DateTime       today          = startDateTime.Date;
                DateTime       tomorrow       = startDateTime.AddDays(1);

                bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode;
                int  securityCodeLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3;

                var attendanceCodeService = new AttendanceCodeService(rockContext);
                var attendanceService     = new AttendanceService(rockContext);
                var groupMemberService    = new GroupMemberService(rockContext);
                var personAliasService    = new PersonAliasService(rockContext);

                //This list is just for mobile check-in
                List <Attendance> attendances = new List <Attendance>();

                var family = checkInState.CheckIn.CurrentFamily;
                if (family != null)
                {
                    foreach (var person in family.GetPeople(true))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GetGroupTypes(true))
                        {
                            foreach (var group in groupType.GetGroups(true))
                            {
                                if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
                                    groupType.GroupType.DefaultGroupRoleId.HasValue &&
                                    !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any())
                                {
                                    var groupMember = new GroupMember();
                                    groupMember.GroupId     = group.Group.Id;
                                    groupMember.PersonId    = person.Person.Id;
                                    groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
                                    groupMemberService.Add(groupMember);
                                }

                                foreach (var location in group.GetLocations(true))
                                {
                                    foreach (var schedule in location.GetSchedules(true))
                                    {
                                        var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                        if (primaryAlias != null)
                                        {
                                            int groupId = ActualGroupId(group.Group);
                                            // If a like attendance service exists close it before creating another one.
                                            var oldAttendance = attendanceService.Queryable()
                                                                .Where(a =>
                                                                       a.StartDateTime >= today &&
                                                                       a.StartDateTime < tomorrow &&
                                                                       a.Occurrence.LocationId == location.Location.Id &&
                                                                       a.Occurrence.ScheduleId == schedule.Schedule.Id &&
                                                                       a.Occurrence.GroupId == groupId &&
                                                                       a.PersonAlias.PersonId == person.Person.Id)
                                                                .FirstOrDefault();

                                            if (oldAttendance != null)
                                            {
                                                oldAttendance.EndDateTime = Rock.RockDateTime.Now;
                                                oldAttendance.DidAttend   = false;
                                            }
                                            var attendance = attendanceService.AddOrUpdate(primaryAlias.Id, startDateTime.Date, groupId,
                                                                                           location.Location.Id, schedule.Schedule.Id, campusId ?? location.CampusId,
                                                                                           checkInState.Kiosk.Device.Id, checkInState.CheckIn.SearchType.Id,
                                                                                           checkInState.CheckIn.SearchValue, family.Group.Id, attendanceCode.Id);

                                            attendance.DeviceId                 = checkInState.Kiosk.Device.Id;
                                            attendance.SearchTypeValueId        = checkInState.CheckIn.SearchType.Id;
                                            attendance.SearchValue              = checkInState.CheckIn.SearchValue;
                                            attendance.CheckedInByPersonAliasId = checkInState.CheckIn.CheckedInByPersonAliasId;
                                            attendance.SearchResultGroupId      = family.Group.Id;
                                            attendance.AttendanceCodeId         = attendanceCode.Id;
                                            attendance.CreatedDateTime          = startDateTime;
                                            attendance.StartDateTime            = startDateTime;
                                            attendance.EndDateTime              = null;
                                            attendance.Note      = group.Notes;
                                            attendance.DidAttend = isMobile ? false : groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean();
                                            if (isMobile)
                                            {
                                                if (groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean())
                                                {
                                                    attendance.QualifierValueId = mobileDidAttendId;
                                                }
                                                else
                                                {
                                                    attendance.QualifierValueId = mobileNotAttendId;
                                                }
                                            }
                                            ;

                                            attendanceService.Add(attendance);
                                            attendances.Add(attendance);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (isMobile)
                {
                    var alreadyExistingMobileCheckin = MobileCheckinRecordCache.GetActiveByFamilyGroupId(checkInState.CheckIn.CurrentFamily.Group.Id);
                    if (alreadyExistingMobileCheckin != null)
                    {
                        //This should never run, it's just in case. Each family should only have 1 mobile check-in reservation.
                        MobileCheckinRecordCache.CancelReservation(alreadyExistingMobileCheckin, true);
                    }

                    campusId = RollUpToParentCampus(campusId);

                    MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext);
                    var mobileCheckinRecord = new MobileCheckinRecord
                    {
                        AccessKey             = "MCR" + Guid.NewGuid().ToString("N").Substring(0, 12),
                        ReservedUntilDateTime = Rock.RockDateTime.Now.AddMinutes(kioskType.MinutesValid ?? 10),
                        ExpirationDateTime    = Rock.RockDateTime.Now.AddMinutes((kioskType.MinutesValid ?? 10) + (kioskType.GraceMinutes ?? 60)),
                        UserName      = checkInState.CheckIn.SearchValue,
                        FamilyGroupId = checkInState.CheckIn.CurrentFamily.Group.Id,
                        CampusId      = campusId.Value
                    };

                    foreach (var attendance in attendances)
                    {
                        mobileCheckinRecord.Attendances.Add(attendance);
                    }

                    mobileCheckinRecordService.Add(mobileCheckinRecord);
                }

                rockContext.SaveChanges();
                foreach (var attendance in attendances)
                {
                    AttendanceCache.AddOrUpdate(attendance);
                }
                return(true);
            }
            errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null.");
            return(false);
        }
Exemple #18
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Kiosk kiosk = null;

            var rockContext      = new RockContext();
            var kioskService     = new KioskService(rockContext);
            var attributeService = new AttributeService(rockContext);

            int kioskId = int.Parse(hfKioskId.Value);

            if (kioskId != 0)
            {
                kiosk = kioskService.Get(kioskId);
            }

            if (kiosk == null)
            {
                // Check for existing
                var existingDevice = kioskService.Queryable()
                                     .Where(k => k.Name == tbName.Text)
                                     .FirstOrDefault();
                if (existingDevice != null)
                {
                    nbDuplicateKiosk.Text    = string.Format("A kiosk already exists with the name '{0}'. Please use a different device name.", existingDevice.Name);
                    nbDuplicateKiosk.Visible = true;
                }
                else
                {
                    kiosk = new Kiosk();
                    kioskService.Add(kiosk);
                }
            }


            if (kiosk != null)
            {
                kiosk.Name        = tbName.Text;
                kiosk.Description = tbDescription.Text;
                kiosk.IPAddress   = tbIPAddress.Text;

                if (!kiosk.IsValid || !Page.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                kiosk.CategoryId = pCategory.SelectedValueAsId();

                //Save kiosk's checkin type
                kiosk.KioskTypeId = ddlKioskType.SelectedValue.AsInteger();

                kiosk.PrintToOverride = ( PrintTo )System.Enum.Parse(typeof(PrintTo), ddlPrintTo.SelectedValue);
                kiosk.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
                kiosk.PrintFrom       = ( PrintFrom )System.Enum.Parse(typeof(PrintFrom), ddlPrintFrom.SelectedValue);

                if (tbAccessKey.Text.IsNullOrWhiteSpace())
                {
                    kiosk.AccessKey = Guid.NewGuid().ToString();
                }
                else
                {
                    kiosk.AccessKey = tbAccessKey.Text;
                }

                rockContext.SaveChanges();

                DeviceService deviceService = new DeviceService(rockContext);
                var           devices       = deviceService.Queryable().Where(d => d.Name == kiosk.Name).ToList();
                foreach (var device in devices)
                {
                    KioskDeviceHelpers.FlushItem(device.Id);
                }

                NavigateToParentPage();
            }
        }
        private void ActivateKiosk(Kiosk kiosk, bool logout)
        {
            RockContext   rockContext   = new RockContext();
            DeviceService deviceService = new DeviceService(rockContext);
            KioskService  kioskService  = new KioskService(rockContext);

            //The kiosk can come in a variety of states.
            //Get a fresh version with our context to avoid context errors.
            kiosk = kioskService.Get(kiosk.Id);

            //Load matching device and update or create information
            var device = deviceService.Queryable().Where(d => d.Name == kiosk.Name).FirstOrDefault();

            //create new device to match our kiosk
            if (device == null)
            {
                device = new Device();
                device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id;
                device.Name = kiosk.Name;
                deviceService.Add(device);
            }

            device.LoadAttributes();
            device.IPAddress = kiosk.IPAddress;
            device.Locations.Clear();
            foreach (var loc in kiosk.KioskType.Locations.ToList())
            {
                device.Locations.Add(loc);
            }
            device.PrintFrom       = kiosk.PrintFrom;
            device.PrintToOverride = kiosk.PrintToOverride;
            device.PrinterDeviceId = kiosk.PrinterDeviceId;
            rockContext.SaveChanges();

            if (PageParameter("DateTime").AsDateTime().HasValue)
            {
                device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime"));
            }
            else
            {
                device.SetAttributeValue("core_device_DebugDateTime", "");
            }
            device.SaveAttributeValues(rockContext);

            LocalDeviceConfig.CurrentKioskId       = device.Id;
            LocalDeviceConfig.CurrentGroupTypeIds  = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList();
            LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId;

            CurrentCheckInState = null;
            CurrentWorkflow     = null;

            var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"];

            if (kioskTypeCookie == null)
            {
                kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId");
            }

            kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1);
            kioskTypeCookie.Value   = kiosk.KioskType.Id.ToString();

            this.Page.Response.Cookies.Set(kioskTypeCookie);

            Session["KioskTypeId"]  = kiosk.KioskType.Id;
            Session["KioskMessage"] = kiosk.KioskType.Message;

            //Clean things up so we have the freshest possible version.
            KioskTypeCache.Remove(kiosk.KioskTypeId ?? 0);
            KioskDevice.Remove(device.Id);

            Dictionary <string, string> pageParameters = new Dictionary <string, string>();

            if (kiosk.KioskType.Theme.IsNotNullOrWhiteSpace() && !GetAttributeValue("Manual").AsBoolean())
            {
                LocalDeviceConfig.CurrentTheme = kiosk.KioskType.Theme;
                pageParameters.Add("theme", LocalDeviceConfig.CurrentTheme);
            }

            if (logout)
            {
                pageParameters.Add("logout", "true");
            }

            SaveState();

            NavigateToNextPage(pageParameters);
        }