public Book(string title, Editions edition, Author author, decimal price, int copies, AgeRestrictions ageRestriction, DateTime? releaseDate = null, string description = null) { this.Title = title; this.Description = description; this.Edition = edition; this.author = author; this.Price = price; this.Copies = copies; this.ReleaseDate = releaseDate; this.categories = new HashSet<Category>(); this.AgeRestriction = ageRestriction; this.relatedBooks = new HashSet<Book>(); }
public IHttpActionResult PostAuthor(AuthorBindingModel author) { var authorEntity = new Author { FristName = author.FirstName, LastName = author.LastName }; if (this.Data.Authors.All() .FirstOrDefault(a => a.FristName == authorEntity.FristName && a.LastName == authorEntity.LastName) != null) { return BadRequest("this author allready exists in the db"); } this.Data.Authors.Add(authorEntity); this.Data.SaveChanges(); return Ok("author added"); }
public static ApplicationUserManager Create() { // create our mocked user var user = new Author { UserName = "******", Email = "*****@*****.**" }; // mock the application user manager with mocked user store var mockedUserStore = new Mock<IUserStore<Author>>(); var applicationUserManager = new Mock<ApplicationUserManager>(mockedUserStore.Object); // mock the application user manager to always return our user object with any username and password applicationUserManager.Setup(x => x.FindAsync(It.IsAny<string>(), It.IsAny<string>())) .Returns(Task.FromResult(user)); // mock the application user manager create identity in order to generate valid access token when requested applicationUserManager.Setup(x => x.CreateIdentityAsync(It.IsAny<Author>(), It.IsAny<string>())) .Returns<Author, string>( (author, password) => Task.FromResult(new ClaimsIdentity(new[] {new Claim(ClaimTypes.Name, author.UserName)}, DefaultAuthenticationTypes.ApplicationCookie))); return applicationUserManager.Object; }
public IHttpActionResult Post([FromBody]AuthorOutputModel authorModel) { if (!this.ModelState.IsValid) { return this.BadRequest("The model state is invalid"); } Author author = new Author() { FirstName = authorModel.FirstName, LastName = authorModel.LastName }; this.data.Authors.Add(author); this.data.SaveChanges(); return this.Ok(new { author.Id } ); }
public AuthorDTO(Author author) { this.FirstName = author.FristName; this.LastName = author.LastName; }