コード例 #1
0
 public IHttpActionResult Post(AddAuthorBindingModel model)
 {
     Author author = new Author { FirstName = model.FirstName, LastName = model.LastName};
     _context.Authors.Add(author);
     _context.SaveChanges();
     return this.Ok(author);
 }
コード例 #2
0
 public static AuthorViewModel CreateViewModel(Author a)
 {
     return new AuthorViewModel
     {
         Id = a.Id,
         FirstName = a.FirstName,
         LastName = a.LastName
     };
 }
コード例 #3
0
 public AuthorViewModel(Author author)
 {
     Id = author.Id;
     FirstName = author.FirstName;
     LastName = author.LastName;
     Books = new List<BookViewModel>();
     foreach (var book in author.Books)
     {
         Books.Add(new BookViewModel(book));
     }
 }
コード例 #4
0
        public AuthorsBooksViewModel(Author author)
        {
            AuthorId = author.Id;

            AuthorBooks = new List<BookViewModel>();

            foreach (var book in author.Books)
            {
                AuthorBooks.Add(new BookViewModel(book));
            }
        }
コード例 #5
0
        public IHttpActionResult PostAuthor(AddAuthorBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            Author newAuthor = new Author { FirstName = model.FirstName, LastName = model.LastName };
            this.context.Authors.Add(newAuthor);
            this.context.SaveChanges();
            return this.Ok(newAuthor);
        }
コード例 #6
0
ファイル: AuthorViewModel.cs プロジェクト: ivan4otopa/SoftUni
        public AuthorViewModel(Author author)
        {
            this.Id = author.Id;
            this.FirstName = author.FirstName;
            this.LastName = author.LastName;
            this.BookTitles = new List<AuthorBooksTitlesViewModel>();

            foreach (var book in author.Books)
            {
                this.BookTitles.Add(new AuthorBooksTitlesViewModel(book));
            }
        }
コード例 #7
0
        public static AuthorViewModelMinified ConvertToAuthorViewModel(Author author)
        {
            string authorName = string.Format("{0} {1}", author.FirstName, author.LastName);

            AuthorViewModelMinified authorViewModel = new AuthorViewModelMinified
            {
                Id = author.Id,
                AuthorName = authorName
            };

            return authorViewModel;
        } 
コード例 #8
0
        public static AuthorViewModel ConvertToAuthorViewModel(Author author)
        {
            AuthorViewModel authorViewModel = new AuthorViewModel
                {
                    Id = author.Id,
                    FirstName = author.FirstName,
                    LastName = author.LastName,
                    BookTitles = author.Books.Select(b => b.Title)
                };

            return authorViewModel;
        }
コード例 #9
0
ファイル: AuthorViewModel.cs プロジェクト: nok32/SoftUni
        public static AuthorViewModel Create(Author author)
        {
            var authorView = new AuthorViewModel
            {
                Id = author.Id,
                FirstName = author.FirstName,
                LastName = author.LastName,
                BookTitles = new List<string>(),
                
            };

            AddBookTitles(authorView, author.Books);

            return authorView;
        }
コード例 #10
0
        public IHttpActionResult PostAuthor(AddAuthorBindingModel authorModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var author = new Author()
            {
                FirstName = authorModel.FirstName,
                LastName = authorModel.LastName
            };

            db.Authors.Add(author);
            db.SaveChanges();

            return this.Ok("Author created");
        }
コード例 #11
0
        public IHttpActionResult Create(AuthorBindindModel authorBindingModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var author = new Author()
            {
                FirstName = authorBindingModel.FirstName,
                LastName = authorBindingModel.LastName
            };

            this.data.Authors.Add(author);
            this.data.Save();

            AuthorViewModel authorViewModel = AuthorViewModel.ConvertToAuthorViewModel(author);
            return this.Ok(authorViewModel);
        }
コード例 #12
0
        public IHttpActionResult PostAuthor([FromBody]AddAuthorBindingModel authorModel)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var authorToAdd = new Author()
            {
                FirstName = authorModel.FirstName,
                LastName = authorModel.LastName
            };

            context.Authors.AddOrUpdate(authorToAdd);

            context.SaveChanges();

            return this.Ok(authorToAdd);
        }
コード例 #13
0
        public IHttpActionResult CreateAuthor([FromBody]AddAuthorBindingModel authorModel)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest();
            }

            var author = new Author()
            {
                FirstName = authorModel.FirstName,
                LastName = authorModel.LastName
            };

            unitOfWork.AuthorRepository.Insert(author);

            unitOfWork.Save();

            return this.Ok(author);
        }
コード例 #14
0
        public IHttpActionResult CreateAuthor(AuthorBindingModel authorModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var newAuthorModel = new Author
            {
                FirstName = authorModel.FirstName,
                LastName = authorModel.LastName
            };

            this.BookShopData.Authors.Add(newAuthorModel);
            this.BookShopData.SaveChanges();

            var authorViewModel = AuthorViewModel.CreateViewModel(newAuthorModel);

            return this.Ok(authorViewModel);
        }
コード例 #15
0
        public IHttpActionResult Post([FromBody]AuthorBindingModel author)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var newAuthor = new Author()
            {
                FirstName = author.FirstName,
                LastName = author.LastName
            };

            db.Authors.Add(newAuthor);


            db.SaveChanges();

            return this.Ok(newAuthor);
        }
コード例 #16
0
ファイル: AuthorsController.cs プロジェクト: nok32/SoftUni
        public IHttpActionResult AddNewAuthor([FromBody] AddAuthorBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            if (this.BookShopData.Authors.Any(a => a.FirstName == model.FirstName && a.LastName == model.LastName))
            {
                return this.BadRequest("Duplicate author.");
            }

            var author = new Author
            {
                FirstName = model.FirstName,
                LastName = model.LastName
            };

            this.BookShopData.Authors.Add(author);
            this.BookShopData.SaveChanges();

            return this.Ok(author);
        }
コード例 #17
0
        public IHttpActionResult AddAuthor(AuthorBindingModel model)
        {

            if (model == null)
            {
                this.ModelState.AddModelError("model", "The model cannot be null - (request is empty).");
            }

            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var author = new Author()
            {
                FirstName = model.FirstName ?? null,
                LastName = model.LastName
            };

            this.Data.Authors.Add(author);
            this.Data.SaveChanges();

            return this.Ok();
        }
コード例 #18
0
 //constructor include navigation properties only
 public Book()
 {
     this.categories = new HashSet<Category>();
     this.author = new Author();
     this.relatedBooks = new HashSet<Book>();
 }