Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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);
            }
        }