Esempio n. 1
0
        public IHttpActionResult AddPigeon(PigeonBindingModel inputPigeon)
        {
            if (inputPigeon == null)
            {
                return this.BadRequest(InvalidPigeonPostInputDataMessage);
            }

            var loggedUserId = this.User.Identity.GetUserId();

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var pigeonToAdd = new Pigeon
            {
                Title = inputPigeon.Title,
                Content = inputPigeon.Content,
                Author = this.Data.Users.Search(u => u.Id == loggedUserId).FirstOrDefault(),
                AuthorId = loggedUserId,
                CreatedOn = DateTime.Now,
                Comments = new HashSet<Comment>(),
                Votes = new HashSet<PigeonVote>()
            };

            if (inputPigeon.PhotoData != null)
            {
                var photo = new Photo { Base64Data = inputPigeon.PhotoData };

                this.Data.Photos.Add(photo);
                pigeonToAdd.Photo = photo;
            }

            this.Data.Pigeons.Add(pigeonToAdd);
            this.Data.SaveChanges();

            var pigeonViewModel = PigeonViewModel.CreateSingle(pigeonToAdd);

            return this.Ok(pigeonViewModel);
        }
Esempio n. 2
0
        private void UpdateUserProfilePhoto(string profilePhotoData, User loggedUser)
        {
            if (profilePhotoData != null)
            {
                var profilePhoto = new Photo { Base64Data = profilePhotoData };

                this.Data.Photos.Add(profilePhoto);
                loggedUser.ProfilePhoto = profilePhoto;
            }
        }
Esempio n. 3
0
        private void UpdateUserCoverPhoto(string coverPhotoData, User loggedUser)
        {
            if (coverPhotoData != null)
            {
                var coverPhoto = new Photo { Base64Data = coverPhotoData };

                this.Data.Photos.Add(coverPhoto);
                loggedUser.CoverPhoto = coverPhoto;
            }
        }