//EDIT
        public void EditPost(EditPostViewModel p)
        {
            var post = GetPost(p.Id);

            post.Content  = p.Content;
            post.Title    = p.Title;
            post.SubTitle = p.SubTitle;

            if (p.PostImage != null)
            {
                post.postPicture = new PostPicture()
                {
                    PostImageInBytes = _dataConverter.FileBaseToByteArray(p.PostImage)
                };
            }
            _db.SaveChanges();
        }
Exemple #2
0
        public Post CreatePost(CreatePostViewModel p)
        {
            Post post = new Post()
            {
                Author   = _identityFacade.GetUserName(),
                AuthorId = _identityFacade.GetUserId(),
                PostedAt = DateTime.Now,
                Content  = p.Content,
                Title    = p.Title,
                SubTitle = p.SubTitle
            };

            if (p.file != null)
            {
                post.postPicture = new PostPicture()
                {
                    PostImageInBytes = _dataConverter.FileBaseToByteArray(p.file)
                };
            }
            return(post);
        }
Exemple #3
0
        //ADD
        public void AddImageToDb(string userID, HttpPostedFileBase file)
        {
            var image = _fileController.FileBaseToByteArray(file);

            var db          = _dbContext.GetDBContext();
            var currentUser = db.Users.Where(x => x.Id == userID).Single();

            if (currentUser.Avatar == null)
            {
                currentUser.Avatar = new Picture()
                {
                    AvatarInBytes = image
                };
            }
            else
            {
                currentUser.Avatar.AvatarInBytes = image;
            }

            db.SaveChanges();
            db.Dispose();
        }