protected void Submit_Click(object sender, EventArgs e)
        {
            using (var db = new AzureNOLBContext())
            {
                var location = db.Locations
                               .Where(x => x.StreetAddress == txtStreetAddress.Text.Trim() &&
                                      x.City == txtCity.Text.Trim() &&
                                      x.State == txtState.Text.Trim() &&
                                      x.Floor == txtFloor.Text.Trim() &&
                                      x.RoomNumber == txtRoom.Text.Trim())
                               .SingleOrDefault();

                if (location == null)
                {
                    location = new Location
                    {
                        City          = txtCity.Text.Trim(),
                        Floor         = txtFloor.Text.Trim(),
                        RoomNumber    = txtRoom.Text.Trim(),
                        StreetAddress = txtStreetAddress.Text.Trim(),
                        State         = txtState.Text.Trim()
                    };
                }

                var newRequest = new Request
                {
                    TypeOfEmergency         = hdnTypeOfEmergency.Value,
                    NumberOfPeople          = int.TryParse(hdnNumOfPeople.Value, out int numOfPeople) ? numOfPeople : 0,
                    NumberOfImmobilePeople  = int.TryParse(hdnNumOfImmobilePeople.Value, out int numOfImmobile) ? numOfImmobile : 0,
                    InjuriesOrOtherInfo     = txtInjuriesOrSpecialInfo.Text,
                    AccessibleOutsideWindow = cbOutsideWindow.Checked,
                    FirstName   = txtFirstName.Text,
                    LastName    = txtLastName.Text,
                    PhoneNumber = txtPhone.Text,
                    Latitude    = decimal.TryParse(txtLatitude.Text, out decimal latitude) ? latitude : 0.0M,
                    Longitude   = decimal.TryParse(txtLongitude.Text, out decimal longitude) ? longitude : 0.0M,
                    Location    = location
                };

                var datetime         = DateTimeOffset.Parse(hdnDateTime.Value);
                var adjustedDatetime = datetime.AddHours(int.Parse(hdnTimeOffset.Value));
                newRequest.TimeStamp = adjustedDatetime;

                db.Requests.Add(newRequest);
                db.SaveChanges();

                lblMessage.Text = "Request Successfully Submitted.";

                hdnDateTime.Value        = DateTimeOffset.Now.ToString();
                hdnTypeOfEmergency.Value = "Unknown";
            }
        }
        protected void RequestDataList_OnItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "ClearRequest")
            {
                var id = int.Parse(e.CommandArgument.ToString());

                using (var db = new AzureNOLBContext())
                {
                    var item = db.Requests.SingleOrDefault(x => x.RequestID == id);

                    if (item == null)
                    {
                        return;
                    }
                    else
                    {
                        item.Cleared = true;
                        db.SaveChanges();
                    }
                }
            }
        }
        public void GetRequestData()
        {
            if (LoggedInPanel.CssClass.Contains("no-display"))
            {
                return;
            }

            var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();

            var user = manager.FindByName(Context.User.Identity.Name);

            if (user != null)
            {
                if (user.GrantedDispatchAccess)
                {
                    if (IsPostBack)
                    {
                        var topLimit    = Convert.ToDecimal(hdnMapTopRightLat.Value);
                        var rightLimit  = Convert.ToDecimal(hdnMapTopRightLong.Value);
                        var bottomLimit = Convert.ToDecimal(hdnMapBottomLeftLat.Value);
                        var leftLimit   = Convert.ToDecimal(hdnMapBottomLeftLong.Value);
                        var db          = new AzureNOLBContext();
                        var date        = DateTime.Now.AddDays(-1);
                        var requests    = db.Requests.Include(x => x.Location)
                                          .Where(x => !x.Cleared && x.TimeStamp > date)
                                          .Where(x => x.Latitude <= topLimit && x.Latitude >= bottomLimit &&
                                                 x.Longitude >= leftLimit && x.Longitude <= rightLimit)
                                          .OrderByDescending(x => x.TimeStamp).ToList();
                        //.GroupBy(x => x.LocationID)
                        //.Select(x => x.OrderByDescending(y => y.TimeStamp).FirstOrDefault()).OrderByDescending(x => x.TimeStamp);
                        var requestIds = requests.Select(x => x.RequestID)
                                         .ToList();
                        var lastRequestIds = new List <int>();
                        if (this.Session["LastRequests"] != null)
                        {
                            lastRequestIds = ((List <Request>) this.Session["LastRequests"]).Select(x => x.RequestID)
                                             .ToList();
                        }
                        var hasShownData = (bool)(Session["HasShownData"] ?? false);
                        if (!ScrambledEquals(lastRequestIds, requestIds) || lastRequestIds.Count == 0 || !hasShownData)
                        {
                            this.Session["LastRequests"] = requests;
                            RequestDataList.DataSource   = requests;
                            RequestDataList.DataBind();
                            var coords = requests.Select(x => new
                            {
                                Lat = x.Latitude, Long = x.Longitude, description = x.GetDescription()
                            }).ToList();

                            hdnCoords.Value = Newtonsoft.Json.JsonConvert.SerializeObject(coords);
                            ScriptManager.RegisterStartupScript(this, GetType(), "showLocations", "showLocations();",
                                                                true);
                            Session["HasShownData"] = true;
                            if (!requests.Any())
                            {
                                lblMessage.Text = "No uncleared requests have been submitted in the last 24 hours.";
                            }
                        }
                    }

                    NoAccessPanel.CssClass = " no-display";
                    LoggedInPanel.CssClass = "";
                }
                else
                {
                    NoAccessPanel.CssClass = "";
                    LoggedInPanel.CssClass = "no-display";
                    lblNoAccess.Text       = "You must request access to view this page. <a href=\"/Account/Manage\">Go to account management to request access.</a>";
                }
            }
            else
            {
                NoAccessPanel.CssClass = "";
                LoggedInPanel.CssClass = "no-display";
                lblNoAccess.Text       = "You must be logged into to view this page.";
            }
        }
Exemple #4
0
        protected void btnSubmit_ClickQR(object sender, EventArgs e)
        {
            //Creates New Instance of a QR
            using (var qrCode = new QRCodeGenerator())
            {
                var qrCodeString = GenerateQrCodeString();
                //Append URL to qrCode
                var dataURL = qrCode.CreateQrCode(qrCodeString, QRCodeGenerator.ECCLevel.Q);
                using (var code = new QRCode(dataURL))
                {
                    //Images qrCode and determines dimmensions
                    var imgBarCode = new System.Web.UI.WebControls.Image
                    {
                        Height = 400,
                        Width  = 400
                    };
                    using (Bitmap bitMap = code.GetGraphic(20))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            bitMap.Save(ms, ImageFormat.Png);
                            var byteImage = ms.ToArray();
                            imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                        }
                        PlaceHolder1.Controls.Add(imgBarCode);
                        SetAddressLabel();
                    }
                    //Images qrCode and determines dimmensions
                    var imgBarCodePrint = new System.Web.UI.WebControls.Image
                    {
                        Height = 800,
                        Width  = 800
                    };
                    using (Bitmap bitMap = code.GetGraphic(20))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            bitMap.Save(ms, ImageFormat.Png);
                            var byteImage = ms.ToArray();
                            imgBarCodePrint.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                        }
                        PlaceHolder2.Controls.Add(imgBarCodePrint);
                        SetAddressLabel();
                    }
                }
            }

            using (var db = new AzureNOLBContext())
            {
                var location = db.Locations
                               .Where(x => x.StreetAddress == txtStreetAddress.Text.Trim() &&
                                      x.City == txtCity.Text.Trim() &&
                                      x.State == txtState.Text.Trim() &&
                                      x.Floor == txtFloor.Text.Trim() &&
                                      x.RoomNumber == txtRoom.Text.Trim())
                               .SingleOrDefault();

                if (location == null)
                {
                    location = new Location
                    {
                        City          = txtCity.Text.Trim(),
                        Floor         = txtFloor.Text.Trim(),
                        RoomNumber    = txtRoom.Text.Trim(),
                        StreetAddress = txtStreetAddress.Text.Trim(),
                        State         = txtState.Text.Trim()
                    };

                    db.Locations.Add(location);
                    db.SaveChanges();
                }
            }
        }