public ActionResult Insert(Author item)
        {
            if (ModelState.IsValid)
            {
                bool exist = aus.CheckAuthor(item);

                if (!exist)
                {
                    bool cat = aus.Add(item);
                    if (cat)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ViewBag.Message = "Operation Unsuccessfull";
                    }
                }
                else
                {
                    ViewBag.Message = "This author is already in the list.";
                }
            }
            else
            {
                ViewBag.Message = "Invalid entry";
            }

            return(View(item));
        }
Esempio n. 2
0
        public void AddTest()
        {
            //Arange
            AuthorDTO newAutohorDTO = new AuthorDTO()
            {
                Id   = "a0",
                Name = "Name0"
            };
            bool isAdded = false;
            Mock <IUnitOfWork>           unitOfWorkMock = new Mock <IUnitOfWork>();
            Mock <IRepository <Author> > repositoryMock = new Mock <IRepository <Author> >();

            repositoryMock.Setup(repo => repo.Get(It.IsAny <Expression <Func <Author, bool> > >()))
            .Returns <Expression <Func <Author, bool> > >(predicate =>
                                                          authors.Where(predicate.Compile()).AsQueryable());
            repositoryMock.Setup(repo => repo.Add(It.IsAny <Author>())).Callback(() => isAdded = true);
            unitOfWorkMock.Setup(getRepo => getRepo.GetRepository <Author>()).Returns(repositoryMock.Object);
            AuthorService authorService = new AuthorService(unitOfWorkMock.Object);

            //Act
            authorService.Add(newAutohorDTO);

            //Assert
            Assert.True(isAdded);
        }
Esempio n. 3
0
        private string AddAuthor()
        {
            author author = (author)ObjectUtil.FillObjectWithMap(new author(), BaseService.ReqToDict(Request));

            if (author != null)
            {
                AuthorService = new AuthorService();
                author Std = null;
                if (StringUtil.NotNullAndNotBlank(author.id))
                {
                    Std = (author)AuthorService.Update(author);
                }
                else
                {
                    Std = (author)AuthorService.Add(author);
                }
                if (Std == null)
                {
                    return("0");
                }
                author toSend = (author)ObjectUtil.GetObjectValues(new string[] {
                    "id", "name", "address", "email", "phone"
                }, Std);
                return(JsonConvert.SerializeObject(toSend));
            }
            return("0");
        }
Esempio n. 4
0
        public IActionResult Add(AuthorInsertViewModel model)
        {
            var entity           = _mapper.Map <Author>(model);
            var affedtedRowCount = _service.Add(entity);

            ViewBag.AffectedRowCount = affedtedRowCount;
            return(View(model));
        }
Esempio n. 5
0
        public void TestAdd()
        {
            mockAuthorRepository.Setup(x => x.Add(It.IsAny <Author>())).Returns(author);
            var    authorService = new AuthorService(Options.Create(_setting), mockAuthorRepository.Object);
            Author authorReturn  = authorService.Add(author);

            Assert.IsNotNull(authorReturn);
        }
        public IActionResult Add(AuthorInsertModel model)
        {
            var entity = _mapper.Map <Author>(model);

            _service.Add(entity);

            return(View(model));
        }
Esempio n. 7
0
        public bool AddAuthor(AuthorData a)
        {
            Author author = new Author();

            author.name = a.name;
            bool result = AuthorService.Add(author);

            return(result);
        }
 public IActionResult Post([FromBody] PostAuthorViewModel author)
 {
     if (ModelState.IsValid)
     {
         _authorService.Add(author);
         return(Ok(author));
     }
     return(BadRequest(ModelState));
 }
Esempio n. 9
0
        public IActionResult Post([FromBody] AuthorRequestBody body)
        {
            var author = authorService.Add(body.MapTo <AuthorToAddOrUpdate>());

            return(this.CreateHalResponse(author.MapTo <AuthorResponseBody>())
                   .AddLink(LinkTemplates.Author.Self)
                   .AddLocationHeader(this, author.Id)
                   .ToActionResult(this, HttpStatusCode.Created));
        }
Esempio n. 10
0
 private void add_author_btn_Click(object sender, EventArgs e)
 {
     try
     {
         authorService.Add(author_name_txtbox.Text);
     }
     catch (Exception ex)
     {
         UserError(ex);
     }
 }
Esempio n. 11
0
        // GET: Home
        public async Task IndexAsync(string booksName)
        {
            //https://www.goodreads.com/search/index.xml?key=Axm8msC1oG3ZqXyqlO5Ng&q=harry&search%5Bfield%5D=title


            // Create an unauthorized Goodreads client.
            var client = GoodreadsClient.Create(apiKey, apiSecret);

            // Now you are able to call some Goodreads endpoints that don't need the OAuth credentials. For example:
            // Get a book by specified id.
            Book kitap = await client.Books.GetByTitle(booksName);

            string authorname = "";

            foreach (var item in kitap.Authors)
            {
                authorname += item.Name + " & ";
            }
            authorname = authorname.Substring(0, authorname.Length - 3);
            //db yazar
            AuthorService _authorService = new AuthorService();

            Common.Domains.Author author = new Common.Domains.Author
            {
                Name = authorname
            };
            await _authorService.Add(author);

            //db image

            ProductService _productService = new ProductService();
            Product        book            = new Product
            {
                AuthorId    = _authorService.GetByName(authorname).Id,
                ImageUrl    = kitap.ImageUrl,
                Description = kitap.Description,
                Verify      = false,
                Name        = kitap.Title
            };
            await _productService.Add(book);

            CategoryService _categoryService = new CategoryService();

            foreach (var item in kitap.PopularShelves)
            {
                Common.Domains.Category categories = new Category
                {
                    Name      = item.Key,
                    ProductID = _productService.GetByName(kitap.Title).Id
                };
                await _categoryService.Add(categories);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// The button that adds the book and check all the fields.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_AddBook_Click(object sender, EventArgs e)
        {
            var author = AS.All().Where(a => a.Name == txt_Author.Text.Trim()).FirstOrDefault();

            if (txt_ISBN.Text.Trim() == "" || txt_Title.Text.Trim() == "" || txt_Description.Text.Trim() == "" || txt_Author.Text.Trim() == "")
            {
                MessageBox.Show("Please enter all the fields.");
            }
            else if (BS.BookAlreadyExists(txt_ISBN.Text.Trim()))
            {
                MessageBox.Show("This Book already exists");
            }
            else
            {
                if (author != null)
                {
                    Book book = new Book()
                    {
                        ISBN        = txt_ISBN.Text.Trim(),
                        Title       = txt_Title.Text.Trim(),
                        Description = txt_Description.Text.Trim(),
                        Author      = author
                    };
                    try
                    {
                        BS.Add(book);
                    } catch (ArgumentNullException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    Author author2 = new Author()
                    {
                        Name = txt_Author.Text.Trim()
                    };
                    Book book = new Book()
                    {
                        ISBN        = txt_ISBN.Text.Trim(),
                        Title       = txt_Title.Text.Trim(),
                        Description = txt_Description.Text.Trim(),
                        Author      = author2
                    };
                    AS.Add(author2);
                    BS.Add(book);
                    this.Close();
                }
            }
        }
Esempio n. 13
0
 public IActionResult Add(AdminAuthorAddVM model)
 {
     if (ModelState.IsValid)
     {
         var entity = new Author();
         entity.FirstName = model.Name;
         entity.LastName  = model.Surname;
         _authorService.Add(entity);
         return(RedirectToAction("Add"));
     }
     else
     {
         return(View(model));
     }
 }
Esempio n. 14
0
 private void btnAddAuthor_Click(object sender, EventArgs e)
 {
     if (txtBox_AddAuthor.Text.Trim() == "")
     {
         MessageBox.Show("Please enter an author.");
     }
     else
     {
         Author author = new Author()
         {
             Name = txtBox_AddAuthor.Text.Trim()
         };
         authorService.Add(author);
     }
 }
        private void BTNAddAuthor_Click(object sender, EventArgs e)
        {
            string name = tbName.Text;

            if (string.IsNullOrWhiteSpace(tbName.Text))
            {
                MessageBox.Show("Please enter name of the author.");
            }
            else
            {
                Author newAuthor = new Author(name);
                authorService.Add(newAuthor);
                this.Close();
            }
        }
Esempio n. 16
0
        public async override Task <bool> AddIfNotExists(CsvRowResult row)
        {
            AuthorService service = new AuthorService();
            Author        author  = row.Entity as Author;

            if (await service.ExistsWithName(author.FirstName, author.LastName))
            {
                return(false);
            }
            else
            {
                await service.Add(author);

                return(true);
            }
        }
        private void AddAuthor_button_Click(object sender, EventArgs e)
        {
            string authorName = AuthorName_textBox.Text;

            if (!string.IsNullOrEmpty(authorName))
            {
                Author author = new Author(authorName);
                authorService.Add(author);

                MessageBox.Show(authorName + " was succesfully added");
            }
            else
            {
                MessageBox.Show("Invalid Input - An author must have a name");
            }
        }
        public async Task AddAuthor_AuthorIsValid_Returns_AuthorDto()
        {
            var author    = new Author();
            var authorDto = new AuthorDto();

            _mapper.Setup(s => s.Map <Author>(authorDto))
            .Returns(author);
            _mapper.Setup(s => s.Map <AuthorDto>(author))
            .Returns(authorDto);

            var authorResult = await _authorService.Add(authorDto);

            _authorRepositoryMock.Verify(x => x.Add(author), Times.Once);
            _authorRepositoryMock.Verify(x => x.SaveChangesAsync(), Times.Once);
            authorResult.Should().Be(authorDto);
        }
Esempio n. 19
0
        private void btnNewAuthor_Click(object sender, EventArgs e)
        {
            Author a1 = new Author();

            if (txtAuthor.Text != null)
            {
                a1.Name = txtAuthor.Text;
                _authorService.Add(a1);
                _authorService.OnChanged(this, EventArgs.Empty);
                txtAuthor.Clear();
            }
            else
            {
                MessageBox.Show("Yoy have not given an input!");
            }
        }
        public IActionResult Post([FromBody] Author newAuthor)
        {
            try
            {
                // add the new book
                _authorService.Add(newAuthor);
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddBook", ex.GetBaseException().Message);
                return(BadRequest(ModelState));
            }

            // return a 201 Created status. This will also add a "location" header
            // with the URI of the new book. E.g., /api/books/99, if the new is 99
            return(CreatedAtAction("Get", new { Id = newAuthor.Id }, newAuthor));
        }
        public IActionResult Create([FromForm] CreateArticleViewModel viewModel)
        {
            string imageDirectory = Path.Combine(webHostEnvironment.WebRootPath, "ArticleImage");

            try
            {
                if (ModelState.IsValid == false)
                {
                    return(View(viewModel));
                }
                if (authorService.DoesAuthorExist(viewModel.Email))
                {
                    tagService.AddMultipleTags(viewModel.ArticleTags);
                    var tags = tagService.GetForArticleFromString(viewModel.ArticleTags);
                    articleService.Add(viewModel.Title,
                                       viewModel.Content,
                                       viewModel.Email,
                                       viewModel.Image,
                                       imageDirectory,
                                       tags);
                    return(RedirectToAction("Index"));
                }
                if (viewModel.DoesAuthorExist == true)
                {
                    viewModel.DoesAuthorExist = false;
                    return(View(viewModel));
                }
                tagService.AddMultipleTags(viewModel.ArticleTags);
                var myTags = tagService.GetForArticleFromString(viewModel.ArticleTags);
                authorService.Add(viewModel.Email, viewModel.FirstName, viewModel.LastName);
                articleService.Add(viewModel.Title,
                                   viewModel.Content,
                                   viewModel.Email,
                                   viewModel.Image,
                                   imageDirectory,
                                   myTags);
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Checks if text input is null or empty, if not it creates a new author.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddAuthor_Click(object sender, EventArgs e)
        {
            int id = authorService.GenerateId();

            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Input fields are not filled in.");
            }
            else
            {
                Author author = new Author
                {
                    Id   = id,
                    Name = txtName.Text
                };

                authorService.Add(author);
                authorService.Edit(author);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Creates a Author object
        /// </summary>
        /// <param name="sender">
        /// Object reference
        /// </param>
        /// <param name="e">
        /// Event data
        /// </param>
        private void btn_Create_Author_Click(object sender, EventArgs e)
        {
            AddAuthorDialog aad = new AddAuthorDialog();

            if (aad.ShowDialog() == DialogResult.OK)
            {
                if (aad._Name == "")
                {
                    MessageBox.Show("No author created: You must choose a name for an author", "Error: Author Name", MessageBoxButtons.OK);
                }
                else
                {
                    Author a = new Author()
                    {
                        Name = aad._Name
                    };
                    authorService.Add(a);
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Button to create a new book
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateNewBook_Click(object sender, EventArgs e)
        {
            Author addNewAuthor;

            if (chckAddNewAuthor.Checked == false)
            {
                addNewAuthor = lbAuthor.SelectedItem as Author;
                Debug.WriteLine(addNewAuthor);
            }
            else
            {
                addNewAuthor = new Author(txtAuthorName.Text);
                authorService.Add(addNewAuthor);
            }

            try
            {
                Regex rx = new Regex(@"^[0-9]{10,13}$");
                if (rx.Match(txtBookISBN.Text).Success)
                {
                    Book newBook = new Book()
                    {
                        ISBN        = txtBookISBN.Text,
                        Title       = txtBookTitle.Text,
                        Description = txtBookDesc.Text,
                        BookAuthor  = addNewAuthor
                    };
                    bookService.Add(newBook);
                    MessageBox.Show("Book added");
                }
                else
                {
                    MessageBox.Show("Invalid ISBN, should be a combination of 10 or 13 digits");
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("Unable to add, make sure you selected an author.");
                Debug.WriteLine(exp);
            }
        }
Esempio n. 25
0
        public async Task Add_Test()
        {
            // arrange
            var fakeUowProvider  = A.Fake <IUnitOfWorkProvider>();
            var fakeRepoProvider = A.Fake <IAuthorRepositoryProvider>();
            var fakeRepo         = A.Fake <IAuthorRepository>();
            var fakeUow          = A.Fake <IUnitOfWork>();

            A.CallTo(() => fakeUowProvider.Get()).Returns(fakeUow);
            A.CallTo(() => fakeRepoProvider.Get(fakeUow)).Returns(fakeRepo);
            AuthorService service = new AuthorService(fakeUowProvider, fakeRepoProvider);
            Author        author  = new Author {
                FirstName = "John", LastName = "Smith"
            };

            // act
            await service.Add(author);

            // assert
            A.CallTo(() => fakeRepo.Create(author)).MustHaveHappened();
            A.CallTo(() => fakeUow.Dispose()).MustHaveHappened();
        }
Esempio n. 26
0
        /// <summary>
        /// "Add new author"-knapp
        /// </summary>
        private void btnAddNewAuthor_Click(object sender, EventArgs e)
        {
            if (textBoxAuthorName.Text == "")
            {
                MessageBox.Show("You need to enter a name of the author.", "Error!");
            }
            else if (!textBoxAuthorName.Text.All(char.IsLetter))
            {
                MessageBox.Show("Name can only contain letters.", "Error!");
            }
            else
            {
                Author author = new Author(textBoxAuthorName.Text);
                authorService.Add(author);

                MessageBox.Show("You have now added the author: " + textBoxAuthorName.Text);
                textBoxAuthorName.Clear();
                AuthorTabShowAllAuthors(authorService.All());
                BookTabShowAllAuthors(authorService.All());
                BookTabBooksByAuthor(authorService.All());
            }
        }
        public IActionResult JoinInfluencers([FromForm] AddAuthorViewModel model)
        {
            authorService.Add(model.Nickname, model.Email);

            return(Redirect(Url.Action("Index", "Article")));
        }
Esempio n. 28
0
 private void AddAuthor_Click(object sender, EventArgs e)
 {
     _authorService.Add(authorNameField.Text);
 }
Esempio n. 29
0
 public IActionResult Post([FromBody] PostAuthorViewModel author)
 {
     _authorService.Add(author);
     return(Ok());
 }
Esempio n. 30
0
 public Author Add([FromBody] Author author)
 {
     return(_authorService.Add(author));
 }