Exemplo n.º 1
0
        public ActionResult src(HttpPostedFileBase[] uploadImages)
        {
            if (uploadImages.Count() <= 1)
            {
                return(RedirectToAction("Index", "Home"));
            }

            foreach (var image in uploadImages)
            {
                if (image.ContentLength > 0)
                {
                    byte[] imageData = null;
                    using (var binaryReader = new BinaryReader(image.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(image.ContentLength);
                    }
                    var userImage = new Models.UserProfileImage()
                    {
                        UserId    = getCurrentUser().Id,
                        ImageData = imageData,
                        FileName  = image.FileName
                    };

                    var db = new Models.MyIdentityDbContext();
                    db.UserProfileImages.Add(userImage);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
        /*
         * private void fillMissingPics()
         * {
         *  var db = new Models.MyIdentityDbContext();
         *
         *  Models.UserProfileImage defaultImg = db.UserProfileImages.Find("164eb47a-ac68-4e92-8baa-56dd5f730a80");
         *
         *  foreach (var user in db.Users)
         *  {
         *      if (db.UserProfileImages.Find(user.Id) == null)
         *      {
         *          db.UserProfileImages.Add(new Models.UserProfileImage()
         *          {
         *              UserId = user.Id,
         *              ImageData = defaultImg.ImageData,
         *              FileName = "Default Image"
         *          });
         *      }
         *  }
         *
         *  db.SaveChanges();
         * }
         */

        private void addDefaultPicture(Models.MyIdentityUser user)
        {
            var db = new Models.MyIdentityDbContext();

            Models.UserProfileImage defaultImg = db.UserProfileImages.Find("164eb47a-ac68-4e92-8baa-56dd5f730a80");
            db.UserProfileImages.Add(new Models.UserProfileImage()
            {
                UserId    = user.Id,
                ImageData = defaultImg.ImageData,
                FileName  = "Default Image"
            });
            db.SaveChanges();
        }
Exemplo n.º 3
0
        public ActionResult UploadProfileImage(HttpPostedFileBase[] uploadImage)
        {
            var db          = new Models.MyIdentityDbContext();
            var currentUser = getCurrentUser();

            if (uploadImage.Length == 0)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
            }

            if (uploadImage[0] == null)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
            }

            if (db.UserProfileImages.Find(currentUser.Id) != null)
            {
                var profile = db.UserProfileImages.Find(currentUser.Id);
                db.UserProfileImages.Remove(profile);
                db.SaveChanges();
            }

            foreach (var image in uploadImage)
            {
                if (image.ContentLength > 0)
                {
                    byte[] imageData = null;
                    using (var binaryReader = new BinaryReader(image.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(image.ContentLength);
                    }
                    var userImage = new Models.UserProfileImage()
                    {
                        UserId    = currentUser.Id,
                        ImageData = imageData,
                        FileName  = image.FileName
                    };

                    //AddNewPostToFollowers(imageData, currentUser);
                    //AddNewPostToCurrentUser(imageData, currentUser);
                    AddNewPost(imageData, currentUser);

                    db.UserProfileImages.Add(userImage);
                    db.SaveChanges();
                }
            }
            return(Redirect(Request.UrlReferrer.ToString()));
        }
Exemplo n.º 4
0
        private List <Models.UserProfileImage> getUserProfileImages(List <Models.MyIdentityUser> userList)
        {
            var db = new Models.MyIdentityDbContext();

            List <Models.UserProfileImage> userImageList = new List <Models.UserProfileImage>();

            foreach (var user in userList)
            {
                Models.UserProfileImage img = db.UserProfileImages.Find(user.Id);

                if (img != null)
                {
                    userImageList.Add(img);
                }
            }

            return(userImageList);
        }