Example #1
0
        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)));
        }
Example #3
0
        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"));
        }
Example #4
0
        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());
        }
Example #5
0
        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"));
        }
Example #6
0
        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"));
            }
        }
Example #7
0
        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();
        }
Example #8
0
 public void Delete(int id)
 {
     BAuthor.DelAuthor(id);
 }