public IEnumerable <Rubric> GetRubricsHierarchy() { var rubrics = Rubric.FormTree(Ninject.Get <GetRubricsQuery>().Execute()).ToArray(); ClearTree(rubrics); return(rubrics); }
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()); }
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); }
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); }
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); } }
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); }
public IEnumerable <Reader> GetBookObligators(Book book) { var query = Ninject.Get <GetBookObligatorsQuery>(); query.Book = book; return(query.Execute()); }
public IEnumerable <Author> GetBookAuthors(Book book) { var query = Ninject.Get <GetBookAuthorsQuery>(); query.Book = book; return(query.Execute()); }
public IEnumerable <RequestRejected> GetRejectedRequests(Card card) { var query = Ninject.Get <GetRejectedRequestsQuery>(); query.Card = card; return(query.Execute().OrderByDescending(r => r.Id.Id.CreateDate)); }
public Book DeleteBook(Book book) { var query = Ninject.Get <DeleteBookQuery>(); query.Book = book; query.Execute(); return(book); }
public Book AddBook(Book book) { var query = Ninject.Get <InsertBookQuery>(); query.Book = book; query.Execute(); return(book); }
public Rubric DeleteRubric(Rubric rubric) { var query = Ninject.Get <DeleteRubricQuery>(); query.Rubric = rubric; query.Execute(); return(rubric); }
public Reader DeleteReader(Reader reader) { var query = Ninject.Get <DeleteReaderQuery>(); query.Reader = reader; query.Execute(); return(reader); }
public Author AddAuthor(Author author) { var query = Ninject.Get <InsertAuthorQuery>(); query.Author = author; query.Execute(); return(author); }
static void Main(string[] args) { Ninject.InitKernel(NatsClientTypeEnum.Subscriber); var publisher = Ninject.Get <INatsClient>(); var task = publisher.Run("foo"); task.Start(); }
static void Main() { Ninject.InitKernel(NatsClientTypeEnum.Publisher); var publisher = Ninject.Get <INatsClient>(); var task = publisher.Run("foo"); task.Start(); }
public Publisher DeletePublisher(Publisher publisher) { var query = Ninject.Get <DeletePublisherQuery>(); query.Publisher = publisher; query.Execute(); return(publisher); }
public Rubric AddRubric(Rubric rubric) { var query = Ninject.Get <InsertRubricQuery>(); query.Rubric = rubric; query.Execute(); return(rubric); }
public Publisher AddPublisher(Publisher publisher) { var query = Ninject.Get <InsertPublisherQuery>(); query.Publisher = publisher; query.Execute(); return(publisher); }
public Author DeleteAuthor(Author author) { var query = Ninject.Get <DeleteAuthorQuery>(); query.Author = author; query.Execute(); return(author); }
void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (!(e.Cancel = !DialogMessages.Question("Вы уверены, что хотите покинуть систему?"))) { try { GetAuthenticationProxy().LogOut(Ninject.Get <AuthenticationData>()); } catch { } } }
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))); }
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(); } }
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); }
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); }
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); }
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)); }
//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); }
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); }
protected override TypedEditForm <Author> CreateEditForm() { return(Ninject.Get <AuthorEditForm>()); }