Esempio n. 1
0
        public void InsertPost(PostDTO post)
        {
            if (post == null)
            {
                throw new ValidationException("Argument is null", nameof(post));
            }

            Post postEntity = ToDalEntity(post);

            if (post.ImageForm != null)
            {
                postEntity.Image = $"Post{postEntity.UserId}{DateTime.UtcNow.ToString().Replace(" ", "").Replace(":", "")}.jpeg";
            }

            UnitOfWork.Post.Create(postEntity);

            if (post.ImageForm != null)
            {
                MemoryStream ms = new MemoryStream(post.ImageForm.GetBytes().Result);

                Task.Run(() => AddImage.UploadFile(ms, $"Post{postEntity.UserId}{DateTime.UtcNow.ToString().Replace(":","").Replace(" ","")}.jpeg"));
            }

            UnitOfWork.Save();
        }
Esempio n. 2
0
        public void UpdatePost(PostDTO post)
        {
            if (post == null)
            {
                throw new ValidationException("Argument is null", nameof(post));
            }

            var element = (from posts in UnitOfWork.Post.GetAll() where posts.Id == post.Id select posts).FirstOrDefault(); // Get post by id.


            if (element != null)
            {
                Post postEntity = ToDalEntity(post);
                postEntity.Content = post.Content;
                postEntity.Title   = post.Title;


                if (post.ImageForm != null)
                {
                    postEntity.Image = $"Post{postEntity.UserId}{DateTime.UtcNow.ToString().Replace(" ", "").Replace(":", "")}.jpeg";
                    MemoryStream ms = new MemoryStream(post.ImageForm.GetBytes().Result);

                    Task.Run(() => AddImage.UploadFile(ms, postEntity.Image));
                }

                UnitOfWork.Post.Update(postEntity);
                UnitOfWork.Save();
            }
            else
            {
                throw new ValidationException("Comment not found", nameof(post));
            }
        }
        public void InsertPhoto(PhotoDTO photo)
        {
            if (photo == null)
            {
                throw new ValidationException("Argument is null", nameof(photo));
            }

            Photo photoEntity = ToDalEntity(photo);

            photoEntity.URL = photo.PlaceId.ToString() + DateTime.UtcNow;
            UnitOfWork.Photo.Create(photoEntity);
            MemoryStream ms = new MemoryStream(photo.Image.GetBytes().Result);

            Task.Run(() => AddImage.UploadFile(ms, photoEntity.URL));
            UnitOfWork.Save();
        }
        public void InsertPerson(PersonDTO person)
        {
            if (person == null)
            {
                throw new ValidationException("Argument is null", nameof(person));
            }


            Person personEntity = ToDalEntity(person);

            personEntity.Avatar = $"{personEntity.NickName}Avatar";
            UnitOfWork.Person.Create(personEntity);

            MemoryStream ms = new MemoryStream(person.Image.GetBytes().Result);

            Task.Run(() => AddImage.UploadFile(ms, personEntity.Avatar));
            UnitOfWork.Save();
        }
        public void InsertPlace(PlaceDTO place)
        {
            if (place == null)
            {
                throw new ValidationException("Argument is null", nameof(place));
            }

            Place placeEntity = ToDalEntity(place);

            UnitOfWork.Place.Create(placeEntity);
            if (place.Image != null)
            {
                MemoryStream ms = new MemoryStream(place.Image.GetBytes().Result);

                Task.Run(() => AddImage.UploadFile(ms, placeEntity.Avatar));
                placeEntity.Avatar = $"{placeEntity.Id}Avatar";
            }
            UnitOfWork.Save();
        }
        public void UpdatePerson(PersonDTO person)
        {
            if (person == null)
            {
                throw new ValidationException("Argument is null", nameof(person));
            }

            var gId = (from p in UnitOfWork.Person.GetAll() where p.IDUserOfGoogle == person.IDUserOfGoogle select p).FirstOrDefault();


            Person personEntity = ToDalEntity(person);

            personEntity.Id     = gId.Id;
            personEntity.Avatar = $"{personEntity.NickName}Avatar";
            personEntity.Rating = gId.Rating;

            UnitOfWork.Person.Update(personEntity);

            MemoryStream ms = new MemoryStream(person.Image.GetBytes().Result);

            Task.Run(() => AddImage.UploadFile(ms, personEntity.Avatar));
            UnitOfWork.Save();
        }