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();
        }
Exemple #2
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);


                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();
            }
        }