public override bool IsUserInRole(string username, string roleName)
 {
     if (roleName == Roles.admin.ToString())
     {
         using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
         {
             if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); }
             return dc.User.Any(u => u.Email == username && u.IsAdmin);
         }
     }
     return false;
 }
 protected void btnFilterReported_Click(object sender, EventArgs e)
 {
     CurrentSiteStateFilter = SiteState.Reported;
     btnFilterNone.Font.Bold = false; txtNumSitesTotal.Font.Bold = false;
     btnFilterReported.Font.Bold = true; txtNumReportedSites.Font.Bold = true;
     btnFilterBroken.Font.Bold = false; txtNumBrokenSites.Font.Bold = false;
     using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
     {
         if (dc.DatabaseExists())
         {
             BindGrid(dc);
         }
     }
 }
 public override bool ValidateUser(string username, string password)
 {
     using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
     {
         if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); }
         var result = dc.User.Any(u => u.Email == username && u.Password == password);
         return result;
     }
 }
 public override string GetPassword(string username, string answer)
 {
     using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
     {
         if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); }
         return (from u in dc.User where u.Email == username select u.Password).First();
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
                {
                    if (dc.DatabaseExists())
                    {
                        txtNumSitesTotal.Text = dc.Site.Count().ToString();
                        txtNumReportedSites.Text = dc.Site.Count(s => s.State == SiteState.Reported).ToString();
                        txtNumBrokenSites.Text = dc.Site.Count(s => s.State == SiteState.Broken).ToString();

                        BindGrid(dc);
                    }
                }
            }
        }
 protected void siteOverview_Sorting(object sender, GridViewSortEventArgs e)
 {
     CurrentSortingProperty = e.SortExpression;
     using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
     {
         if (dc.DatabaseExists())
         {
             BindGrid(dc);
         }
     }
 }
예제 #7
0
        private void BindGrid()
        {
            using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
            {
                if (dc.DatabaseExists())
                {
                    var site = dc.Site.FirstOrDefault(s => s.Name == this.Request.Params["site"]);
                    if (site != null)
                    {
                        btnDeleteSite.Visible =
                            (User.Identity.Name == site.Owner_FK &&
                            site.State == SiteState.Broken &&
                            (DateTime.Now - dc.Report.Where(r => r.Site_FK == this.Request.Params["site"] && r.Type == ReportType.ConfirmedBroken).OrderByDescending(r => r.Date).Select(r => r.Date).FirstOrDefault()).TotalDays > 10)
                            || User.IsInRole("admin");
                        reports.ShowFooter = User.Identity.Name == site.Owner_FK || User.IsInRole("admin");

                        reports.Columns[reports.Columns.Count - 1].Visible = User.Identity.Name == site.Owner_FK || User.IsInRole("admin");
                        var reportsQuery = from a in dc.Report where a.Site_FK == this.Request.Params["site"] select new { Message = a.Message, Type = a.Type, Date = a.Date, };
                        reportsQuery = reportsQuery.OrderByDescending(s => s.Date);
                        var result = (List<Report>)reportsQuery.ToList().ToNonAnonymousList(typeof(Report));
                        if (result.Count == 0) result.Add(null); // hack to make ASP.NET < 4 show header and footer when empty data
                        reports.DataSource = result;
                        reports.DataBind();
                    }
                }
            }
        }