Beispiel #1
0
 public TestSplitter()
 {
     InitializeComponent();
     configFile         = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\GlobalConfiguration.json";
     globalConfigReader = new GlobalConfigReader();
     config             = globalConfigReader.Load(configFile);
 }
        private BorrowListItem CreateBorrowListItem(BorrowRecord record)
        {
            int    limitDays = 31;
            string getBorrowDayLimitValue = GlobalConfigReader.ReadFromLibraryServiceConfig("BorrowDayLimit", "days");

            if (!string.IsNullOrEmpty(getBorrowDayLimitValue))
            {
                limitDays = Convert.ToInt32(getBorrowDayLimitValue);
            }

            var state = new AdminBookState(record);
            var item  = new BorrowListItem
            {
                BorrowId   = record.BorrowRecordId.ToString(),
                BookId     = record.BookId.ToString(),
                BookNumber = record.Book.BookNumber,
                Title      = record.Book.BookType.Title,
                UserId     = record.UserId.ToString(),
                UserName   = record.User.DisplayName,
                BorrowDate = record.BorrowedDate.ToShortDateString(),
                ReturnDate = record.BorrowedDate.AddDays(limitDays).ToShortDateString(),
                State      = state.State,
                Operation  = state.Operation
            };

            return(item);
        }
Beispiel #3
0
        public CustomerBookState(BookLibraryContext db, BorrowRecord borrowRecord, IEnumerable <SubscribeRecord> subscribeRecords)
        {
            int    limitDays = 31;
            string getBorrowDayLimitValue = GlobalConfigReader.ReadFromLibraryServiceConfig("BorrowDayLimit", "days");

            if (!string.IsNullOrEmpty(getBorrowDayLimitValue))
            {
                limitDays = Convert.ToInt32(getBorrowDayLimitValue);
            }

            if (borrowRecord == null)
            {
                throw new ArgumentNullException("borrowRecord");
            }

            var currentUser = Users.Current;

            if (borrowRecord.UserId == currentUser.UserId)
            {
                InitBorrowed(borrowRecord);
            }
            else if (subscribeRecords.Any(r => r.UserId == currentUser.UserId))
            {
                InitSubscribed();
            }
            else
            {
                InitCanSubscribe(borrowRecord.BookId);
            }

            BorrowedBy   = GetUserName(db, borrowRecord.UserId);
            ReturnDate   = borrowRecord.BorrowedDate.AddDays(limitDays).ToShortDateString();
            SubscribedBy = string.Join(", ", subscribeRecords.Select(s => GetUserName(db, s.UserId)));
        }
        public ReadOnlyCollection <MailMessage> Verify(IEnumerable <BorrowRecord> borrowRecords)
        {
            int    limitDays = 31;
            string getBorrowDayLimitValue = GlobalConfigReader.ReadFromLibraryServiceConfig("BorrowDayLimit", "days");

            if (!string.IsNullOrEmpty(getBorrowDayLimitValue))
            {
                limitDays = Convert.ToInt32(getBorrowDayLimitValue);
            }
            var emailContextList        = new List <MailMessage>();
            var limitDay                = DateTime.Now.AddDays(-limitDays);
            var shouldReturnBookRecords = borrowRecords.Where(br => br.BorrowedDate < limitDay);

            foreach (var shouldReturnBookRecord in shouldReturnBookRecords)
            {
                var body = string.Format(
                    "The book [{0}] you borrowed at {1} is out of date.{2} Please return it ASAP.",
                    shouldReturnBookRecord.Book.BookType.Title,
                    shouldReturnBookRecord.BorrowedDate.ToShortDateString(),
                    Environment.NewLine);
                var message = Utility.BuildMail(
                    shouldReturnBookRecord.User.EmailAdress,
                    "A borrowed book have to be returned",
                    body);
                emailContextList.Add(message);
            }

            return(emailContextList.AsReadOnly());
        }
Beispiel #5
0
        public static GlobalConfiguration ReadConfiguration()
        {
            string              configFile         = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\GlobalConfiguration.json";
            GlobalConfigReader  globalConfigReader = new GlobalConfigReader();
            GlobalConfiguration config             = globalConfigReader.Load(configFile);

            return(config);
        }
        private static int GetBorrowLimit()
        {
            int    number = 5;
            string getBorrowLimitValue = GlobalConfigReader.ReadFromGlobalConfig("BorrowNumberLimit", "number");

            if (!string.IsNullOrEmpty(getBorrowLimitValue))
            {
                number = Convert.ToInt32(getBorrowLimitValue);
            }
            return(number);
        }
Beispiel #7
0
        private int GetPageSize()
        {
            int    size             = 10;
            string getPageSizeValue = GlobalConfigReader.ReadFromGlobalConfig("PageInfo", "size");

            if (!string.IsNullOrEmpty(getPageSizeValue))
            {
                size = Convert.ToInt32(getPageSizeValue);
            }
            return(size);
        }
Beispiel #8
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Enum.TryParse(cbConectionType.SelectedValue.ToString(), out WPFConfig.ConnectionType connectionType);
         globalConfiguration.WPFConfig.connectionType = connectionType;
         //MessageBox.Show(globalConfiguration.WPFConfig.AppLanguage + Environment.NewLine + globalConfiguration.WPFConfig.connectionType.ToString());
         GlobalConfigReader globalConfigReader = new GlobalConfigReader();
         globalConfigReader.Save(globalConfiguration);
         MessageBox.Show("Saved");
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error:" + ex.Message);
     }
 }
        public ReadOnlyCollection <MailMessage> Verify(IEnumerable <BorrowRecord> borrowRecords)
        {
            int    aheadNotificationDays         = 7;
            string getAheadNotificationDaysValue = GlobalConfigReader.ReadFromLibraryServiceConfig("AheadNotification", "days");

            if (!string.IsNullOrEmpty(getAheadNotificationDaysValue))
            {
                aheadNotificationDays = Convert.ToInt32(getAheadNotificationDaysValue);
            }
            int    limitDays = 31;
            string getBorrowDayLimitValue = GlobalConfigReader.ReadFromLibraryServiceConfig("BorrowDayLimit", "days");

            if (!string.IsNullOrEmpty(getBorrowDayLimitValue))
            {
                limitDays = Convert.ToInt32(getBorrowDayLimitValue);
            }
            var emailContextList        = new List <MailMessage>();
            var limitDay                = DateTime.Now.AddDays(aheadNotificationDays - limitDays).Date;
            var shouldReturnBookRecords =
                borrowRecords.Where(br => br.BorrowedDate.Date == limitDay);

            foreach (var shouldReturnBookRecord in shouldReturnBookRecords)
            {
                var body = string.Format(
                    "The book [{0}] you borrowed will out of date at {1}.{2} Please take keep an eye open with it.",
                    shouldReturnBookRecord.Book.BookType.Title,
                    shouldReturnBookRecord.BorrowedDate.AddDays(limitDays).ToShortDateString(),
                    Environment.NewLine);
                var message = Utility.BuildMail(
                    shouldReturnBookRecord.User.EmailAdress,
                    "A borrowed book will out of data",
                    body);
                emailContextList.Add(message);
            }

            return(emailContextList.AsReadOnly());
        }