Example #1
0
        public BookResponse GetBook(string id)
        {
            BookResponse resp = new BookResponse();
            int          bookId;

            if (int.TryParse(id, out bookId))
            {
                using (TablesContext context = new TablesContext())
                {
                    resp.Book = context.Books.Find(bookId);
                    if (resp.Book != null && !resp.Book.Deleted)
                    {
                        resp.Status  = (int)Constants.STATUSES.OK;
                        resp.Message = Constants.SUCCESS;
                    }
                    else
                    {
                        resp.Book    = null;
                        resp.Status  = (int)Constants.STATUSES.ERROR;
                        resp.Message = Constants.BOOK_NOT_FOUND;
                    }
                }
            }
            else
            {
                resp.Status  = (int)Constants.STATUSES.ERROR;
                resp.Message = Constants.ENTER_INT;
            }

            return(resp);
        }
Example #2
0
        public Order NewOrder(OrderRequest orderRequest)
        {
            using (TablesContext context = new TablesContext())
            {
                Order order = new Order
                {
                    UserId       = orderRequest.UserId,
                    TotalPayment = orderRequest.TotalPayment,
                    Status       = orderRequest.Status,
                };

                context.Orders.Add(order);
                context.SaveChanges();

                orderRequest.Books.ForEach(delegate(int book)
                {
                    BooksInOrder bookInOrder = new BooksInOrder
                    {
                        OrderId = context.Orders.ToList <Order>().Last().Id,
                        BookId  = book
                    };
                    context.BooksInOrders.Add(bookInOrder);
                    context.SaveChanges();
                });

                return(order);
            }
        }
Example #3
0
        public UserResponse Auth(Auth data)
        {
            UserResponse response = new UserResponse();

            if (data.Password.Equals(Constants.DEF_PASS))
            {
                using (TablesContext context = new TablesContext())
                {
                    var users = from u in context.Users where u.Email.Equals(data.Email) select u;
                    if (users != null && users.Count() > 0)
                    {
                        response.Status  = (int)Constants.STATUSES.OK;
                        response.Message = Constants.SUCCESS;
                        response.User    = users.First <User>();
                    }
                    else
                    {
                        response.Status  = (int)Constants.STATUSES.ERROR;
                        response.Message = Constants.WRONG_USER_DATA;
                    }
                }
            }
            else
            {
                response.Status  = (int)Constants.STATUSES.ERROR;
                response.Message = Constants.WRONG_USER_DATA;
            }
            return(response);
        }
Example #4
0
        public string RestoreBook(string id)
        {
            int  bookId;
            Book book;

            if (int.TryParse(id, out bookId))
            {
                using (TablesContext context = new TablesContext())
                {
                    book = context.Books.Find(bookId);
                    if (book.Deleted)
                    {
                        book.Deleted = false;
                        context.SaveChanges();
                        return(Constants.BOOK_RESTORED);
                    }
                    else
                    {
                        return(Constants.BOOK_NOT_DELETED);;
                    }
                }
            }
            else
            {
                return(Constants.ENTER_INT);
            }
        }
Example #5
0
        public UserResponse GetUser(string id)
        {
            UserResponse resp = new UserResponse();
            int          userId;

            if (int.TryParse(id, out userId))
            {
                using (TablesContext context = new TablesContext())
                {
                    resp.User = context.Users.Find(userId);
                    if (resp.User != null && !resp.User.Deleted)
                    {
                        resp.Status  = (int)Constants.STATUSES.OK;
                        resp.Message = Constants.SUCCESS;
                    }
                    else
                    {
                        resp.Status  = (int)Constants.STATUSES.ERROR;
                        resp.User    = null;
                        resp.Message = Constants.USER_NOT_FOUND;
                    }
                }
            }
            else
            {
                resp.Status  = (int)Constants.STATUSES.ERROR;
                resp.Message = Constants.ENTER_INT;
            }

            return(resp);
        }
Example #6
0
        public string PayOrder(string id)
        {
            int orderId;

            if (int.TryParse(id, out orderId))
            {
                Order order;
                using (TablesContext context = new TablesContext())
                {
                    order = context.Orders.Find(orderId);
                    if (order != null)
                    {
                        if (!order.Status)
                        {
                            order.Status = true;
                            context.SaveChanges();
                            return(Constants.ORDER_PAYED);
                        }
                        else
                        {
                            return(Constants.ORDER_ALREADY_PAYED);
                        }
                    }
                    else
                    {
                        return(Constants.ORDER_NOT_FOUND);
                    }
                }
            }
            else
            {
                return(Constants.ENTER_INT);
            }
        }
Example #7
0
 public InsertCommandContext(SchemaMetaData schemaMetaData, ParameterContext parameterContext, InsertCommand insertCommand) : base(insertCommand)
 {
     _tablesContext       = new TablesContext(insertCommand.Table);
     _columnNames         = insertCommand.UseDefaultColumns() ? schemaMetaData.GetAllColumnNames(insertCommand.Table.GetTableName().GetIdentifier().GetValue()) : insertCommand.GetColumnNames();
     _insertValueContexts = GetInsertValueContexts(parameterContext);
     _generatedKeyContext = new GeneratedKeyContextEngine(schemaMetaData).CreateGenerateKeyContext(parameterContext, insertCommand);
 }
Example #8
0
 public SelectCommandContext(SchemaMetaData schemaMetaData, string sql, ParameterContext parameterContext, SelectCommand sqlCommand) : base(sqlCommand)
 {
     _tablesContext      = new TablesContext(sqlCommand.GetSimpleTableSegments());
     _groupByContext     = new GroupByContextEngine().CreateGroupByContext(sqlCommand);
     _orderByContext     = new OrderByContextEngine().CreateOrderBy(sqlCommand, _groupByContext);
     _projectionsContext = new ProjectionsContextEngine(schemaMetaData).CreateProjectionsContext(sql, sqlCommand, _groupByContext, _orderByContext);
     _paginationContext  = new PaginationContextEngine().CreatePaginationContext(sqlCommand, _projectionsContext, parameterContext);
     _containsSubQuery   = ContainsSubQuery();
 }
Example #9
0
 public void RemoveLibrarian(int id)
 {
     using (TablesContext db = new TablesContext())
     {
         Librarian librarian = db.Librarians.Find(id);
         db.Librarians.Remove(librarian);
         db.SaveChanges();
         Console.WriteLine("Данные успешно удалены");
     }
 }
Example #10
0
 public void RemoveStudent(int id)
 {
     using (TablesContext db = new TablesContext())
     {
         Student student = db.Students.Find(id);
         db.Students.Remove(student);
         db.SaveChanges();
         Console.WriteLine("Данные успешно удалены");
     }
 }
Example #11
0
 // TODO to be remove, for test case only
 public SelectCommandContext(SelectCommand sqlCommand, GroupByContext groupByContext,
                             OrderByContext orderByContext, ProjectionsContext projectionsContext, PaginationContext paginationContext) : base(sqlCommand)
 {
     _tablesContext           = new TablesContext(sqlCommand.GetSimpleTableSegments());
     this._groupByContext     = groupByContext;
     this._orderByContext     = orderByContext;
     this._projectionsContext = projectionsContext;
     this._paginationContext  = paginationContext;
     _containsSubQuery        = ContainsSubQuery();
 }
Example #12
0
        public Book NewBook(Book book)
        {
            using (TablesContext context = new TablesContext())
            {
                context.Books.Add(book);
                context.SaveChanges();
            }

            return(book);
        }
Example #13
0
 public AllBooksResponse AllBooks()
 {
     using (TablesContext context = new TablesContext())
     {
         AllBooksResponse resp = new AllBooksResponse();
         resp.Status  = 0;
         resp.Message = "Success";
         resp.Books   = context.Books.ToList <Book>();
         return(resp);
     }
 }
Example #14
0
        public OrdersByUser GetOrdersByUserId(string id)
        {
            OrdersByUser resp = new OrdersByUser();
            int          userId;

            if (int.TryParse(id, out userId))
            {
                resp.OrderData = new List <OrderData>();
                using (TablesContext context = new TablesContext())
                {
                    var orders = from o in context.Orders where o.UserId.Equals(userId) select o;
                    if (orders != null && orders.Count() > 0)
                    {
                        orders.ToList <Order>().ForEach(delegate(Order order)
                        {
                            List <Book> booksInOrder = new List <Book>();
                            OrderData current        = new OrderData
                            {
                                Id           = order.Id,
                                UserId       = order.UserId,
                                TotalPayment = order.TotalPayment,
                                Status       = order.Status
                            };

                            var books = from b in context.BooksInOrders where b.OrderId.Equals(current.Id) select b;
                            if (books != null && books.Count() > 0)
                            {
                                books.ToList <BooksInOrder>().ForEach(delegate(BooksInOrder book)
                                {
                                    booksInOrder.Add(context.Books.Find(book.BookId));
                                });
                            }
                            current.Books = booksInOrder;
                            resp.OrderData.Add(current);
                        });
                        resp.Status  = (int)Constants.STATUSES.OK;
                        resp.Message = Constants.SUCCESS;
                    }
                    else
                    {
                        resp.Status  = (int)Constants.STATUSES.ERROR;
                        resp.Message = Constants.NO_ORDERS;
                    }
                }
            }
            else
            {
                resp.Status  = (int)Constants.STATUSES.ERROR;
                resp.Message = Constants.ENTER_INT;
            }

            return(resp);
        }
Example #15
0
        public void Add()
        {
            string EBookName;
            string EBookAuthor;
            string EPublisher;
            int    EYearOfPublish;
            string EGenre;
            int    EExemplarAmount;

            try
            {
                Console.WriteLine("Введите название книги");
                EBookName = Console.ReadLine();
                Console.WriteLine("Введите автора книги");
                EBookAuthor = Console.ReadLine();
                Console.WriteLine("Введите издатель книги");
                EPublisher = Console.ReadLine();
                Console.WriteLine("Введите год издания книги");
                EYearOfPublish = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Введите жанр книги");
                EGenre = Console.ReadLine();
                using (TablesContext db = new TablesContext())
                {
                    Genre genre = new Genre {
                        Name = EGenre
                    };
                    Book books = new Book {
                        BookName = EBookName, BookAuthor = EBookAuthor, Publisher = EPublisher, YearOfPublish = EYearOfPublish
                    };
                    db.Genres.Add(genre);
                    db.Books.Add(books);

                    Console.WriteLine("Введите количество экземпляров книги");
                    EExemplarAmount = Convert.ToInt32(Console.ReadLine());

                    for (int i = 0; i < EExemplarAmount; i++)
                    {
                        Console.Write("Введите номер экземпляра {0} > ", i + 1);
                        string   EExemplar = Console.ReadLine();
                        Exemplar exemplars = new Exemplar {
                            ExemplarNumber = EExemplar, BookId = books.Id, ExemplarStatus = "In Stock"
                        };
                        db.Exemplars.Add(exemplars);
                    }

                    db.SaveChanges();
                    Console.WriteLine("Объекты успешно сохранены");
                }
            }
            catch (Exception) { Console.WriteLine("Данные введены не верно"); }
        }
Example #16
0
        public void ShowLibrarian(int id)
        {
            using (TablesContext db = new TablesContext())
            {
                Librarian librarian = db.Librarians.Find(id);

                Console.WriteLine("Логин:                      " + librarian.LibLogin);
                Console.WriteLine("Имя:                        " + librarian.LibFirstName);
                Console.WriteLine("Фамилия:                    " + librarian.LibLastName);
                Console.WriteLine("Отчество:                   " + librarian.LibPatronymicName);
                Console.WriteLine("Номер телефона:             " + librarian.LibPhone);
                Console.WriteLine("Адрес:                      " + librarian.LibAdress);
            }
        }
Example #17
0
 public void FindN(string name)
 {
     try
     {
         using (TablesContext db = new TablesContext())
         {
             var books = db.Books.Where(b => b.BookName == name).FirstOrDefault();
             var table = new ConsoleTable("Id", "Название", "Автор");
             table.AddRow(books.Id, books.BookName, books.BookAuthor);
             table.Write();
         }
     }
     catch (Exception) { Console.WriteLine("Поиск не дал результатов, попробуйте повторить запрос"); }
 }
Example #18
0
 public void Show()
 {
     using (TablesContext db = new TablesContext())
     {
         var book = db.Books;
         Console.WriteLine("Список всех книг:");
         var table = new ConsoleTable("Id", "Название", "Автор");
         foreach (Book b in book)
         {
             table.AddRow(b.Id, b.BookName, b.BookAuthor);
         }
         table.Write();
     }
 }
Example #19
0
 public void ShowLibrarian()
 {
     using (TablesContext db = new TablesContext())
     {
         var librarians = db.Librarians;
         var table      = new ConsoleTable("Id", "Логин", "Имя", "Фамилия", "Отчество");
         Console.WriteLine("Список всех пользователей:\n");
         foreach (Librarian l in librarians)
         {
             table.AddRow(l.Id, l.LibFirstName, l.LibFirstName, l.LibLastName, l.LibPatronymicName);
         }
         table.Write();
     }
 }
Example #20
0
        public OrderResponse GetOrder(string id)
        {
            OrderResponse resp = new OrderResponse();
            int           orderId;

            if (int.TryParse(id, out orderId))
            {
                Order       order;
                List <Book> booksInOrder = new List <Book>();
                using (TablesContext context = new TablesContext())
                {
                    order = context.Orders.Find(orderId);
                    if (order != null)
                    {
                        resp.Status    = (int)Constants.STATUSES.OK;
                        resp.Message   = Constants.SUCCESS;
                        resp.OrderData = new OrderData
                        {
                            Id           = order.Id,
                            UserId       = order.UserId,
                            TotalPayment = order.TotalPayment,
                            Status       = order.Status
                        };


                        var books = from b in context.BooksInOrders where b.OrderId.Equals(orderId) select b;
                        if (books != null && books.Count() > 0)
                        {
                            books.ToList <BooksInOrder>().ForEach(delegate(BooksInOrder book)
                            {
                                booksInOrder.Add(context.Books.Find(book.BookId));
                            });
                            resp.OrderData.Books = booksInOrder;
                        }
                    }
                    else
                    {
                        resp.Status  = (int)Constants.STATUSES.ERROR;
                        resp.Message = Constants.ORDER_NOT_FOUND;
                    }
                }
            }
            else
            {
                resp.Status  = (int)Constants.STATUSES.ERROR;
                resp.Message = Constants.ENTER_INT;
            }

            return(resp);
        }
Example #21
0
 public void ShowStudent()
 {
     using (TablesContext db = new TablesContext())
     {
         var students = db.Students;
         var table    = new ConsoleTable("Id", "Логин", "Имя", "Фамилия", "Отчество");
         Console.WriteLine("Список всех пользователей:\n");
         foreach (Student s in students)
         {
             table.AddRow(s.Id, s.StudLogin, s.StudFirstName, s.StudLastName, s.StudPatronymicName);
         }
         table.Write();
     }
 }
Example #22
0
        public void ShowStudent(int id)
        {
            using (TablesContext db = new TablesContext())
            {
                Student student = db.Students.Find(id);

                Console.WriteLine("Логин:                      " + student.StudLogin);
                Console.WriteLine("Имя:                        " + student.StudFirstName);
                Console.WriteLine("Фамилия:                    " + student.StudLastName);
                Console.WriteLine("Отчество:                   " + student.StudPatronymicName);
                Console.WriteLine("Номер читательского билета: " + student.StudCardNumber);
                Console.WriteLine("Номер телефона:             " + student.StudPhone);
                Console.WriteLine("Адрес:                      " + student.StudAdress);
            }
        }
Example #23
0
 public void FindG(string name)
 {
     using (TablesContext db = new TablesContext())
     {
         var genres = db.Genres.Where(g => g.Name == name);
         var table  = new ConsoleTable("Id", "Название");
         foreach (Genre g in genres)
         {
             foreach (Book b in g.Books)
             {
                 table.AddRow(g.Id, b.BookName);
             }
         }
         table.Write();
     }
 }
Example #24
0
 public void Remove(int id)
 {
     try
     {
         using (TablesContext db = new TablesContext())
         {
             Book books    = db.Books.Find(id);
             var  exemplar = db.Exemplars.Where(e => e.BookId == id).FirstOrDefault();
             db.Exemplars.Remove(exemplar);
             db.Books.Remove(books);
             db.SaveChanges();
             Console.WriteLine("Данные успешно удалены");
         }
     }
     catch (Exception) { Console.WriteLine("Данные введены не верно"); }
 }
Example #25
0
 public String NewUser(User user)
 {
     using (TablesContext context = new TablesContext())
     {
         var users = from u in context.Users where u.Email.Equals(user.Email) select u;
         if (users == null || users.Count() == 0)
         {
             context.Users.Add(user);
             context.SaveChanges();
             return(Constants.USER_CREATED);
         }
         else
         {
             return(Constants.USER_ALREADY_EXISTS);
         }
     }
 }
Example #26
0
 public void FindByGenre(string GenreName)
 {
     using (TablesContext db = new TablesContext())
     {
         var book  = db.Books.Where(b => b.Genre.Name == GenreName).FirstOrDefault();
         var genre = db.Genres.Where(g => g.Name == GenreName).FirstOrDefault();
         try
         {
             Console.WriteLine("Название книги:         " + book.BookName);
             Console.WriteLine("Автор книги:            " + book.BookAuthor);
             Console.WriteLine("Жанр книги:             " + genre.Name);
             Console.WriteLine("Издатель книги:         " + book.Publisher);
             Console.WriteLine("Год издания книги:      " + book.YearOfPublish);
         }
         catch (Exception e) { Console.WriteLine("Книга не найдена"); }
     }
 }
Example #27
0
        public void EditStudent(int id)
        {
            string ELogin;
            string EPassword;
            string EFirstName;
            string ELastName;
            string EPatronymicName;
            string ECardNumber;
            string EPhone;
            string EAdress;

            using (TablesContext db = new TablesContext())
            {
                Student studentId = db.Students.Find(id);

                Console.Write("Изменить логин \n {0} -> ", studentId.StudLogin);
                ELogin = Console.ReadLine();
                Console.Write("Изменить пароль \n {0} -> ", studentId.StudPassword);
                EPassword = Console.ReadLine();
                Console.Write("Изменить имя \n {0} -> ", studentId.StudFirstName);
                EFirstName = Console.ReadLine();
                Console.Write("Изменить фамилию \n {0} -> ", studentId.StudLastName);
                ELastName = Console.ReadLine();
                Console.Write("Изменить отчество \n {0} -> ", studentId.StudPatronymicName);
                EPatronymicName = Console.ReadLine();
                Console.Write("Изменить номер читательского билета \n {0}->", studentId.StudCardNumber);
                ECardNumber = Console.ReadLine();
                Console.Write("Изменить номер телефона \n {0} -> ", studentId.StudPhone);
                EPhone = Console.ReadLine();
                Console.Write("Изменить адрес проживания \n {0} -> ", studentId.StudAdress);
                EAdress = Console.ReadLine();

                studentId.StudLogin          = ELogin;
                studentId.StudPassword       = EPassword;
                studentId.StudFirstName      = EFirstName;
                studentId.StudLastName       = ELastName;
                studentId.StudPatronymicName = EPatronymicName;
                studentId.StudCardNumber     = ECardNumber;
                studentId.StudAdress         = EAdress;
                studentId.StudPhone          = EPhone;
                db.SaveChanges();

                Console.WriteLine("Объекты успешно сохранены\n");
            }
        }
Example #28
0
 public String UpdateUser(User updateData)
 {
     using (TablesContext context = new TablesContext())
     {
         User user = context.Users.Find(updateData.Id);
         if (user != null && !user.Deleted)
         {
             user.FirstName = updateData.FirstName;
             user.LastName  = updateData.LastName;
             user.Email     = updateData.Email;
             context.SaveChanges();
             return(Constants.USER_UPDATED);
         }
         else
         {
             return(Constants.USER_NOT_FOUND);
         }
     }
 }
Example #29
0
 public CompanyRegistrationModel Get()
 {
     using (TablesContext tc = new TablesContext())
     {
         var comps = (from c in tc.companies
                      join r in tc.registry
                      on c.Key equals r.Key
                      select
                      new CompanyRegistrationModel
         {
             FieldValue = r.FieldValue,
             Name = c.Name,
             Company = c.Company,
             Industry = c.Industry,
             Rank = c.Rank
         }).ToList();
         return(comps);
     }
 }
Example #30
0
 public String UpdateBook(Book updateData)
 {
     using (TablesContext context = new TablesContext())
     {
         Book book = context.Books.Find(updateData.Id);
         if (book != null && !book.Deleted)
         {
             book.Name        = updateData.Name;
             book.Cost        = updateData.Cost;
             book.Description = updateData.Description;
             context.SaveChanges();
             return(Constants.BOOK_UPDATED);
         }
         else
         {
             return(Constants.BOOK_NOT_FOUND);
         }
     }
 }