示例#1
0
        public ActionResult <Publisher> PostPublisher(Publisher publisher)
        {
            _publisherRepository.Create(publisher);
            _publisherRepository.Save();

            return(CreatedAtAction("GetPublisher", new { id = publisher.Id }, publisher));
        }
示例#2
0
 public async Task Add(Publisher entity)
 {
     await Task.Run(() =>
     {
         IUnitOfWork uow           = this._uowProvider.Get();
         IPublisherRepository repo = this._repoProvider.Get(uow);
         repo.Create(entity);
         uow.Dispose();
     });
 }
示例#3
0
        public int Create(CreatePublisherRequest request)
        {
            var publisherEntity = new PublisherEntity()
            {
                LicenceNumber = request.LicenceNumber,
                Name          = request.Name
            };

            publisherRepository.Create(publisherEntity);

            return(publisherEntity.Id);
        }
示例#4
0
        public void Register(string name)
        {
            var hasPublisher = GetByName(name);

            if (hasPublisher != null)
            {
                throw new Exception(Errors.DuplicatedName);
            }

            var publisher = new Publisher(name);

            _repository.Create(publisher);
        }
        public IActionResult Create([FromBody] PublisherDto dto)
        {
            if (dto == null || dto.Id != 0)
            {
                return(BadRequest());
            }

            if (_publisherRepository.Create(dto))
            {
                return(Ok(dto));
            }
            else
            {
                return(BadRequest());
            }
        }
示例#6
0
        public IActionResult Save([FromBody] Publisher publisher)
        {
            if (publisher is null)
            {
                return(BadRequest("Publisher is null."));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (publisher.PublisherId == 0)
            {
                _repository.Create(publisher);
                return(new JsonResult(new { create = true, publisher }));
            }
            else
            {
                _repository.Update(publisher);
                return(new JsonResult(new { update = true, publisher }));
            }
        }
示例#7
0
        public async Task Add(Book book)
        {
            await Task.Run(() =>
            {
                // begin transaction
                IUnitOfWork uow                    = this._uowProvider.Get();
                IBookRepository bookRepo           = this._repoProvider.Get(uow);
                IPublisherRepository publisherRepo = this._publisherRepoProvider.Get(uow);
                ITagRepository tagRepo             = this._tagRepoProvider.Get(uow);
                IAuthorRepository authorRepo       = this._authorRepoProvider.Get(uow);
                uow.Begin();

                // handle publisher
                int publisherId = 0;
                if (publisherRepo.ExistsWithName(book.Publisher.Name))
                {
                    // publisher exists
                    // get the id
                    publisherId = publisherRepo.GetIdByName(book.Publisher.Name);
                }
                else
                {
                    // publisher does not exist
                    // insert publisher
                    publisherRepo.Create(book.Publisher);
                    // get the id
                    publisherId = publisherRepo.GetIdByName(book.Publisher.Name);
                }
                book.Publisher.Id = publisherId;

                // insert Books table record
                bookRepo.Create(book);

                // handle tags
                // get all tag Ids
                List <int> tagIds = new List <int>();
                foreach (var tag in book.Tags)
                {
                    if (tagRepo.ExistsWithName(tag.Name))
                    {
                        // tag exists
                        // get the id
                        int tagId = tagRepo.GetIdByName(tag.Name);
                        tagIds.Add(tagId);
                    }
                    else
                    {
                        // tag does not exist
                        // insert tag
                        tagRepo.Create(tag);
                        // get the id
                        int tagId = tagRepo.GetIdByName(tag.Name);
                        tagIds.Add(tagId);
                    }
                }
                // insert records in Book_Tag link table
                int bookId = bookRepo.GetIdByTitle(book.Title);
                foreach (int tagId in tagIds)
                {
                    tagRepo.LinkBook(bookId, tagId);
                }

                // handle authors
                // get all author Ids
                List <int> authorIds = new List <int>();
                foreach (var author in book.Authors)
                {
                    if (authorRepo.AuthorExists(author.FirstName, author.LastName))
                    {
                        // author exists
                        // get the Id
                        int authorId = authorRepo.GetIdByName(author.FirstName, author.LastName);
                        authorIds.Add(authorId);
                    }
                    else
                    {
                        // author does not exist
                        // insert author
                        authorRepo.Create(author);
                        // get the Id
                        int authorId = authorRepo.GetIdByName(author.FirstName, author.LastName);
                        authorIds.Add(authorId);
                    }
                }
                // insert records in Book_Author table
                foreach (int authorId in authorIds)
                {
                    authorRepo.LinkBook(bookId, authorId);
                }

                // commit transaction
                uow.Commit();
            });
        }
示例#8
0
 public ActionResult Create(PublisherStaroseletsEV book)
 {
     repo.Create(book);
     return(RedirectToAction("ListOfPublisher"));
 }