Exemplo n.º 1
0
        public void Create(string userId, Feeling feeling, string text, IFormFile photo)
        {
            var post = new Post
            {
                UserId  = userId,
                Feeling = feeling,
                Text    = text,
                Likes   = 0,
                Date    = DateTime.UtcNow,
                Photo   = photo != null?this.photoService.PhotoAsBytes(photo) : null
            };

            db.Posts.Add(post);
            db.SaveChanges();
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ChangeAvatar(PersonViewModel pvm)
        {
            var user = await _userManager.GetUserAsync(User);

            if (pvm.Avatar != null)
            {
                byte[] imageData = null;

                using (var binaryReader = new BinaryReader(pvm.Avatar.OpenReadStream()))
                {
                    imageData = binaryReader.ReadBytes((int)pvm.Avatar.Length);
                }

                user.Avatar = imageData;
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "Profile"));
        }
Exemplo n.º 3
0
        public int Create(IFormFile photo, string userId)
        {
            using (var memoryStream = new MemoryStream())
            {
                photo.CopyTo(memoryStream);

                var instanceOfPhoto = new Photo
                {
                    IsProfilePicture = false,
                    PhotoAsBytes     = memoryStream.ToArray(),
                    UserId           = userId
                };

                db.Photos.Add(instanceOfPhoto);
                db.SaveChanges();

                return(instanceOfPhoto.Id);
            }
        }
        public IActionResult Create(PersonViewModel pvm)
        {
            User user = new User {
                UserName = pvm.Name
            };

            if (pvm.Avatar != null)
            {
                byte[] imageData = null;

                using (var binaryReader = new BinaryReader(pvm.Avatar.OpenReadStream()))
                {
                    imageData = binaryReader.ReadBytes((int)pvm.Avatar.Length);
                }

                user.Avatar = imageData;
            }
            _context.Users.Add(user);
            _context.SaveChanges();

            return(RedirectToAction("Create"));
        }