Esempio n. 1
0
        public void AddPost(Guid authorId, Guid wallOwnerId, string bodyPost, Picture picture = null)
        {
            var author = _unitOfWork.UserRepository.GetById(authorId);
            var post = new Post()
            {
                Author = author,
                Picture = picture,
                Body = bodyPost,
                DateCreated = DateTime.Now,
                Id = Guid.NewGuid()
            };

            _unitOfWork.PostRepository.Add(post);
            _unitOfWork.Save();
            
            var wallOwner = _unitOfWork.UserRepository.GetById(wallOwnerId);
            post.PostedUsers.Add(wallOwner);
            _unitOfWork.PostRepository.Update(post);
            _unitOfWork.Save();
        }
Esempio n. 2
0
        public ActionResult ChangeAvatar(HttpPostedFileBase newAvatar)
        {
            var pictureFolderStorage = ConfigurationManager.AppSettings["pictureStorage"];
            var pathToStorage = HostingEnvironment.MapPath($"~/{pictureFolderStorage}");

            var tmp = newAvatar.FileName.Split('.');
            var extension = tmp[tmp.Length - 1];
            var userId = HttpContext.User.Identity.GetUserId();

            var picture = new Picture()
            {
                Id = Guid.NewGuid(),
                Secret = Guid.NewGuid().ToString().Substring(0, 8),
                Extension = extension
            };

            _pictureService.AddPicture(picture);
            

            var filename = _pictureService.GeneratePictureFilename(picture);
            var pathToFile = Path.Combine(pathToStorage, userId);


            _pictureService.CreatePicture(filename, pathToFile, newAvatar.InputStream);

            string pathToAvatar = $"http://{Request.Url.Authority}/" +
                                  _pictureService.GetPictureLocation(pictureFolderStorage, new Guid(userId), picture.Id)
                                      .Replace(@"\", @"/");
            var cropPhotoViewModel = new CropPhotoViewModel()
            {
                PathToPicture = pathToAvatar,
                PictureId = picture.Id
            };

            ViewBag.CropPhotoViewModel = cropPhotoViewModel;

            var userPageViewModel = GetUserPageViewModel(userId);

            return View("CropPhoto", userPageViewModel);
        }
Esempio n. 3
0
 public string GetPictureLocation(string pictureStorage, Guid creator, Picture picture, string postfix = "")
 {
     return Path.Combine(pictureStorage, creator.ToString(),
         GeneratePictureFilename(picture.Id, picture.Secret, picture.Extension, postfix));
 }
Esempio n. 4
0
 public string GeneratePictureFilename(Picture picture, string postfix = "")
 {
     return GeneratePictureFilename(picture.Id, picture.Secret, picture.Extension, postfix);
 }
Esempio n. 5
0
 public void AddPicture(Picture picture)
 {
     _unitOfWork.PictureRepository.Add(picture);
     _unitOfWork.Save();
 }
Esempio n. 6
0
        public void AddPostWithPicture(Guid authorId, Guid wallOwnerId, string bodyPost, string pathToStorage, Stream inputStream, string pictureExtension)
        {
            var picture = new Picture()
            {
                Id = Guid.NewGuid(),
                Secret = Guid.NewGuid().ToString().Substring(0,8),
                Extension = pictureExtension
            };

            _unitOfWork.PictureRepository.Add(picture);
            _unitOfWork.Save();

            var filename = _pictureService.GeneratePictureFilename(picture);
            var pathToFile = Path.Combine(pathToStorage, authorId.ToString());

            _pictureService.CreatePicture(filename, pathToFile, inputStream);

            AddPost(authorId, wallOwnerId, bodyPost, picture);
        }
Esempio n. 7
0
 public void ChangeAvatar(Picture picture, Guid userId)
 {
     var user = _unitOfWork.UserRepository.GetById(userId);
     user.Avatar = picture;
     _unitOfWork.UserRepository.Update(user);
     _unitOfWork.Save();
 }