Ejemplo n.º 1
0
        public IBooking ReserveBook(IList <IBook> books, ILibrarian libNr, IMember memberNr)
        {
            foreach (IBook book in books)
            {
                book.Loan();
                books.Where(x => x.ISBN == book.ISBN).Select(x => { return(book); }).ToList();
            }

            int bookingNr = 1;

            if (bookings.Count() != 0)
            {
                bookingNr = bookings.Max(x => x.BookingNr) + 1;
            }

            if (bookings.Count() != 0)
            {
                bookingNr = bookings.Max(x => x.BookingNr) + 1;
            }
            IBooking booking = new Booking(bookingNr, books, libNr, memberNr, DateTime.Now);

            bookings.Add(booking);

            return(booking);
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            ILibrarian C = (ILibrarian)Activator.GetObject(typeof(ILibrarian), "tcp://localhost:1234/Obj");
            string     type;

            if (memoire.Checked)
            {
                type = "memoire";
            }
            else
            {
                if (these.Checked)
                {
                    type = "these";
                }
                else
                {
                    type = "livre";
                }
            }

            Boolean b = C.AddWork(tags.Text.Split(',').ToList(), writers.Text.Split(',').ToList(), title.Text.ToString(), theme.Text.ToString(), type);

            if (b)
            {
                MessageBox.Show("successfull");
            }
            else
            {
                MessageBox.Show("failed");
            }
        }
Ejemplo n.º 3
0
        public async Task Invoke(HttpContext httpContext, ILibrarian librarian) // injection to method
        {
            httpContext.Items["CurrentUserName"] = httpContext.User.Identity.Name;

            await librarian.CheckAccess();

            await _next(httpContext);
        }
Ejemplo n.º 4
0
        public IBooking ReservBook(IList <IBook> books, int libNr, int memberNr)
        {
            ILibrarian librarian = GetLibrarianNr(libNr);
            IMember    member    = GetMemberNr(memberNr);
            IBooking   booking   = inventory.ReserveBook(books, librarian, member);

            bookings.Add(booking);
            return(booking);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> VerifyEmail([FromServices] ILibrarian librarian, string authorEmail)
        {
            if (await librarian.CheckAccess())
            {
                return(Json($"Selected author {authorEmail} is invalid"));
            }

            return(Json(true));
        }
Ejemplo n.º 6
0
        private bool SafeCheck(ILibrarian lib)
        {
            try {
                return(lib.Check());
            } catch (Exception e) {
                SLogger <LiYinLoader> .Warn($"An error occurred when checking a librarian", e);

                return(false);
            }
        }
Ejemplo n.º 7
0
        public Booking(int bookingNr, IList <IBook> books, ILibrarian libNr, IMember memberNr, DateTime startDate)
        {
            BookingNr = bookingNr;
            Books     = books;
            LibNr     = libNr;
            MemberNr  = memberNr;
            StartDate = startDate;

            BookingCompleted = false;
        }
Ejemplo n.º 8
0
        public ILogIn LogingIn(int libNr, string password)
        {
            ILogIn     loggaIn   = null;
            ILibrarian librarian = datastore.GetLibrarianNr(libNr);

            if (librarian != null && librarian.CorrectPassword(password))
            {
                loggaIn = new LogIn(librarian);
            }
            return(loggaIn);
        }
Ejemplo n.º 9
0
        public ILibrarian GetLibrarianNr(int libNr)
        {
            ILibrarian librarian = librarians.Where(a => a.LibrNr == libNr).FirstOrDefault();

            if (librarian.LibrNr != libNr)
            {
                librarian = GetLibrarianNr(libNr);
                librarians.Add(librarian);
            }
            return(librarian);
        }
Ejemplo n.º 10
0
        private bool SafeReady(ILibrarian lib)
        {
            try
            {
                lib.Ready();
                return(true);
            }
            catch (Exception e)
            {
                SLogger <DreamLibManager> .Warn($"There is an error occurred when calling a librarian's Ready() method", e);

                return(false);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取程序集的入口
        /// </summary>
        /// <param name="assembly"></param>
        /// <returns></returns>
        private ILibrarian GetLibrarianFrom(Assembly assembly)
        {
            ILibrarian librarian = null;
            var        types     = from type in assembly.GetExportedTypes()
                                   where IsLibrarian(type)
                                   select type;

            if (types.Count() != 0)
            {
                librarian = (ILibrarian)Activator.CreateInstance(types.First());
                return(librarian);
            }
            librarian = new DefaultLibrarian(assembly);
            return(librarian);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> NeedToPay([FromServices] ILibrarian librarian, int bookId) // inject  to controller Action
        {
            var book = _booksRepository.Get(bookId);

            if (book == null)
            {
                return(NotFound());
            }

            var userRepository = HttpContext.RequestServices.GetService <IUsersRepository>(); // get directly from HttpContext

            var currentVisitor = (Visitor)userRepository.Get(User.Identity.Name);

            await librarian.ApplyFees(book, currentVisitor);

            return(Json(new { result = "success" }));
        }
Ejemplo n.º 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            ILibrarian C = (ILibrarian)Activator.GetObject(typeof(ILibrarian), "tcp://localhost:1234/Obj");

            try
            {
                Work work = C.getById(Convert.ToInt32(idwork.Text.ToString()));
                this.Hide();
                EditWork editWork = new EditWork(work);
                editWork.Show();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                MessageBox.Show("failed");
            }
        }
Ejemplo n.º 14
0
        private void button1_Click(object sender, EventArgs e)
        {
            ILibrarian C = (ILibrarian)Activator.GetObject(typeof(ILibrarian), "tcp://localhost:1234/Obj");

            try
            {
                int id = Convert.ToInt32(idwork.Text.ToString());

                if (C.DeleteWork(id))
                {
                    MessageBox.Show("successful");
                }
                else
                {
                    MessageBox.Show("failed");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("invalide" + ex);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 获取传入的所有程序集的入口实现
        /// </summary>
        /// <returns>所有入口类</returns>
        private IEnumerable <ILibrarian> GetLibrarianFrom(IEnumerable <Assembly> assemblies)
        {
            List <ILibrarian> result = new List <ILibrarian>();

            foreach (var ass in assemblies)
            {
                try
                {
                    ILibrarian lib = GetLibrarianFrom(ass);
                    if (lib.Check())
                    {
                        lib.Ready();
                        result.Add(lib);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Warn($"加载与检查{ass.GetName().Name}的入口类时失败,该程序集无法被加载为秋之盒拓展", ex);
                }
            }
            return(result);
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            ///<summary>
            ///程序初始化
            /// </summary>
            ///<summary>
            ///菜单选项
            /// </summary>

            int selectCode = default;

            ///<summary>
            ///菜单状态初始化
            /// </summary>
            ///
            #region
            Dictionary <string, bool> loginOrRegisterSelectStatus  = new Dictionary <string, bool>(2);
            Dictionary <string, bool> selectUserTypeStatus         = new Dictionary <string, bool>(3);
            Dictionary <string, bool> studentMenuSelectStatus      = new Dictionary <string, bool>(4);
            Dictionary <string, bool> loginOrRegisterSucceedStatus = new Dictionary <string, bool>(2);

            #endregion


            loginOrRegisterSelectStatus.Add("loginRequirement", false);
            loginOrRegisterSelectStatus.Add("registerRequirement", false);

            selectUserTypeStatus.Add("studentRequirement", false);
            selectUserTypeStatus.Add("librarianRequirement", false);
            selectUserTypeStatus.Add("systemManagerRequirement", false);

            studentMenuSelectStatus.Add("bookSearchRequirement", false);
            studentMenuSelectStatus.Add("bookLendingRequirement", false);
            studentMenuSelectStatus.Add("bookReturnRequirement", false);
            studentMenuSelectStatus.Add("viewPersonalInfoRequirement", false);

            loginOrRegisterSucceedStatus.Add("studentLoginSucceed", false);



            Student   student   = new Student();
            Librarian librarian = new Librarian();
            Book      book      = new Book();

            Menu.Display.NoLoginMainMenu();

            selectCode = Convert.ToInt32(Console.ReadLine());

            ///
            /// <summary>
            /// 主菜单,提示登录与注册
            /// </summary>
            ///
            switch (selectCode)
            {
            case 1:
                loginOrRegisterSelectStatus["loginRequirement"] = true;
                break;

            case 2:
                loginOrRegisterSelectStatus["registerRequirement"] = true;
                break;

            default:
                break;
            }

            ///<summary>
            ///登录模块
            /// </summary>
            if (loginOrRegisterSelectStatus[key : "loginRequirement"])
            {
                Menu.Display.SelectUserTypeMenu();

                selectCode = Convert.ToInt32(Console.ReadLine());

                switch (selectCode)
                {
                case 1:
                    IStudent newStudent = student;

                    loginOrRegisterSucceedStatus["studentLoginSucceed"] = newStudent.Login(student);
                    break;

                case 2:
                    ILibrarian newLibrarian = librarian;

                    newLibrarian.Login(librarian);
                    break;

                case 3:


                    break;

                default:
                    break;
                }
            }


            ///<summary>
            ///注册模块
            /// </summary>
            if (loginOrRegisterSelectStatus[key : "registerRequirement"])
            {
                Menu.Display.SelectUserTypeMenu();

                selectCode = Convert.ToInt32(Console.ReadLine());

                switch (selectCode)
                {
                case 1:
                    IStudent newStudent = student;

                    newStudent.Register(student);
                    newStudent.SaveInfoXmlOfStudent(student);
                    break;

                case 2:
                    ILibrarian newLibrarian = librarian;

                    newLibrarian.Register(librarian);
                    newLibrarian.SaveInfoXmlOfLibrarian(librarian);
                    break;

                case 3:


                    break;

                default:
                    break;
                }
            }

            ///<summary>
            ///学生登录成功菜单
            /// </summary>
            if (loginOrRegisterSucceedStatus[key : "studentLoginSucceed"])
            {
                Menu.Display.StudentMainMenu();

                selectCode = Convert.ToInt32(Console.ReadLine());

                switch (selectCode)
                {
                case 1:
                    studentMenuSelectStatus[key : "bookSearchRequirement"] = true;
                    break;

                case 2:
                    studentMenuSelectStatus[key : "bookLendingRequirement"] = true;
                    break;

                case 3:
                    studentMenuSelectStatus[key : "bookReturnRequirement"] = true;
                    break;

                case 4:
                    Console.WriteLine($"{ student.ShowInfo()}");

                    System.Threading.Thread.Sleep(5000);
                    break;

                default:
                    break;
                }
            }

            ///<summary>
            ///书籍查询
            /// </summary>
            ///
            if (studentMenuSelectStatus[key : "bookSearchRequirement"])
            {
                IBook newBook = book;
                Console.WriteLine(@"Please enter the ISBN:");
                string targetISBN    = Console.ReadLine();
                bool   searchSucceed = false;
                searchSucceed = newBook.Search(targetISBN, book);

                if (searchSucceed)
                {
                    Console.WriteLine($"{book.ShowInfo()}");
                    System.Threading.Thread.Sleep(10000);
                }
            }
        }
Ejemplo n.º 17
0
 public LogIn(ILibrarian librarian)
 {
     Librarian = librarian;
 }
Ejemplo n.º 18
0
 public LibrarianController(IBookService bookServ, ILibrarian libServ)
 {
     _bookContext = bookServ;
     _libContext  = libServ;
 }