Example #1
0
        public ActionResult Index()
        {
            Entities dbContext = new Entities();
            string myId = UserHelper.getLoggedInUserId();
            if(myId == null)
            {
                return RedirectToAction("Index", "Default");
            }
            Guid userGuid = new Guid(myId);

            var friendsOf = from fo in dbContext.Friendships
                            where fo.FriendId == userGuid && fo.Status == 1
                            select fo.UserId;

            var friendsWith = from fw in dbContext.Friendships
                              where fw.UserId == userGuid && fw.Status == 1
                              select fw.FriendId;

            /*var posts = from p in dbContext.Posts
                        where p.UserId == userGuid || friendsOf.Contains(p.UserId) || friendsWith.Contains(p.UserId)
                        select p;*/

            var posts = dbContext.Posts.Where(p => p.UserId == userGuid || p.PersonId == userGuid || friendsOf.Contains(p.UserId) || friendsWith.Contains(p.UserId)).OrderByDescending(p=>p.CreatedAt).ToList();

            //List ids = new List();

            //var posts = dbContext.Posts.Where(p => p.UserId == userGuid OR p.UserId in ids);

            ViewBag.posts = posts;
            if (posts != null)
                return View();
            else
                return Content("posts is null");//debugging
        }
Example #2
0
        public static bool AreFriends(Guid UserId, Guid SubjectId)
        {
            Entities dbContext = new Entities();
            Friendship friendship = dbContext.Friendships.SingleOrDefault(f => f.Status == 1 && ((f.UserId == UserId && f.FriendId == SubjectId) || (f.UserId == SubjectId && f.FriendId == UserId)));

            return friendship != null;
        }
Example #3
0
        public static bool HasFriendRequest(Guid UserId, Guid SubjectId)
        {
            Entities dbContext = new Entities();
            Friendship friendship = dbContext.Friendships.SingleOrDefault(f => f.Status == 0 && f.UserId == UserId && f.FriendId == SubjectId);

            return friendship != null;
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType = "text/xml";
            XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
            objX.WriteStartDocument();
            objX.WriteStartElement("rss");
            objX.WriteAttributeString("version","2.0");
            objX.WriteStartElement("channel");
            objX.WriteElementString("title", "Nuevo developer news");
            objX.WriteElementString("link",Request.ApplicationPath.TrimEnd('/') + "/News.aspx");
            objX.WriteElementString("description","The latest developer news from Nuevo.");
            objX.WriteElementString("copyright","(c) 2020, Nuevo, LLC. All rights reserved.");
            objX.WriteElementString("ttl","5");

            Entities dbContext = new Entities();
            var articles = dbContext.Articles.OrderBy(a => a.CreatedAt).ToList();

            foreach(Article article in articles)
            {
                objX.WriteStartElement("item");
                objX.WriteElementString("title", article.Title);
                objX.WriteElementString("description", article.Content.Length > 150 ? article.Content.Substring(0, 149)+"..." : article.Content);
                objX.WriteElementString("link", Request.ApplicationPath.TrimEnd('/') + "/Article.aspx?Id=" + article.Id.ToString());
                objX.WriteElementString("pubDate", article.CreatedAt.ToString());
                objX.WriteEndElement();
            }

            objX.WriteEndElement();
            objX.WriteEndElement();
            objX.WriteEndDocument();
            objX.Flush();
            objX.Close();
            Response.End();
        }
Example #5
0
        public ActionResult CreateAlbum(AlbumModel model)
        {
            if (ModelState.IsValid)
            {
                try {
                    Entities dbContext = new Entities();

                    Models.Object obj = new Models.Object();
                    obj.EntityName = "Album";
                    dbContext.Objects.AddObject(obj);
                    dbContext.SaveChanges();

                    Album album = new Album();
                    album.Id = obj.Id;
                    album.UserId = new Guid(UserHelper.getLoggedInUserId());
                    album.Name = model.Name;
                    album.Description = model.Description;
                    album.CreatedAt = DateTime.Now;

                    dbContext.Albums.AddObject(album);

                    dbContext.SaveChanges();

                    return RedirectToAction("Upload", "Photo");

                }catch(Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return View(model);
        }
Example #6
0
        public ActionResult Output(string photoId = "", string width="", string height="")
        {
            int xw;
            int xh;

            int w = 200;
            int h = 200;

            if(int.TryParse(width, out xw) && int.TryParse(height, out xh))
            {
                w = xw;
                h = xh;
            }
            try
            {
                int pid;
                if(!int.TryParse(photoId, out pid))
                {
                    throw new Exception("Invalid photo id specified.");
                }

                Entities dbContext = new Entities();

                var photo = dbContext.Photos.SingleOrDefault(p => p.Id == pid);

                if(photo == null)
                {
                    throw new Exception("The image does not exist.");
                }
                string path = Path.Combine(HttpContext.Server.MapPath("~/Uploads"), photo.FilePath);
                Image image = Image.FromFile(path);

                var abort = new Image.GetThumbnailImageAbort(ThumbnailCallback);

                var thumbnail = image.GetThumbnailImage(w,h,abort,IntPtr.Zero);

                using (Graphics g = Graphics.FromImage(thumbnail))
                {
                    Font drawFont = new Font("Arial", 5);
                    SolidBrush drawBrush = new SolidBrush(Color.DarkMagenta);
                    PointF stringPonit = new PointF(0, 0);

                    g.DrawString("Nuevo", drawFont, drawBrush, stringPonit);
                }
                MemoryStream ms = new MemoryStream();

                thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                thumbnail.Dispose();
                image.Dispose();
                return File(ms.ToArray(), "image/png");

            }catch(Exception ex)
            {
                return Content(ex.Message);
            }
        }
Example #7
0
        public static bool CanSeeWall(Guid UserId, Guid SubjectId)
        {
            Entities dbContext = new Entities();
            UserPrivacy privacy = dbContext.UserPrivacies.SingleOrDefault(p => p.UserId == UserId);
            if(privacy == null || privacy.SeeMyWall == 0)
            {
                return true;
            }

            return FriendshipHelper.AreFriends(UserId, SubjectId) || UserId == SubjectId;
        }
Example #8
0
        public ActionResult Curate(string friendshipId, string option = "")
        {
            try
            {
                int fid;
                if (!int.TryParse(friendshipId, out fid))
                {
                    throw new Exception("The friendship id specified is not a valid integer.");
                }
                Entities dbContext = new Entities();

                var friendship = dbContext.Friendships.SingleOrDefault(f => f.Id == fid);

                if (friendship == null)
                {
                    throw new Exception("The requested friendship does not exist.");
                }

                Guid userGuid = new Guid(UserHelper.getLoggedInUserId());

                if (!(friendship.UserId == userGuid || friendship.FriendId == userGuid))
                {
                    throw new Exception("You are not a part of this friendship.");
                }

                if (option == "0")
                {
                    dbContext.Friendships.DeleteObject(friendship);
                }
                else if (option == "1")
                {
                    if (friendship.Status != 1)
                    {
                        friendship.Status = 1;
                    }
                }

                dbContext.SaveChanges();

                return Redirect(HttpContext.Request.UrlReferrer.ToString());
            }catch(Exception ex)
            {
                return Content(ex.Message);
            }
        }
Example #9
0
        public ActionResult Create()
        {
            string returnUrl = HttpContext.Request.Params["returnUrl"].Length > 0 ? HttpContext.Request.Params["returnUrl"] : HttpContext.Request.UrlReferrer.ToString();

            try
            {

                Guid userGuid = new Guid(UserHelper.getLoggedInUserId());

                Entities dbContext = new Entities();

                int objectId;

                if (!int.TryParse(HttpContext.Request.Params["objectId"], out objectId))
                {
                    throw new Exception("Invalid object id specified.");
                }
                Models.Object obj = dbContext.Objects.SingleOrDefault(o => o.Id == objectId);
                if (obj == null)
                {
                    throw new Exception("The object you are trying to comment on does not exist.");
                }

                if (HttpContext.Request.Params["content"].Length < 1)
                {
                    throw new Exception("You must enter a comment.");
                }

                Comment comment = new Comment();
                comment.UserId = userGuid;
                comment.ObjectId = obj.Id;
                comment.Content = HttpContext.Request.Params["content"];
                comment.CreatedAt = DateTime.Now;

                dbContext.Comments.AddObject(comment);
                dbContext.SaveChanges();

                return Redirect(returnUrl);
            }catch(Exception ex)
            {
                return Content(ex.Message);
            }
        }
Example #10
0
        public ActionResult Add(string userId = "")
        {
            try
            {
                Guid friendId;
                if (!Guid.TryParse(userId, out friendId))
                {
                    throw new Exception("The specified user id is not valid.");
                }

                var user = UserHelper.getUserById(friendId.ToString());

                if (user == null)
                {
                    throw new Exception("The user you are trying to add as friend is not available.");
                }

                Guid userGuid = new Guid(UserHelper.getLoggedInUserId());
                if (!FriendshipHelper.ShowAddFriendLink(userGuid, friendId))
                {
                    throw new Exception("A friendship or friendship request already exists between you and " + UserHelper.GetDisplayName(friendId.ToString()));
                }
                Entities dbContext = new Entities();

                Friendship friendship = new Friendship();
                friendship.UserId = userGuid;
                friendship.FriendId = friendId;
                friendship.Status = 0;
                friendship.CreatedAt = DateTime.Now;
                dbContext.Friendships.AddObject(friendship);
                dbContext.SaveChanges();
                EmailHelper.SendEmail(friendship.Friend.Membership.Email, "Nuevo Friend Request from "+UserHelper.GetDisplayName(friendship.UserId.ToString()), UserHelper.GetDisplayName(friendship.UserId.ToString()) + "Has sent you a friend request on Nuevo. You may login and curate your friend requests.");
                return RedirectToAction("Index", "Profile", new { userId = friendId.ToString() });
            }catch(Exception ex)
            {
                return Content(ex.Message);
            }
        }
Example #11
0
        public ActionResult Privacy()
        {
            Entities dbContext = new Entities();

            Guid userGuid = new Guid(UserHelper.getLoggedInUserId());

            UserPrivacy privacy = dbContext.UserPrivacies.SingleOrDefault(p => p.UserId == userGuid);

            if (privacy == null)
            {
                privacy = new UserPrivacy();
                privacy.SeeMyInfo = 0;
                privacy.SeeMyWall = 0;
                privacy.SeeMyPhotos = 0;
            }

            var model = new PrivacyModel {
                SeeMyInfo = privacy.SeeMyInfo,
                SeeMyWall = privacy.SeeMyWall,
                SeeMyPhotos = privacy.SeeMyPhotos
            };

            return View(model);
        }
Example #12
0
        public ActionResult Create(PostModel model)
        {
            string returnUrl = HttpContext.Request.Params["returnUrl"].Length > 0 ? HttpContext.Request.Params["returnUrl"] : HttpContext.Request.UrlReferrer.ToString();

            if(ModelState.IsValid)
            {
                try
                {
                    Entities dbContext = new Entities();

                    Models.Object obj = new Models.Object();
                    obj.EntityName = "Post";
                    dbContext.Objects.AddObject(obj);
                    dbContext.SaveChanges();

                    Post post = new Post();

                    post.Id = obj.Id;
                    post.UserId = new Guid(UserHelper.getLoggedInUserId());
                    post.PersonId = new Guid(HttpContext.Request.Params["personId"].Length > 0 ? HttpContext.Request.Params["personId"] : UserHelper.getLoggedInUserId());
                    post.Content = model.Content;
                    post.CreatedAt = DateTime.Now;
                    post.UpdatedAt = DateTime.Now;

                    dbContext.Posts.AddObject(post);
                    dbContext.SaveChanges();

                    return Redirect(returnUrl);
                }catch(Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            return View(model);
        }
Example #13
0
        public ActionResult Privacy(PrivacyModel model)
        {
            ViewBag.message = null;

            if(ModelState.IsValid)
            {
                try
                {

                    Entities dbContext = new Entities();

                    Guid userGuid = new Guid(UserHelper.getLoggedInUserId());

                    UserPrivacy privacy = dbContext.UserPrivacies.SingleOrDefault(p => p.UserId == userGuid);

                    if (privacy == null)
                    {
                        privacy = new UserPrivacy();
                        privacy.UserId = userGuid;

                        privacy.SeeMyInfo = model.SeeMyInfo;
                        privacy.SeeMyWall = model.SeeMyWall;
                        privacy.SeeMyPhotos = model.SeeMyPhotos;
                        dbContext.UserPrivacies.AddObject(privacy);
                    }
                    else
                    {
                        privacy.SeeMyInfo = model.SeeMyInfo;
                        privacy.SeeMyWall = model.SeeMyWall;
                        privacy.SeeMyPhotos = model.SeeMyPhotos;
                    }

                    dbContext.SaveChanges();

                    ViewBag.message = "Your privacy settings were saved.";
                }catch(Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            return View(model);
        }
Example #14
0
        public ActionResult ViewPhoto(string photoId = "")
        {
            ViewBag.message = null;
            ViewBag.album = null;

            try
            {
                int aid;
                if (!int.TryParse(photoId, out aid))
                {
                    throw new Exception("The photo id specified is not a valid integer.");
                }

                Entities dbContext = new Entities();
                var album = dbContext.Photos.SingleOrDefault(a => a.Id == aid);

                if (album == null || (!PrivacyHelper.CanSeePhotos(album.UserId, new Guid(UserHelper.getLoggedInUserId()))))
                {
                    throw new Exception("The photo you are looking for is not available.");
                }

                ViewBag.photo = album;

            }
            catch (Exception ex)
            {
                ViewBag.message = ex.Message;
            }
            return View();
        }
Example #15
0
        public ActionResult Search(string query = "")
        {
            if(query.Length > 0)
            {
                Entities dbContext = new Entities();

                var users = from u in dbContext.Users
                            join m in dbContext.Memberships on u.UserId equals m.UserId
                            where
                                u.UserName.EndsWith(query) ||
                                u.UserName.StartsWith(query) ||
                                u.UserName.Contains(query) ||
                                (String)m.Email == query
                            select u;
                ViewBag.users = users.ToList();
            }else{
                ViewBag.users = null;
            }

            return View();
        }
Example #16
0
 public ActionResult Upload()
 {
     Guid userGuid = new Guid(UserHelper.getLoggedInUserId());
     Entities dbContext = new Entities();
     var albums = dbContext.Albums.Where(a => a.UserId == userGuid).ToList();
     ViewBag.albums = albums;
     if (albums != null)
         return View();
     else
     {
         return Content("album is numm");// debugging
     }
 }
Example #17
0
 protected override void Initialize(RequestContext requestContext)
 {
     base.Initialize(requestContext);
     if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
     this.dbContext = new Entities();
 }
Example #18
0
        public ActionResult Upload(string var = "")
        {
            int viewPhotoId = 0;
            try {
                foreach (string photoFile in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[photoFile];

                    if (!(file.ContentLength > 0))
                    {
                        throw new Exception("File is not a valid image.");
                    }

                    string fileExtension = Path.GetExtension(Path.GetFileName(file.FileName));
                    string fileName = UserHelper.getLoggedInUserId() + "_" + DateTime.Now.Ticks.ToString() + fileExtension;
                    string filePath = Path.Combine(HttpContext.Server.MapPath("~/Uploads"), fileName);

                    file.SaveAs(filePath);

                    int albumId;

                    if(!int.TryParse(HttpContext.Request.Params["albumId"], out albumId))
                    {
                        throw new Exception("The requested album id is not a valid integer.");
                    }

                    Entities dbContext = new Entities();

                    var album = dbContext.Albums.SingleOrDefault(a => a.Id == albumId);

                    Guid userGuid = new Guid(UserHelper.getLoggedInUserId());

                    if(album == null || album.UserId != userGuid)
                    {
                        throw new Exception("The album you are trying to upload the photo to is not available.");
                    }

                    Models.Object obj = new Models.Object();
                    obj.EntityName = "Photo";
                    dbContext.Objects.AddObject(obj);
                    dbContext.SaveChanges();

                    Photo photo = new Photo();
                    photo.Id = obj.Id;
                    photo.AlbumId = album.Id;
                    photo.UserId = userGuid;
                    photo.FilePath = fileName;
                    photo.Caption = HttpContext.Request.Params["caption"];
                    photo.CreatedAt = DateTime.Now;
                    dbContext.Photos.AddObject(photo);
                    dbContext.SaveChanges();
                    viewPhotoId = photo.Id;
                }
                return RedirectToAction("ViewPhoto", "Photo", new { photoId = viewPhotoId });
            }catch(Exception ex)
            {
                return Content(ex.Message);
            }
        }
Example #19
0
        public ActionResult Requests()
        {
            var user = UserHelper.getUserById(UserHelper.getLoggedInUserId());
            Entities dbContext = new Entities();

            var friendships = dbContext.Friendships.Where(f => f.Status == 0 && f.FriendId == user.UserId).ToList();

            ViewBag.friendships = friendships;

            return View();
        }