Ejemplo n.º 1
0
        public IEnumerable <Rubric> GetRubricsHierarchy()
        {
            var rubrics = Rubric.FormTree(Ninject.Get <GetRubricsQuery>().Execute()).ToArray();

            ClearTree(rubrics);
            return(rubrics);
        }
Ejemplo n.º 2
0
        public IEnumerable <Book> GetBooks(Rubric rubric = null, Publisher publisher = null, Author author = null, string search = "")
        {
            var books = Ninject.Get <GetBooksQuery>().Execute();

            if (rubric != null)
            {
                var rubrics    = GetRubrics();
                var dictionary = rubrics.ToDictionary(r => r.Id);
                if (dictionary.ContainsKey(rubric.Id))
                {
                    rubric = dictionary[rubric.Id];
                    books  = from b in books
                             where b.Rubric.Id == rubric.Id || dictionary.ContainsKey(b.Rubric.Id) && Rubric.IsChildOf(rubrics, dictionary[b.Rubric.Id], rubric)
                             select b;
                }
            }
            if (author != null)
            {
                var query = Ninject.Get <GetAuthorBooksQuery>();
                query.Author = author;
                var authorBooks = query.Execute();
                books = from b in books
                        join ab in authorBooks on b.Id equals ab.Id
                        select b;
            }
            books                 = publisher.Return(p => books.Where(b => b.Publisher.Id == p.Id), books);
            books                 = string.IsNullOrEmpty(search) ? books : from b in books
                            let s = search.ToLower()
                                    where b.Name.ToLower().Contains(s) || (b.Annotation ?? string.Empty).ToLower().Contains(s)
                                    select b;

            return(books.ToArray());
        }
Ejemplo n.º 3
0
        public IEnumerable <Author> SetBookAuthors(Book book, IEnumerable <Author> authors)
        {
            var existsAuthors       = GetBookAuthors(book).ToArray();
            var existsDictionary    = existsAuthors.ToDictionary(a => a.Id);
            var insertingDictionary = authors.ToDictionary(a => a.Id);

            var provider = Factory.Get();
            var executor = Ninject.Get <Executor>();

            //сначала удаляем те, что существуют, но больше не нужные
            //затем добавляем те, что не существуют
            executor.ExecuteNonQueries((from a in existsAuthors
                                        where !insertingDictionary.ContainsKey(a.Id)
                                        select(BookAuthorQuery) new DeleteBookAuthorQuery(provider)
            {
                Book = book,
                Author = a
            })
                                       .Union(from a in authors
                                              where !existsDictionary.ContainsKey(a.Id)
                                              select(BookAuthorQuery) new InsertBookAuthorQuery(provider)
            {
                Book   = book,
                Author = a
            }));
            return(authors);
        }
Ejemplo n.º 4
0
        public Reader AddReader(Reader reader)
        {
            if (GetReaders().Any(r => r.PassportNumber == reader.PassportNumber && r.Card.ExpiryDate.Date > DateTime.Now.Date))
            {
                throw new Exception("Читатель с таким номером паспорта уже существует и его читательский билет не истек! Добавление читателя невозможно");
            }

            var executor = Ninject.Get <Executor>();
            var provider = Factory.Get();

            reader.Card = new Card();
            var insertReader = new InsertReaderQuery(provider)
            {
                Reader = reader
            };
            var insertCard = new InsertCardQuery(provider)
            {
                Reader = reader
            };

            executor.ExecuteNonQueries(new NoValueQuery[] {
                insertReader,
                insertCard
            });
            return(reader);
        }
Ejemplo n.º 5
0
        void AddRequest(Book book)
        {
            var quantity = 1;

            using (var form = Ninject.Get <BookQuantityInputDialog>()) {
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                quantity = form.BookQuantity;
            }

            if (!Requests.Any(r => r.Book.Id == book.Id))
            {
                Requests.Add(new Request()
                {
                    Id = new RequestHeader()
                    {
                        Id = -1
                    },
                    Book         = book,
                    BookQuantity = quantity
                });
                Requests = Requests.OrderBy(r => r.Book.Name).ToList();
                gcResult.Bind(Requests);
            }
        }
Ejemplo n.º 6
0
        public RequestApproved CloseRequest(RequestApproved request)
        {
            request = GetRequestApproved(request);

            if (request.IsReturned)
            {
                throw new Exception("Книга уже возвращена");
            }

            var returnBook = Ninject.Get <UpdateBooksQuantityQuery>();

            returnBook.Book         = request.Id.Book;
            returnBook.BookQuantity = request.Id.BookQuantity;

            var closeRequest = Ninject.Get <CloseRequestQuery>();

            closeRequest.RequestApproved = request;

            var executor = Ninject.Get <Executor>();

            try {
                executor.ExecuteNonQueries(new NoValueQuery[] {
                    returnBook,
                    closeRequest
                });
                request.IsReturned = true;
            } catch (Exception exc) {
                throw exc;
            }
            return(request);
        }
Ejemplo n.º 7
0
        public IEnumerable <Reader> GetBookObligators(Book book)
        {
            var query = Ninject.Get <GetBookObligatorsQuery>();

            query.Book = book;
            return(query.Execute());
        }
Ejemplo n.º 8
0
        public IEnumerable <Author> GetBookAuthors(Book book)
        {
            var query = Ninject.Get <GetBookAuthorsQuery>();

            query.Book = book;
            return(query.Execute());
        }
Ejemplo n.º 9
0
        public IEnumerable <RequestRejected> GetRejectedRequests(Card card)
        {
            var query = Ninject.Get <GetRejectedRequestsQuery>();

            query.Card = card;
            return(query.Execute().OrderByDescending(r => r.Id.Id.CreateDate));
        }
Ejemplo n.º 10
0
        public Book DeleteBook(Book book)
        {
            var query = Ninject.Get <DeleteBookQuery>();

            query.Book = book;
            query.Execute();
            return(book);
        }
Ejemplo n.º 11
0
        public Book AddBook(Book book)
        {
            var query = Ninject.Get <InsertBookQuery>();

            query.Book = book;
            query.Execute();
            return(book);
        }
Ejemplo n.º 12
0
        public Rubric DeleteRubric(Rubric rubric)
        {
            var query = Ninject.Get <DeleteRubricQuery>();

            query.Rubric = rubric;
            query.Execute();
            return(rubric);
        }
Ejemplo n.º 13
0
        public Reader DeleteReader(Reader reader)
        {
            var query = Ninject.Get <DeleteReaderQuery>();

            query.Reader = reader;
            query.Execute();
            return(reader);
        }
Ejemplo n.º 14
0
        public Author AddAuthor(Author author)
        {
            var query = Ninject.Get <InsertAuthorQuery>();

            query.Author = author;
            query.Execute();
            return(author);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Ninject.InitKernel(NatsClientTypeEnum.Subscriber);
            var publisher = Ninject.Get <INatsClient>();
            var task      = publisher.Run("foo");

            task.Start();
        }
Ejemplo n.º 16
0
        static void Main()
        {
            Ninject.InitKernel(NatsClientTypeEnum.Publisher);
            var publisher = Ninject.Get <INatsClient>();
            var task      = publisher.Run("foo");

            task.Start();
        }
Ejemplo n.º 17
0
        public Publisher DeletePublisher(Publisher publisher)
        {
            var query = Ninject.Get <DeletePublisherQuery>();

            query.Publisher = publisher;
            query.Execute();
            return(publisher);
        }
Ejemplo n.º 18
0
        public Rubric AddRubric(Rubric rubric)
        {
            var query = Ninject.Get <InsertRubricQuery>();

            query.Rubric = rubric;
            query.Execute();
            return(rubric);
        }
Ejemplo n.º 19
0
        public Publisher AddPublisher(Publisher publisher)
        {
            var query = Ninject.Get <InsertPublisherQuery>();

            query.Publisher = publisher;
            query.Execute();
            return(publisher);
        }
Ejemplo n.º 20
0
        public Author DeleteAuthor(Author author)
        {
            var query = Ninject.Get <DeleteAuthorQuery>();

            query.Author = author;
            query.Execute();
            return(author);
        }
Ejemplo n.º 21
0
 void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!(e.Cancel = !DialogMessages.Question("Вы уверены, что хотите покинуть систему?")))
     {
         try {
             GetAuthenticationProxy().LogOut(Ninject.Get <AuthenticationData>());
         } catch {
         }
     }
 }
Ejemplo n.º 22
0
 public IEnumerable <RequestCreator> GetRequestCreators(string search = "")
 {
     search = (search ?? string.Empty).Trim().ToLower();
     return
         (Ninject.Get <GetRequestCreatorsQuery>()
          .Execute()
          .Where(r =>
                 r.FirstName.ToLower().Contains(search) ||
                 r.LastName.ToLower().Contains(search) ||
                 r.MiddleName.ToLower().Contains(search) ||
                 r.Card.Id.ToString().Contains(search)));
 }
Ejemplo n.º 23
0
 void OnEndLoadAuthors(Book book, IEnumerable <Author> bookAuthors, IEnumerable <Author> authors)
 {
     Ninject.Rebind <BookAuthorEditForm>().ToMethod(method => {
         return(new BookAuthorEditForm(book, authors)
         {
             Data = bookAuthors,
             Operation = EditFormOperation.Insert
         });
     });
     using (var form = Ninject.Get <BookAuthorEditForm>()) {
         form.ShowDialog();
     }
 }
Ejemplo n.º 24
0
        public Rubric UpdateRubric(Rubric rubric)
        {
            var rubrics = GetRubrics();

            if (Rubric.IsChildOf(rubrics, rubric, rubric))
            {
                throw new Exception("Обнаружена циклическая зависимость рубрик. Обновление рубрики невозможно");
            }

            var query = Ninject.Get <UpdateRubricQuery>();

            query.Rubric = rubric;
            query.Execute();
            return(rubric);
        }
Ejemplo n.º 25
0
        public AuthenticationData Authenticate(string name, string hash)
        {
            var employee = Ninject.Get <GetEmployeesQuery>().Execute().FirstOrDefault(e => e.Name == name && e.Password == hash);

            if (employee != null)
            {
                var result = new AuthenticationData()
                {
                    Id       = Guid.NewGuid(),
                    Employee = employee
                };
                Authorized[result.Id] = result;
                return(result);
            }
            return(null);
        }
Ejemplo n.º 26
0
        public Reader RenewCard(Reader reader)
        {
            reader = GetReaders().FirstOrDefault(r => r.Id == reader.Id);
            if (reader == null)
            {
                throw new Exception("Читатель не найден");
            }
            if (reader.Card.ExpiryDate.Date > DateTime.Now.Date)
            {
                throw new Exception("Срок действия читательского билета еще не истек. Продление невозможно");
            }
            if (reader.Card.ExpiryDate.AddMonths(1).Date < DateTime.Now.Date)
            {
                throw new Exception("Продление читательского билета возможно только в течении месяца после его срока истечения");
            }

            var query = Ninject.Get <RenewCardQuery>();

            query.Reader = reader;
            query.Execute();
            return(reader);
        }
Ejemplo n.º 27
0
        public RequestCreator CreateRequest(Reader reader, IEnumerable <Request> requests)
        {
            if (requests == null || !requests.Any())
            {
                throw new Exception("Для создания запроса необходимо выбрать хотя бы одну книгу");
            }

            var card = GetReaders().Select(r => r.Card).FirstOrDefault(c => c.Id == reader.Card.Id);

            if (card == null)
            {
                throw new Exception("Не удалось обнаружить читательский билет. Возможно, билет не создан");
            }
            if (card.ExpiryDate.Date < DateTime.Now.Date)
            {
                throw new Exception("Срок действия читательского билета истек. Перед созданием запроса продлите читательский билет");
            }

            var executor = Ninject.Get <Executor>();
            var id       = Ninject.Get <GenerateRequestIdQuery>().Execute();
            var provider = Factory.Get();

            foreach (var r in requests)
            {
                r.Id = new RequestHeader()
                {
                    Id     = id,
                    Reader = reader
                };
            }

            executor.ExecuteNonQueries(from r in requests
                                       select new InsertRequestQuery(provider)
            {
                Request = r
            });

            return(GetRequestCreators().FirstOrDefault(c => c.Card.Id == reader.Card.Id));
        }
Ejemplo n.º 28
0
        //public IEnumerable<RequestApproved> GetApprovedRequests(RequestHeader request) {
        //    var query = Ninject.Get<GetApprovedRequestsQuery>();
        //    query.Request = request;
        //    return query.Execute();
        //}

        //public IEnumerable<RequestRejected> GetRejectedRequests(RequestHeader request) {
        //    var query = Ninject.Get<GetRejectedRequestsQuery>();
        //    query.Request = request;
        //    return query.Execute();
        //}

        public RequestApproved RenewRequest(RequestApproved request)
        {
            request = GetRequestApproved(request);

            if (request.IsReturned)
            {
                throw new Exception("Книга уже возвращена. Продление невозможно");
            }

            if (DateTime.Now.Date <= request.ReturnDate.Date)
            {
                throw new Exception("Срок возврата еще не истек. Продление невозможно");
            }

            var command = Ninject.Get <RenewRequestQuery>();

            command.RequestApproved = request;
            try {
                command.Execute();
            } catch (DbException exc) {
                throw new Exception("Достигнут предел числа продлений. Дальнейшее продление невозможно");
            }
            return(request);
        }
Ejemplo n.º 29
0
        public IEnumerable <Notification> SendNotifications()
        {
            var query = Ninject.Get <SendNotificationsQuery>();

            query.Execute();
            var sended = query.Notifications.ToList();
            var result = new List <Notification>();

            if (sended.Count > 0)
            {
                result.AddRange(
                    from s in sended
                    join n in Ninject.Get <GetNotificationsQuery>().Execute() on new {
                    RequestId = s.RequestId,
                    BookId    = s.BookId
                } equals new {
                    RequestId = n.Id.Id.Id,
                    BookId    = n.Id.Book.Id
                }
                    select n
                    );
            }
            return(result);
        }
Ejemplo n.º 30
0
 protected override TypedEditForm <Author> CreateEditForm()
 {
     return(Ninject.Get <AuthorEditForm>());
 }