Esempio n. 1
0
File: User.cs Progetto: Ozerich/labs
        public static User FindByLogin(string login)
        {
            Catalog catalog = new Catalog();

            var q = from user in catalog.Users where user.Login == login select user;
            return q.First();
        }
Esempio n. 2
0
        public static void AddBook(int catId, string Title, string Genre, string Author, string Publication, int PagesCount, int Year, EnumFileFormat fileFormat, List<string> Tags)
        {
            Book book = new Book();

            book.parentId = catId;
            book.Title = Title;
            book.Author = Author;
            book.parentId = catId;
            book.Publication = Publication;
            book.PagesCount = PagesCount;
            book.Year = Year;
            book.FileFormat = fileFormat;
            book.Genre = Genre;
            book.Tags = Tags;

            Catalog catalog = new Catalog();

            catalog.Books.InsertOnSubmit(book);

            catalog.SubmitChanges();

            int bookId = book.Id;

            foreach (string tag in book.Tags)
            {
                BookTag bookTag = new BookTag();
                bookTag.Name = tag;
                bookTag.Book_Id = bookId;

                catalog.Tags.InsertOnSubmit(bookTag);
            }

            catalog.SubmitChanges();
        }
Esempio n. 3
0
File: User.cs Progetto: Ozerich/labs
        public bool HasBook(int book_Id)
        {
            Catalog catalog = new Catalog();

            var q = from book in catalog.UserBooks where book.Book_Id == book_Id where book.User_Id == Id select book;

            return q.Count() > 0;
        }
Esempio n. 4
0
        public static void AddCategory(string name)
        {
            Catalog catalog = new Catalog();

            BookCategory cat = new BookCategory();
            cat.Name = name;

            catalog.BookCategories.InsertOnSubmit(cat);
            catalog.SubmitChanges();
        }
Esempio n. 5
0
        public static void PutBook(int bookId, int userId)
        {
            Catalog catalog = new Catalog();

            var q = from book in catalog.UserBooks where book.Book_Id == bookId where book.User_Id == userId select book;

            UserBook userBook = q.First();
            catalog.UserBooks.DeleteOnSubmit(userBook);
            catalog.SubmitChanges();
        }
Esempio n. 6
0
        public static void TakeBook(int bookId, int userId)
        {
            Catalog catalog = new Catalog();

            UserBook userBook = new UserBook();
            userBook.Book_Id = bookId;
            userBook.User_Id = userId;

            catalog.UserBooks.InsertOnSubmit(userBook);
            catalog.SubmitChanges();
        }
Esempio n. 7
0
        public static void CreateUser(string login, string password)
        {
            User user = new User();
            user.Login = login;
            user.Password = password;

            Catalog catalog = new Catalog();

            catalog.Users.InsertOnSubmit(user);

            catalog.SubmitChanges();
        }
Esempio n. 8
0
 public static string BuildDealerUrl(Dealer dealer, Catalog catalog)
 {
     var url = string.Empty;
     if (Convert.ToInt32(catalog.CatalogYear) < 2015 || catalog.Brand == "Lincoln")
     {
         url = string.Format(@"http://www.mybrochureorder.com/qr/?model={0}&year={1}&brand={2}&dealerid={3}&zip={4}",
             catalog.ShortName, catalog.CatalogYear, catalog.Brand, dealer.DealerPa, dealer.DealerZip);
     }
     else if (Convert.ToInt32(catalog.CatalogYear) >= 2015 && catalog.Brand == "Ford")
     {
         url = string.Format(@"http://fbqr.co/{0}{1}", catalog.QRCodeName, dealer.DealerPa);
     }
     return url;
 }
Esempio n. 9
0
 public static string BuildGenericUrl(Catalog catalog)
 {
     var url = string.Empty;
     switch (catalog.Brand)
     {
         case "Lincoln":
             //url = string.Format(@"http://m.inventory.lincoln.com/{0}-Lincoln-{1}?fmccmp=qr-t3-brochure", catalog.CatalogYear, catalog.ShortName);
             url = string.Format(@"http://www.mybrochureorder.com/qr/?model={0}&year={1}&brand=Lincoln&dealerid=00000&zip=00000", catalog.ShortName, catalog.CatalogYear);
             break;
         case "Ford":
             url = catalog.CatalogYear >= 2015
                 ? string.Format(@"http://fbqr.co/{0}00000", catalog.QRCodeName)
                 : string.Format(@"http://m.inventory.ford.com/{0}-Ford-{1}?fmccmp=qr-t3-brochure", catalog.CatalogYear, catalog.ShortName);
             break;
     }
     return url;
 }
Esempio n. 10
0
        public static void DeleteBook(Book book)
        {
            Catalog catalog = new Catalog();

            var tagq = from tag in catalog.Tags where tag.Book_Id == book.Id select tag;
            foreach (BookTag tag in tagq)
                catalog.Tags.DeleteOnSubmit(tag);

            var userq = from t in catalog.UserBooks where t.Book_Id == book.Id select t;
            foreach (UserBook ub in userq)
                catalog.UserBooks.DeleteOnSubmit(ub);

            catalog.SubmitChanges();

            var q = from qBook in catalog.Books where qBook.Id == book.Id select book;

            Book deleteBook = q.First();

            catalog.Books.Attach(deleteBook);
            catalog.Books.DeleteOnSubmit(deleteBook);

            catalog.SubmitChanges();
        }
Esempio n. 11
0
        public static Book GetBook(int bookId)
        {
            Catalog catalog = new Catalog();

            var q = from book in catalog.Books where book.Id == bookId select book;
            Book resultBook = q.First();

            resultBook.Tags = new List<string>();
            var tagQuery = from tag in catalog.Tags where tag.Book_Id == bookId select tag;
            foreach (BookTag tag in tagQuery)
                resultBook.Tags.Add(tag.Name);

            return resultBook;
        }
Esempio n. 12
0
        public static List<Book> GetBooks(int parentId, string sort = "Title")
        {
            List<Book> result = new List<Book>();

            Catalog catalog = new Catalog();

            var q = parentId != 0 ? from book in catalog.Books where book.parentId == parentId select book : from book in catalog.Books select book;
            foreach (Book book in q)
                result.Add(book);

            if (sort == "Title")
                result = result.OrderBy(x => x.Title).ToList();
            else if (sort == "Author")
                result = result.OrderBy(x => x.Author).ToList();
            else if (sort == "Year")
                result = result.OrderBy(x => x.Year).ToList();
            else if (sort == "Pages number")
                result = result.OrderBy(x => x.PagesCount).ToList();

            foreach (Book book in result)
            {
                book.Tags = new List<string>();

                var qTag = from tag in catalog.Tags where tag.Book_Id == book.Id select tag;
                foreach (BookTag bookTag in qTag)
                    book.Tags.Add(bookTag.Name);
            }

            return result;
        }
Esempio n. 13
0
        public static List<BookCategory> GetCategories()
        {
            Catalog catalog = new Catalog();

            var q = from c in catalog.BookCategories select c;

            return q.ToList<BookCategory>();
        }
Esempio n. 14
0
        public static void UpdateBook(int bookId, int catId, string Title, string Genre, string Author, string Publication, int PagesCount, int Year, EnumFileFormat fileFormat, List<string> Tags)
        {
            Catalog catalog = new Catalog();

            var q = from ord in catalog.Books where ord.Id == bookId select ord;

            Book book = q.First();
            book.Title = Title;
            book.Author = Author;
            book.parentId = catId;
            book.Publication = Publication;
            book.PagesCount = PagesCount;
            book.Year = Year;
            book.FileFormat = fileFormat;
            book.Genre = Genre;
            book.Tags = Tags;

            var tagQuery = from tag in catalog.Tags where tag.Book_Id == bookId select tag;
            foreach (BookTag bookTag in tagQuery)
            {

                catalog.Tags.DeleteOnSubmit(bookTag);
            }

            foreach(string tag in book.Tags)
            {
                BookTag bookTag = new BookTag();
                bookTag.Name = tag;
                bookTag.Book_Id = bookId;

                catalog.Tags.InsertOnSubmit(bookTag);
            }

            catalog.SubmitChanges();
        }
Esempio n. 15
0
        private static DealerQRCode BuildGenericQrCode(Catalog catalog)
        {
            var genericQr = new DealerQRCode
                {
                    DealerPA = "00000",
                    SKU = catalog.Sku,
                    Year = catalog.CatalogYear,
                    Brand = catalog.Brand,
                    Vehicle = catalog.ShortName,
                    FileName = string.Format(@"{0}_Generic_QRCode.jpg", catalog.Sku),
                    QRCodeYear = catalog.CatalogYear.ToString(CultureInfo.InvariantCulture),
                    BarcodeData = QrCodeUrl.BuildGenericUrl(catalog),
                    IsGeneric = true
                };

            return genericQr;
        }
Esempio n. 16
0
 private static List<DealerQRCode> BuildDealerQRCodes(Catalog catalog, IEnumerable<Dealer> dealers)
 {
     return dealers.Select(dealer => new DealerQRCode
         {
             DealerPA = dealer.DealerPa,
             SKU = catalog.Sku,
             Year = catalog.CatalogYear,
             Brand = catalog.Brand,
             Vehicle = catalog.ShortName,
             DealerZip = dealer.DealerZip,
             FileName = string.Format(@"{0}_{1}.jpg", catalog.Sku, dealer.DealerPa),
             QRCodeYear = catalog.CatalogYear.ToString(CultureInfo.InvariantCulture),
             BarcodeData = QrCodeUrl.BuildDealerUrl(dealer, catalog),
             IsGeneric = false
         }).ToList();
 }
Esempio n. 17
0
        public static void DeleteCategory(int catId)
        {
            Catalog catalog = new Catalog();

            var bookQuery = from book in catalog.Books where book.parentId == catId select book;
            foreach (Book bookElem in bookQuery)
                DeleteBook(bookElem);

            var categoryQuery = from category in catalog.BookCategories where category.Id == catId select category;

            catalog.BookCategories.DeleteOnSubmit(categoryQuery.First());
            catalog.SubmitChanges();
        }