public ActionResult EditAndCreate(AuthorModel author) { BAuthor oldAuthor = AutoMapper <AuthorModel, BAuthor> .Map(author); authorService.CreateOrUpdate(oldAuthor); return(PartialView("ViewAuthors", AutoMapper <IEnumerable <BAuthor>, List <AuthorModel> > .Map(authorService.GetAuthors))); }
public AuthorModel Post(AuthorModel author) { BAuthor newAuthor = AutoMapper <AuthorModel, BAuthor> .Map(author); authorService.CreateOrUpdate(newAuthor); return(AutoMapper <BAuthor, AuthorModel> .Map(authorService.GetForName(author.FirstName))); }
public ApiResponseDto <List <BookAuthorDto> > GetBook() { var book = _bookService.GetBook(); List <BookAuthorDto> bookAuthorDtoList = new List <BookAuthorDto>(); BookAuthorDto bookAuthorDtos; if (book != null) { foreach (var item in book) { var author = BAuthor.GetAuthorByID(item.FK_AuthorID); bookAuthorDtos = new BookAuthorDto() { ID = item.ID, BookName = item.Name, PublishedYear = item.PublishedYear, Cover = item.Cover, AuthorName = author.Name }; bookAuthorDtoList.Add(bookAuthorDtos); } return(ApiResponseDto <List <BookAuthorDto> > .SuccessResponse(bookAuthorDtoList, "basarili")); } return(ApiResponseDto <List <BookAuthorDto> > .FailedResponse("basarisiz")); }
public BAuthor GetForName(string name) { BAuthor author = AutoMapper <Authors, BAuthor> .Map(Database.Authors.Find(i => i.FirstName == name).FirstOrDefault()); if (author != null) { return(author); } return(new BAuthor()); }
public ApiResponseDto <List <AuthorDto> > GetAuthor() { var author = BAuthor.GetAuthor(); if (author == null) { return(ApiResponseDto <List <AuthorDto> > .FailedResponse("basarisiz")); } return(ApiResponseDto <List <AuthorDto> > .SuccessResponse(author, "basarili")); }
public ApiResponseDto <AuthorDto> CreateAuthor(AuthorDto authorDto) { var author = BAuthor.CreateAuthor(authorDto); if (author == null) //yazar varmış { var getAuthor = BAuthor.GetAuthorByName(authorDto.Name); return(ApiResponseDto <AuthorDto> .FailedResponseData(getAuthor, "basarili")); } else { return(ApiResponseDto <AuthorDto> .SuccessResponse(author, "basarili")); } }
public void CreateOrUpdate(BAuthor author) { if (author.Id == 0) { Authors dauthor = new Authors() { FirstName = author.FirstName, LastName = author.LastName }; Database.Authors.Create(dauthor); } else { Authors editAuthor = AutoMapper <BAuthor, Authors> .Map(author); Database.Authors.Update(editAuthor); } Database.Save(); }
public void Delete(int id) { BAuthor.DelAuthor(id); }