예제 #1
0
        public async Task InsertPost(Post post)
        {
            var user = await _unitofWork.UserRepository.GetById(post.UserId);

            if (user == null)
            {
                throw new BusnissException("User doesn't exist");
            }

            var userPost = await _unitofWork.PostRepository.GetPostsByUser(post.UserId);

            if (userPost.Count() < 10)
            {
                var lastPost = userPost.OrderByDescending(post => post.Date).FirstOrDefault();
                if ((DateTime.Now - lastPost.Date).TotalDays < 7)
                {
                    throw new BusnissException("You are not able to publish the post");
                }
            }


            if (post.Description.Contains("sexo"))
            {
                throw new BusnissException("Content not allowed");
            }

            await _unitofWork.PostRepository.Add(post);

            await _unitofWork.SaveChangesAsync();
        }
예제 #2
0
        public async Task <Guid> AddAuthorAsync(AuthorCreation model)
        {
            var author = _mapper.Map <Author>(model);

            _repository.Add(author);

            await _unitofWork.SaveChangesAsync();

            return(author.Id);
        }
예제 #3
0
        public async Task <Guid> AddBookAsync(BookCreation book)
        {
            var bookToCreate = _mapper.Map <Book>(book);

            _booksRepository.Add(bookToCreate);

            await _unitofWork.SaveChangesAsync();

            //Return id for the controller action to pass
            //in the id into for the location header
            return(bookToCreate.Id);
        }
예제 #4
0
        public async Task <PhoneBook> CreatePhonebookAsync(string Name)
        {
            var phoneBook = new PhoneBook()
            {
                Name = Name
            };

            PhoneDB.Add(phoneBook);
            await Uow.SaveChangesAsync();

            return(phoneBook);
        }
예제 #5
0
        public async Task <int> CreateProductAsync(ProductEntity argProductEntity)
        {
            var itemData = _mapper.Map <Products>(argProductEntity);

            using (var transaction = _unitOfWork.BeginTransaction())
            {
                await _genericRepository.InsertAsync(itemData).ConfigureAwait(false);

                await _unitOfWork.SaveChangesAsync().ConfigureAwait(false);

                transaction.Commit();
            }
            return(itemData.Id);
        }