Beispiel #1
0
        // @Carte - cartea ce se cumpara
        // @numberOfBooks - numarul de exemplare

        public void BuyBooks(CarteDTO carteDto, short numberOfBooks)
        {
            Autor autor = autorRepository.GetAutorByFirstAndLastName(carteDto.AutorDto.nume, carteDto.AutorDto.prenume);

            if (autor == null)
            {
                Autor autorToBeInserted = AutorTransformer.fromDtoToModel(carteDto.AutorDto);
                autor = autorRepository.InsertObject(autorToBeInserted);
            }

            Gen gen = genderRepository.GetGenByDescription(carteDto.GenDto.descriere);

            if (gen == null)
            {
                Gen genToBeInserted = GenTransformer.fromDtoToModel(carteDto.GenDto);
                gen = genderRepository.InsertObject(genToBeInserted);
            }

            while (numberOfBooks > 0)
            {
                Carte bookToSave = new Carte()
                {
                    autorId  = autor.autorId,
                    genId    = gen.genId,
                    titlu    = carteDto.titlu,
                    Autor    = autor,
                    Gen      = gen,
                    Imprumut = new List <Imprumut>()
                };
                bookRepository.InsertObject(bookToSave);
                numberOfBooks--;
            }

            bookRepository.SaveChanges();
        }
Beispiel #2
0
        public void LoanBook(CarteDTO book, CititorDTO reader, DateTime loanDate, DateTime deadLine)
        {
            Imprumut loan = new Imprumut()
            {
                carteId      = book.carteId,
                cititorId    = reader.cititorId,
                dataImprumut = loanDate,
                dataScadenta = deadLine
            };

            loanRepository.InsertObject(loan);
            loanRepository.SaveChanges();
        }