Пример #1
0
        public bool Create(DealCreateApiModel apiModel, int createdUser)
        {
            var validator = _dealValidator.Validate(apiModel);

            if (validator.IsValid)
            {
                return(_dealRepository.Create(apiModel, createdUser));
            }
            return(false);
        }
Пример #2
0
        private void addDealButton_Click(object sender, EventArgs e)
        {
            var          addDealForm  = new AddDealForm();
            DialogResult dialogResult = addDealForm.ShowDialog(this);

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }

            int readerId = addDealForm.SelectedReader.Id;

            var dealRepository = new DealRepository();

            var            bookCopyInDealRepository = new BookCopyInDealRepository();
            BookCopyInDeal bookCopyInDeal;
            var            bookCopyRepository = new BookCopyRepository();

            Deal deal = new Deal
            {
                LibrarianId = _librarianId,
                ReaderId    = readerId,
                Date        = DateTime.UtcNow
            };

            dealRepository.Create(deal);
            var p = addDealForm.booksDataGridView.SelectedRows;

            for (int i = 0; i < p.Count; i++)
            {
                bookCopyInDeal = new BookCopyInDeal
                {
                    DealId     = deal.Id,
                    BookCopyId = bookCopyRepository.GetAvailableBookCopiesByBookId((int)p[i].Cells[0].Value)[0].Id,
                    RequiredDateOfReturning = DateTime.UtcNow.AddDays((int)addDealForm.daysNumericUpDown.Value)
                };
                bookCopyInDealRepository.Create(bookCopyInDeal);
            }
        }