public async Task<IHttpActionResult> PutAuthor(int id, Author author)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != author.Id)
            {
                return BadRequest();
            }

            db.Entry(author).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthorExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemple #2
0
        public IActionResult OnPost()
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            Library.Models.Author author = this.Context.Authors.Where(a => a.Name == this.Author).FirstOrDefault();
            if (author == null)
            {
                author = new Library.Models.Author()
                {
                    Name = this.Author
                };
                this.Context.Authors.Add(author);
                this.Context.SaveChanges();
            }

            Book book = new Book()
            {
                Title          = this.Title,
                Description    = this.Description,
                BookCoverImage = this.ImageUrl,
                AuthorId       = author.Id,
                IsAvailable    = true
            };

            this.Context.Books.Add(book);
            this.Context.SaveChanges();

            return(this.RedirectToPage("/Books/Details", new { id = book.Id }));
        }
Exemple #3
0
 public Book(Author _author, string title, string description, long isbnNumber, int nrOfCopies)
 {
     this.author = _author;
     this.Title = title;
     this.Description = description;
     this.IsbnNumber = isbnNumber;
     this.NrOfCopies = nrOfCopies;
     CreateBookCopyList(nrOfCopies);
 }
Exemple #4
0
 public Book(long isbnNumber, string title, int copies, string description, Author _author)
 {
     this.BookId = generateNewId();
     this.IsbnNumber = isbnNumber;
     this.Title = title;
     this.nrOfCopies = copies;
     this.Description = description;
     this.author = _author;
 }
        public async Task<IHttpActionResult> PostAuthor(Author author)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Author.Add(author);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = author.Id }, author);
        }
        public void ParseCsv()
        {
            var path = Application.StartupPath + "/../../Files/library.csv";
            var lines = File.ReadAllLines(path, Encoding.GetEncoding("iso-8859-1"));

            foreach (string line in lines)
            {
                var items = line.Split(new string[] { ";" }, StringSplitOptions.None);

                string key = items[2] + items[3];

                if (!authorList.ContainsKey(key))
                {
                    Author author;
                    author = new Author { Name = items[2] + " " + items[3]};
                    authorList.Add(items[2] + items[3], author);
                }
                Book bookToAdd = new Book { Title = items[1], Author = authorList.Where(a => a.Key == items[2] + items[3]).First().Value, Isbn = items[0], Description = items[4], Copies = new List<BookCopy>()};
                bookList.Add(bookToAdd);
            }
        }
Exemple #7
0
        /// <summary>
        /// Add new book
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="isbn"></param>
        /// <param name="author"></param>
        /// <param name="noOfCopies"></param>
        public void Add(string title, string description, string isbn, Author author, int noOfCopies)
        {
            if (ContainsTitle(title))
            {
                throw new ValidationException("The title you are trying to add already exists");
            }
            else if (ContainsISBN(isbn))
            {
                throw new ValidationException("The ISBN you are trying to add already exists");
            }

            Book book = new Book()
            {
                Title = title,
                Description = description,
                ISBN = isbn,
                Author = author
            };

            // Add book copies to the new book
            List<BookCopy> bookCopies = new List<BookCopy>();
            for (int i = 0; i < noOfCopies; i++)
            {
                bookCopies.Add(new BookCopy() {Book = book});
            }

            book.BookCopies = bookCopies;

            ValidationResult error = ObjectValidator.Validate(book);

            if (error != null)
            {
                throw new ValidationException(error.ErrorMessage);
            }
            else
            {
                _bookRepository.Add(book);
                OnUpdated(new EventArgs());
            }
        }
        private bool CreateAuthor()
        {
            int affectedRows = 0;

            using (LibraryEntities db = new LibraryEntities())
            {
                Models.Author newauthor = new Models.Author
                {
                    Name    = txtName_Author.Text,
                    Surname = txtSurname_Author.Text
                };
                db.Authors.Add(newauthor);

                db.SaveChanges();
            }
            if (affectedRows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #9
0
        /// <summary>
        /// Add new author
        /// </summary>
        /// <param name="name"></param>
        public void Add(string name)
        {
            if (ContainsName(name))
            {
                throw new ValidationException("The author you are trying to add already exists");
            }

            Author author = new Author()
            {
                Name = name
            };

            ValidationResult error = ObjectValidator.Validate(author);

            if (error != null)
            {
                throw new ValidationException(error.ErrorMessage);
            }
            else
            {
                _authorRepository.Add(author);
                OnUpdated(new EventArgs());
            }
        }
 public void Add(Author author)
 {
     _authorRepository.Add(author);
     OnUpdated(this, new EventArgs());
 }
 public void Remove(Author item)
 {
 }
 public void Edit(Author item)
 {
 }
 public void Add(Author item)
 {
 }
Exemple #14
0
 partial void DeleteAuthor(Author instance);
Exemple #15
0
 partial void UpdateAuthor(Author instance);
Exemple #16
0
 partial void InsertAuthor(Author instance);