Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Room,Place,IsTaken")] BookLocation bookLocation, string[] Publications, string[] Readers)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }

            if (Readers != null)
            {
                bookLocation.Reader = db.Readers.ToList().First(e => e.ToString() == Readers[0]);
            }
            bookLocation.Publication = db.Publications.ToList().First(e => Publications[0].Contains(e.ToString()));
            if (ModelState.IsValid)
            {
                db.BookLocations.Add(bookLocation);
                db.Stats.Add(new Stats {
                    DateTaken = DateTime.Now, Publication = bookLocation.Publication
                });
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Publications = new SelectList(db.Publications, bookLocation.Publication);
            ViewBag.Readers      = new SelectList(db.Readers, bookLocation.Reader);

            return(View(bookLocation));
        }
        public ActionResult Create([Bind(Include = "Id,First,Last,Patronimic,toEnumWT")] Author author)
        {
            if (ModelState.IsValid)
            {
                db.Authors.Add(author);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Name")] Discipline discipline)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }

            {
                if (ModelState.IsValid)
                {
                    db.Disciplines.Add(discipline);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(View(discipline));
        }
        public ActionResult Create([Bind(Include = "Id,First,Last,Patronimic,toEnumAL,Group")] Reader reader)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                if (reader.Group == null)
                {
                    reader.Group = string.Empty;
                }

                db.Readers.Add(reader);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(reader));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Id,DateTaken")] Stats stats, int Publications)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }

            {
                stats.Publication = db.Publications.Find(Publications);
                if (ModelState.IsValid)
                {
                    db.Stats.Add(stats);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ViewBag.Publications = new SelectList(db.Publications, "Id", "Name", stats.Publication);
            }
            return(View(stats));
        }
        public ActionResult Create(
            [Bind(Include = "Id,Name,DatePublished,toEnumPT,Publisher,InternetLocation")] Publication publication, string[] Authors, string[] Courses, string[] Disciplines)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }
            ViewBag.db = db;

            foreach (Author author in db.Authors)
            {
                if (Authors.Any(e => e == author.ToString()))
                {
                    publication.Authors.Add(author);
                }
            }

            foreach (Courses course in db.Courses)
            {
                if (Courses.Any(e => e == course.ToString()))
                {
                    publication.Courses.Add(course);
                }
            }

            foreach (var discipline in db.Disciplines)
            {
                if (Disciplines.Any(e => e == discipline.ToString()))
                {
                    publication.Disciplines.Add(discipline);
                }
            }

            if (ModelState.IsValid)
            {
                db.Publications.Add(publication);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(publication));
        }
Ejemplo n.º 7
0
        public ActionResult Create(byte Course)
        {
            if (!User.IsInRole("Admin"))
            {
                return(HttpNotFound());
            }

            var course = new Courses {
                Course = Course
            };

            {
                if (ModelState.IsValid)
                {
                    db.Courses.Add(course);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(View(course));
        }
Ejemplo n.º 8
0
 public Books ReturnBook(string title)
 {
     using (LibraryDatabase db = new LibraryDatabase())
     {
         var book = db.UserBooks.FirstOrDefault(b => b.Title.ToLower() == title.ToLower());
         if (book != null)
         {
             db.UserBooks.Remove(book);
             var returnedBook = db.Books.FirstOrDefault(b => b.Title.ToLower() == title.ToLower());
             returnedBook.Copies++;
             db.SaveChanges();
             return(returnedBook);
         }
     }
     return(null);
 }
Ejemplo n.º 9
0
        public Books TakeBook(string title)
        {
            //Book book = LibraryBooks.AvBooks.Find(book =>
            //book.Title.Equals(title, StringComparison.OrdinalIgnoreCase));
            using (LibraryDatabase db = new LibraryDatabase())
            {
                var book = db.Books.FirstOrDefault(b => b.Title.ToLower() == title.ToLower());

                if (book != null && book.Copies > 0)
                {
                    book.Copies--;
                    db.UserBooks.Add(new UserBooks()
                    {
                        Author = book.Author,
                        Title  = book.Title,
                        Year   = book.Year
                    });

                    db.SaveChanges();
                    return(book);
                }
            }
            return(null);
        }
Ejemplo n.º 10
0
        public ActionResult TestFill()
        {
            if (User.IsInRole("Admin"))
            {
                using (var db = new LibraryDatabase())
                {
                    if (!db.Authors.Any())
                    {
                        for (int i = 0; i < 6; i++)
                        {
                            db.Authors.Add(Author.FillBlanks());
                        }
                        db.SaveChanges();
                    }
                    var authors = db.Authors.ToArray();

                    if (!db.Readers.Any())
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            db.Readers.Add(Reader.FillBlanks());
                        }
                        db.SaveChanges();
                    }
                    var readers = db.Readers.ToArray();

                    Courses[] courses;
                    if (!db.Courses.Any())
                    {
                        courses = new[]
                        {
                            new Courses {
                                Id = 1, Course = 1
                            },
                            new Courses {
                                Id = 2, Course = 2
                            },
                            new Courses {
                                Id = 3, Course = 3
                            },
                            new Courses {
                                Id = 4, Course = 4
                            },
                        };
                        foreach (var t in courses)
                        {
                            db.Courses.Add(t);
                        }
                        db.SaveChanges();
                    }
                    courses = db.Courses.ToArray();

                    Discipline[] disciplines;
                    if (!db.Disciplines.Any())
                    {
                        disciplines = new[]
                        {
                            new Discipline
                            {
                                Id   = 1,
                                Name = "Программирование",
                            },
                            new Discipline
                            {
                                Id   = 2,
                                Name = "Конструирование ПО",
                            },
                            new Discipline
                            {
                                Id   = 3,
                                Name = "НИС",
                            }
                        };
                        foreach (var t in disciplines)
                        {
                            db.Disciplines.Add(t);
                        }
                        db.SaveChanges();
                    }
                    disciplines = db.Disciplines.ToArray();

                    Publication[] publications;
                    if (!db.Publications.Any())
                    {
                        publications = new[]
                        {
                            new Publication("Принципы программирования",
                                            authors[2],
                                            ePublicationType.None,
                                            eBookPublication.Book,
                                            new DateTime(1985, 4, 1),
                                            "Росмэн")
                            {
                                Id      = 1,
                                Courses = new[]
                                {
                                    courses[0],
                                    courses[1]
                                },
                                Disciplines = new[]
                                {
                                    disciplines[0]
                                }
                            },
                            new Publication("Справочник по C#",
                                            new[]
                            {
                                authors[1],
                                authors[2]
                            },
                                            ePublicationType.None,
                                            eBookPublication.Book,
                                            new DateTime(2011, 6, 1),
                                            "Справочники")
                            {
                                Id      = 3,
                                Courses = new[]
                                {
                                    courses[0],
                                },
                                Disciplines = new[]
                                {
                                    disciplines[0],
                                }
                            },
                            new Publication("Pascal.NET programming guide",
                                            new[]
                            {
                                authors[2],
                                authors[3]
                            },
                                            ePublicationType.Educational,
                                            eBookPublication.Publication,
                                            new DateTime(2001, 8, 1),
                                            "Питер")
                            {
                                Id      = 2,
                                Courses = new[]
                                {
                                    courses[1],
                                    courses[3]
                                },
                                Disciplines = new[]
                                {
                                    disciplines[0],
                                    disciplines[1]
                                }
                            },
                            new Publication("Как писать божественный код",
                                            authors[5],
                                            ePublicationType.Scientific,
                                            eBookPublication.Publication,
                                            new DateTime(2018, 3, 1),
                                            null)
                            {
                                Id = 6,
                                InternetLocation = "https://youtube.com/",
                                Courses          = new[]
                                {
                                    courses[2],
                                    courses[3]
                                },
                                Disciplines = new[]
                                {
                                    disciplines[0],
                                }
                            },
                            new Publication("Почему Perl 6 - лучший язык программирования",
                                            new[]
                            {
                                authors[3],
                                authors[4],
                            },
                                            ePublicationType.Educational,
                                            eBookPublication.Publication,
                                            new DateTime(2015, 1, 1), null)
                            {
                                Id = 4,
                                InternetLocation = "https://google.com/",
                                Courses          = new[]
                                {
                                    courses[1],
                                    courses[2]
                                },
                                Disciplines = new[]
                                {
                                    disciplines[1],
                                }
                            },
                            new Publication("Где учиться на программиста",
                                            authors[5],
                                            ePublicationType.Educational,
                                            eBookPublication.Publication,
                                            new DateTime(2016, 11, 1),
                                            null)
                            {
                                Id = 5,
                                InternetLocation = "https://wikipedia.org/",
                                Courses          = new[]
                                {
                                    courses[1],
                                    courses[3],
                                },
                                Disciplines = new[]
                                {
                                    disciplines[2],
                                }
                            },
                        };
                        foreach (var t in publications)
                        {
                            db.Publications.Add(t);
                        }
                        db.SaveChanges();
                    }
                    publications = db.Publications.ToArray();

                    Stats[] stats;
                    if (!db.Stats.Any())
                    {
                        stats = new[]
                        {
                            new Stats
                            {
                                Id          = 1,
                                DateTaken   = new DateTime(2016, 01, 09),
                                Publication = publications[2]
                            },
                            new Stats
                            {
                                Id          = 2,
                                DateTaken   = new DateTime(2017, 06, 10),
                                Publication = publications[2]
                            },
                            new Stats
                            {
                                Id          = 3,
                                DateTaken   = new DateTime(2017, 11, 15),
                                Publication = publications[1]
                            },
                            new Stats
                            {
                                Id          = 4,
                                DateTaken   = new DateTime(2018, 08, 20),
                                Publication = publications[1]
                            },
                            new Stats
                            {
                                Id          = 5,
                                DateTaken   = new DateTime(2018, 03, 01),
                                Publication = publications[2]
                            },
                        };
                        foreach (var t in stats)
                        {
                            db.Stats.Add(t);
                        }
                        db.SaveChanges();
                    }

                    BookLocation[] locations;
                    if (!db.BookLocations.Any())
                    {
                        locations = new[]
                        {
                            new BookLocation
                            {
                                Id          = 1,
                                Room        = 307,
                                Place       = "здесь",
                                IsTaken     = true,
                                Reader      = readers[2],
                                Publication = publications[2]
                            },
                            new BookLocation
                            {
                                Id          = 2,
                                Room        = 321,
                                Place       = "где-то была",
                                IsTaken     = false,
                                Publication = publications[2]
                            },
                            new BookLocation
                            {
                                Id          = 3,
                                Room        = 501,
                                Place       = "в столе",
                                IsTaken     = true,
                                Reader      = readers[1],
                                Publication = publications[1]
                            },

                            new BookLocation
                            {
                                Id          = 4,
                                Room        = 321,
                                Place       = "на верхней полке шкафа",
                                IsTaken     = false,
                                Publication = publications[2]
                            },
                            new BookLocation
                            {
                                Id          = 5,
                                Room        = 318,
                                Place       = "в правом шкафу слева",
                                IsTaken     = false,
                                Publication = publications[0]
                            },
                            new BookLocation
                            {
                                Id          = 6,
                                Room        = 302,
                                Place       = "на столе",
                                IsTaken     = false,
                                Publication = publications[1]
                            },
                            new BookLocation
                            {
                                Id          = 7,
                                Room        = 323,
                                Place       = "под потолком",
                                IsTaken     = false,
                                Publication = publications[0]
                            },
                        };
                        foreach (var t in locations)
                        {
                            db.BookLocations.Add(t);
                        }
                        db.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("Index", "Home"));
        }