Esempio n. 1
0
        protected void NewAlbumButton_Click(object sender, EventArgs e)
        {
            if (!Roles.IsUserInRole("family"))
            {
                ErrorMessage.Text = "<p class=\"errormsg\">Error: You do not have enough permissions to create an album.</p>";
                ErrorMessage.Visible = true;
                return;
            }

            // Add album to database
            using (var db = new NietoYostenDbDataContext())
            {
                var newAlbum = new Album()
                    {
                        Title = AlbumTitle.Text,
                        FolderName = AlbumFolder.Text
                    };
                db.Albums.InsertOnSubmit(newAlbum);
                db.SubmitChanges();
            }
            // Create folders for album
            //string originalDir = Server.MapPath(string.Format("~/pictures/original/{0}", AlbumFolder.Text));
            Directory.CreateDirectory(Server.MapPath(string.Format("~/pictures/original/{0}", AlbumFolder.Text)));
            Directory.CreateDirectory(Server.MapPath(string.Format("~/pictures/web/{0}", AlbumFolder.Text)));
            Directory.CreateDirectory(Server.MapPath(string.Format("~/pictures/thumb/{0}", AlbumFolder.Text)));

            Response.Redirect("~/Pictures.aspx");
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int pictureId = 0;
            if (!int.TryParse(Page.Request.QueryString["PictureId"], out pictureId)) return;

            using (var db = new NietoYostenDbDataContext())
            {
                var pic = db.Pictures.FirstOrDefault(a => a.Id == pictureId);
                if (pic == null) return;

                string albumFolderName = pic.Album.FolderName;

                PageImage.ImageUrl = string.Format(
                    "~/pictures/web/{0}/{1}",
                    albumFolderName,
                    pic.FileName);

                PicTitle.Text = pic.Title;

                DownloadOriginalLink.NavigateUrl = string.Format(
                    "~/pictures/original/{0}/{1}",
                    albumFolderName,
                    pic.FileName);
            }
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string sectionName = Page.RouteData.Values["SectionName"].ToString();

            int pageNum = GetPageNum();
            int articlesPerPage = int.Parse(ConfigurationManager.AppSettings["articlesPerPage"]);
            int startAtArticle = (pageNum - 1) * articlesPerPage + 1;

            // Create datasource for repeater based on page number
            NietoYostenDbDataContext db = new NietoYostenDbDataContext();
            Section section = db.Sections.Single(s => s.Name == sectionName);
            int sectionId = section.SectionId;
            litPageName.Text = section.Name;

            var q =
                from c in db.Articles
                join user in db.aspnet_Users on c.CreatedBy equals user.UserId
                where c.SectionId == sectionId
                where c.Published == true
                orderby c.DateCreated descending
                select new { c.ArticleId, c.Title, c.IntroText, c.DateCreated, user.UserName,
                     HasNoContent = String.IsNullOrEmpty(c.Content) };

            rptArticles.DataSource = q.Skip(startAtArticle - 1).Take(articlesPerPage);
            rptArticles.DataBind();

            int totalPages = (int)System.Math.Ceiling((double)q.Count() / (double)articlesPerPage);
            rptPaginationLinks.DataSource = GetPaginationLinks(sectionName, pageNum, articlesPerPage, totalPages);
            rptPaginationLinks.DataBind();
        }
Esempio n. 4
0
        public static UploadPictureDto BeginFileUpload(int albumId, string fileName, string base64Data)
        {
            if (!Roles.IsUserInRole("family"))
            {
                return new UploadPictureDto { fileName = null, folderName = null, position = 0,
                    errorMsg = "Current user is not allowed to upload pictures." };
            }

            string folderName = null;
            using (var db = new NietoYostenDbDataContext())
            {
                var album = db.Albums.FirstOrDefault(x => x.Id == albumId);
                folderName = album.FolderName;
            }

            long position = 0;
            using (var fs = File.Create(GetTempFilePath(fileName)))
            {
                byte[] data = Convert.FromBase64String(base64Data);
                fs.Write(data, 0, data.Length);
                position = fs.Position;
            }

            return new UploadPictureDto {fileName = fileName, folderName = folderName, position = position };
        }
Esempio n. 5
0
        protected void DeleteAlbum(NietoYostenDbDataContext db, int albumId)
        {
            // Delete pictures in album, if any
            var album = db.Albums.SingleOrDefault(a => a.Id == albumId);
            foreach (var picture in album.Pictures)
            {
                NyUtil.DeletePicture(db, Server, picture.Id);
            }

            // Delete album folders (thumb, web, original)
            string[] folders = {"thumb", "web", "original"};

            foreach (var folder in folders)
            {
                string pictureFolder = Server.MapPath(string.Format(
                    "~/pictures/{0}/{1}", folder, album.FolderName));
                if (System.IO.Directory.Exists(pictureFolder))
                {
                    System.IO.Directory.Delete(pictureFolder);
                }
            }

            // Remove album from DB
            db.Albums.DeleteOnSubmit(album);
        }
Esempio n. 6
0
        protected IEnumerable<Thumbnail[]> GetThumbnailRowSet(int albumId)
        {
            List<Thumbnail[]> rows = new List<Thumbnail[]>();

            using (var db = new NietoYostenDbDataContext())
            {
                // Get all pictures in album
                var pics = from c in db.Pictures
                           where c.AlbumId == albumId
                           select c;

                // Get album folder name
                string folderName = db.Albums.FirstOrDefault(a => a.Id == albumId).FolderName;

                // Iterate through the album pictures to create datasource for the thumbnail grid (a list of Thumbnail arrays)
                int currentRow = 0;
                int currentCol = 0;
                Thumbnail[] workingRow = null;

                foreach (var pic in pics)
                {
                    if (workingRow == null)
                    {
                        // Start new row
                        workingRow = new Thumbnail[NumThumbnailsPerRow];
                        for (int i = 0; i < NumThumbnailsPerRow; i++)
                        {
                            workingRow[i] = new Thumbnail { Empty = true };
                        }
                        workingRow[0].AlphaOmega = "alpha";
                        workingRow[NumThumbnailsPerRow - 1].AlphaOmega = "omega";
                    }

                    // Fill data for current picture
                    workingRow[currentCol].PictureId = pic.Id;
                    workingRow[currentCol].RelativePath = string.Format(
                            "pictures/thumb/{0}/{1}", folderName, pic.FileName);
                    workingRow[currentCol].Title = pic.Title;
                    workingRow[currentCol].Empty = false;

                    // Move to column, row cursors for next picture
                    currentCol++;
                    if (currentCol >= NumThumbnailsPerRow)
                    {
                        // Move to next row
                        currentCol = 0;
                        currentRow++;

                        // Add working row and clear for next row
                        rows.Add(workingRow);
                        workingRow = null;
                    }
                }
                if (workingRow != null)
                {
                    rows.Add(workingRow);
                }
            }
            return rows;
        }
Esempio n. 7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         NietoYostenDbDataContext db = new NietoYostenDbDataContext();
         WeblinkCategory wcat = db.WeblinkCategories.Single(w => w.Id.ToString() == Request.QueryString["catId"]);
         litHeading.Text = "Links - " + wcat.Name;
     }
 }
Esempio n. 8
0
        public static string EndFileUpload(string folderName, string fileName)
        {
            if (!Roles.IsUserInRole("family"))
            {
                return "Error: Current user is not allowed to upload pictures.";
            }

            string originalPicFile = Path.Combine(
                HttpContext.Current.Server.MapPath("~/pictures/original/" + folderName),
                fileName);

            try
            {
                File.Copy(GetTempFilePath(fileName), originalPicFile);
            }
            catch (IOException)
            {
                return "Error: file with same name already exists in this album.";
            }
            finally
            {
                File.Delete(GetTempFilePath(fileName));
            }

            // Create and save web-sized image
            string webPicFile = HttpContext.Current.Server.MapPath(string.Format(
                "~/pictures/web/{0}/{1}", folderName, fileName));
            ResizeImage(originalPicFile, webPicFile, 640);

            // Create and save thumbnail-sized image
            string thumbPicFile = HttpContext.Current.Server.MapPath(string.Format(
                "~/pictures/thumb/{0}/{1}", folderName, fileName));
            ResizeImage(originalPicFile, thumbPicFile, 120);

            // Add picture to the database
            using (var db = new NietoYostenDbDataContext())
            {
                var album = db.Albums.FirstOrDefault(x => x.FolderName == folderName);

                var picture = new Picture();
                picture.AlbumId = album.Id;

                picture.FileName = fileName;
                picture.Title = fileName;

                db.Pictures.InsertOnSubmit(picture);
                db.SubmitChanges();
            }
            return "Upload successful";
        }
Esempio n. 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Set facebook app id on form
                fbAppId.Value = ConfigurationManager.AppSettings["FacebookAppId"];

                if (!string.IsNullOrEmpty(Request.Form["signed_request"]))
                {
                    var signedRequest = Request.Form["signed_request"];

                    bool isValid = FacebookUtil.ValidateSignedRequest(signedRequest);
                    if (!isValid)
                    {
                        return;
                    }

                    string fbUserId = FacebookUtil.GetFacebookUserId(signedRequest);

                    using (var db = new NietoYostenDbDataContext())
                    {
                        var userNameQuery = from u in db.aspnet_Users
                                       join fbu in db.FacebookUserIds on u.UserId equals fbu.UserId
                                            where fbu.FbUid == fbUserId
                                       select u.UserName;

                        var userName = userNameQuery.FirstOrDefault();

                        // If FB login was successful but user is not in DB, then redirect to Registration page
                        if (null == userName)
                        {
                            Response.Redirect("~/FbRegister.aspx");
                            return;
                        }

                        // Otherwise log in user
                        FormsAuthentication.RedirectFromLoginPage(userName, true);
                    }
                }
            }
            else
            {

            }
        }
Esempio n. 10
0
        protected void DeleteAlbumButton_Click(object sender, EventArgs e)
        {
            if (!Roles.IsUserInRole("family"))
            {
                ErrorMessage.Text = "<p class=\"errormsg\">Error: You do not have enough permissions to delete an album.</p>";
                ErrorMessage.Visible = true;
                return;
            }

            if (DeleteAlbumConfirmed.Value == "true")
            {
                var selAlbums = GetSelectedAlbums();
                using (var db = new NietoYostenDbDataContext())
                {
                    foreach (int albumId in selAlbums)
                    {
                        DeleteAlbum(db, albumId);
                    }
                    db.SubmitChanges();
                }
                Response.Redirect(Request.RawUrl);
            }
        }
Esempio n. 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NietoYostenDbDataContext db = new NietoYostenDbDataContext();
                int articleId = 0;
                if (!int.TryParse(Page.Request.QueryString["id"], out articleId)) return;

                Article article;
                if (db.Articles.Count(a => a.ArticleId == articleId) == 1)
                {
                    article = db.Articles.SingleOrDefault(a => a.ArticleId == articleId);
                }
                else
                {
                    return;
                }
                aspnet_User user = db.aspnet_Users.Single(u => u.UserId == article.CreatedBy);

                litArticleDate.Text = string.Format("{0:D}<br />Created by {1}", article.DateCreated, user.UserName);
                litTitle.Text = article.Title;
                litContent.Text = article.IntroText + article.Content;
            }
        }
Esempio n. 12
0
        public static void CreateIndexThreadProc()
        {
            lock (myLock)
            {
                IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);

                // Clear the index
                writer.DeleteAll();

                int count = 0;
                NietoYostenDbDataContext db = new NietoYostenDbDataContext();
                foreach (Article article in db.Articles)
                {
                    Document doc = ArticleToDocument(article);
                    writer.AddDocument(doc);
                    count++;
                }

                // Commit documents to index
                writer.Optimize();
                writer.Commit();
                writer.Close();
            }
        }
Esempio n. 13
0
        protected void DeletePicture_Click(object sender, EventArgs e)
        {
            if (!Roles.IsUserInRole("family"))
            {
                ErrorMessage.Text = "<p class=\"errormsg\">Error: You do not have enough permissions to delete pictures.</p>";
                ErrorMessage.Visible = true;
                return;
            }

            if (DeleteConfirmed.Value == "true")
            {
                var selPics = GetSelectedPictures();

                using (var db = new NietoYostenDbDataContext())
                {
                    foreach (int pictureId in selPics)
                    {
                        NyUtil.DeletePicture(db, Server, pictureId);
                    }
                    db.SubmitChanges();
                }
                Response.Redirect(Request.RawUrl);
            }
        }
Esempio n. 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.Form["signed_request"]))
                {
                    string signedRequest = Request.Form["signed_request"];

                    if (!FacebookUtil.ValidateSignedRequest(signedRequest)) return;

                    var regInfo = FacebookUtil.GetRegistrationInfo(signedRequest);

                    // Check if user is already registered on the site (just re-connecting to the app)
                    bool alreadyRegistered = false;
                    string userName = null;

                    using (var db = new NietoYostenDbDataContext())
                    {
                        if (db.FacebookUserIds.Any(x => x.FbUid == regInfo.UserId))
                        {
                            // Nothing to do here other than log the user in
                            alreadyRegistered = true;
                            userName = FacebookUtil.GetUserNameFromFbUid(db, regInfo.UserId);
                        }
                    }
                    if (alreadyRegistered)
                    {
                        FormsAuthentication.RedirectFromLoginPage(userName, true);
                        return;
                    }

                    // Merge with site user if necessary
                    var existingUser = Membership.GetUserNameByEmail(regInfo.Email);
                    if (!string.IsNullOrEmpty(existingUser))
                    {
                        var aspnetUser = Membership.GetUser(existingUser);
                        var userId = new FacebookUserId()
                            {
                                UserId = (Guid) aspnetUser.ProviderUserKey,
                                FbUid = regInfo.UserId
                            };
                        using (var db = new NietoYostenDbDataContext())
                        {
                            db.FacebookUserIds.InsertOnSubmit(userId);
                            db.SubmitChanges();
                        }

                        // Login user after doing the merge
                        FormsAuthentication.RedirectFromLoginPage(aspnetUser.UserName, true);
                        return;
                    }
                    else
                    {
                        // Create new user
                        MembershipCreateStatus createStatus;
                        var password = "******";
                        var newUser = Membership.CreateUser(regInfo.UserName, password, regInfo.Email, null, null, true, Guid.NewGuid(), out createStatus);

                        // Grant role to user: default to friend for now
                        // TODO: Grant role based on membership to NY family Facebook group
                        Roles.AddUserToRole(newUser.UserName, "friend");

                        switch (createStatus)
                        {
                            case MembershipCreateStatus.Success:
                                var userId = new FacebookUserId()
                                    {
                                        UserId = (Guid) newUser.ProviderUserKey,
                                        FbUid = regInfo.UserId
                                    };
                                using (var db = new NietoYostenDbDataContext())
                                {
                                    db.FacebookUserIds.InsertOnSubmit(userId);
                                    db.SubmitChanges();
                                }
                                FormsAuthentication.RedirectFromLoginPage(newUser.UserName, true);
                                break;

                            default:
                                Response.Redirect("FbRegister.aspx?facebook_result=success");
                                break;
                        }
                    }
                }
            }
        }
Esempio n. 15
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         using (var db = new NietoYostenDbDataContext())
         {
             rptAlbums.DataSource = db.Albums;
             rptAlbums.DataBind();
         }
     }
 }