Пример #1
0
        public static void Activity_BookRemoved(SDCContext db, UserProfile profile, Book book, string shelfName)
        {
            string template = "<p>Removed <strong>%booktitle% </strong> from %shelfname% <span class='text-muted'>on %when%</span></p>";
            var content = template
                .Replace("%booktitle%", book.Title)
                .Replace("%shelfname%", shelfName)
                .Replace("%when%", DateTime.Now.ToString(G.DATE));

            Activity activity = new Activity()
            {
                Profile = profile,
                Content = content,
                Type = ActivityType.RemoveBook
            };

            db.Activities.Add(activity);
            db.SaveChanges();
        }
Пример #2
0
        public static void Activity_BookUpdated(SDCContext db, UserProfile profile, Book book, string bookurl, string shelfurl)
        {
            string template = "<p>Updated <a href = '%bookurl%'> <strong>%booktitle%</strong> </a> in <a href = '%shelfurl%'> <strong>%shelfname%</strong> </a> <span class='text-muted'>on %when%</span></p>";
            var content = template
                .Replace("%bookurl%", bookurl)
                .Replace("%booktitle%", book.Title)
                .Replace("%shelfurl%", shelfurl)
                .Replace("%shelfname%", book.Shelf.Name)
                .Replace("%when%", DateTime.Now.ToString(G.DATE));

            Activity activity = new Activity()
            {
                Profile = profile,
                Content = content,
                Type = ActivityType.UpdateBook
            };

            db.Activities.Add(activity);
            db.SaveChanges();
        }
Пример #3
0
 public static void AttachToContext(UserProfile profile, SDCContext db)
 {
     if (db.Set<UserProfile>().Local.Any(local => profile == local))
     {
         db.Entry<UserProfile>(profile).State = EntityState.Unchanged;
     }
     else
     {
         db.Set<UserProfile>().Attach(profile);
         db.Entry<UserProfile>(profile).State = EntityState.Unchanged;
     }
 }
Пример #4
0
        private void LoadBooks(SDCContext db, UserProfile profile, Shelf shelf)
        {
            int perShelf = _rnd.Next(10, 50);
            int startindex = Progress;
            for(int i = startindex; i < startindex + perShelf && Progress < _max; i++)
            {
                string isbn, title, author, publisher, imgurl;
                int year;
                try {
                    isbn = _booksSplit[i, 0];
                    title = _booksSplit[i, 1];
                    author = _booksSplit[i, 2];
                    year = Int32.Parse(_booksSplit[i, 3]);
                    publisher = _booksSplit[i, 4];
                    imgurl = _booksSplit[i, 5];
                }catch(Exception)
                {
                    continue;
                }

                DateTime d1 = DateTime.Now;
                Author a = null;
                if (!_authorsSet.ContainsKey(author))
                {
                    a = new Author()
                    {
                        Name = author,
                        AddedDate = DateTime.Now,
                        AddedBy = profile,
                        LastModifiedBy = profile,
                        IsVerified = true
                    };
                    db.Authors.Add(a);
                    _authorsSet.Add(author, a);
                }
                else
                {
                    a = _authorsSet[author];
                }
                Debug.WriteLine("Author lookup in " + DateTime.Now.Subtract(d1).TotalMilliseconds);

                DateTime d2 = DateTime.Now;
                Publisher p = null;
                if (!_publishersSet.ContainsKey(publisher))
                {
                    p = new Publisher()
                    {
                        Name = publisher,
                        AddedBy = profile,
                        IsVerified = true
                    };
                    db.Publishers.Add(p);
                    _publishersSet.Add(publisher, p);
                }
                else
                {
                    p = _publishersSet[publisher];
                }
                Debug.WriteLine("Author lookup in " + DateTime.Now.Subtract(d2).TotalMilliseconds);

                Book book = new Book()
                {
                    Authors = new List<Author>(new Author[] { a }),
                    Title = title,
                    AddedDate = DateTime.Now,
                    Language = _lang,
                    Shelf = shelf,
                    ISBN = isbn,
                    Publisher = p,
                    Year = year,
                    Description = _booksSplit[i, 6],
                    Pages = _rnd.Next(1, 500),
                    Price = _rnd.Next(10, 100)
                };

                //3 random genres bongo bong!
                var bookGenres = _allGenres.OrderBy(x => Guid.NewGuid().ToString()).Take(3).ToArray();
                book.Genres.Add(bookGenres[0]);

                db.Books.Add(book);

                //book pictures
                BookPicture bp = new BookPicture()
                {
                    Book = book,
                    Key = null,
                    Url = imgurl,
                    IsMain = true,
                    Title = "img title"
                };

                //book.Pictures = new List<BookPicture>();
                book.Pictures.Add(bp);

                Progress++;
                if (Cancel)
                    break;
            }
        }