Example #1
0
 public AuxiliaryHelper(LedgerContext ledger, ICacheHelper cache, IAccountBookHelper acctBook, HttpContextBase context)
 {
     _ledger   = ledger;
     _cache    = cache;
     _acctBook = acctBook;
     _context  = context;
 }
 public CertificateWordHelper(HttpContextBase context, LedgerContext ledger, ICacheHelper cache)
 {
     _identity = context.User.Identity as ClaimsIdentity;
     _ledger   = ledger;
     _context  = context;
     _cache    = cache;
 }
 public List <Category> GetCategories(DbContextOptionsBuilder <LedgerContext> context)
 {
     using (var ctx = new LedgerContext(context.Options))
     {
         return(ctx.Categories.ToList());
     }
 }
Example #4
0
        public static void FinishRecord()
        {
            try
            {
                Guid personId = SetInformations.SetPersonId();

                using (var context = new LedgerContext())
                {
                    var leavingPerson = context.People.Find(personId);
                    var ledgers       = context.Ledgers.ToList();

                    for (int i = 0; i < ledgers.Count; i++)
                    {
                        if (ledgers[i].PersonId == leavingPerson.Id)
                        {
                            context.Ledgers.Remove(ledgers[i]);
                            context.SaveChanges();
                            ledgers[i].ExitTime = DateTime.Now;
                            context.Ledgers.Add(ledgers[i]);
                            context.SaveChanges();
                            break;
                        }
                    }
                }
            }
            catch (ArgumentNullException exception)
            {
                Console.WriteLine(exception.ParamName);
            }
        }
        public Guid Create(Transaction transaction, DbContextOptionsBuilder <LedgerContext> context)
        {
            try
            {
                using (var ctx = new LedgerContext(context.Options))
                {
                    transaction.DateCreated = DateTime.Now.ToUniversalTime();
                    ctx.Transactions.Add(transaction);
                    if (ctx.SaveChanges() != 1)
                    {
                        return(Guid.Empty);
                    }

                    return(transaction.Id);
                }
            }
            catch (DbEntityValidationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public List <Transaction> GetTransactions(Guid accountId, DbContextOptionsBuilder <LedgerContext> context)
 {
     using (var ctx = new LedgerContext(context.Options))
     {
         return(ctx.Transactions.OrderBy(t => t.TransactionDate).ToList());
     }
 }
Example #7
0
 public List <PaymentType> GetPaymentTypes(DbContextOptionsBuilder <LedgerContext> context)
 {
     using (var ctx = new LedgerContext(context.Options))
     {
         return(ctx.PaymentTypes.ToList());
     }
 }
Example #8
0
        public void Can_Get_Transaction()
        {
            using (var context = new LedgerContext(_optionBuilder.Options))
            {
                var trans = context.Transactions.FirstOrDefault(t => t.AccountId == _acctId);

                Assert.IsNotNull(trans, "Transaction was not successfully created");
            }
        }
Example #9
0
 public AccountBookHelper(HttpContextBase context,
                          LedgerContext ledger,
                          ICacheHelper cache,
                          ICertificateWordHelper certWord)
 {
     _identity = context.User.Identity as ClaimsIdentity;
     _ledger   = ledger;
     _cache    = cache;
     _certWord = certWord;
 }
Example #10
0
        private void AutofacConfig()
        {
            var builder  = new ContainerBuilder();
            var assembly = Assembly.GetExecutingAssembly();

            // MVC - Register your MVC controllers.
            builder.RegisterControllers(assembly);

            // MVC - OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule <AutofacWebTypesModule>();

            // MVC - OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // MVC - OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            //注入实现Sintoacct.Ledger.IDependency接口的对象
            builder.RegisterAssemblyTypes(assembly)
            .Where(t => t.GetInterface("Sintoacct.Ledger.IDependency") != null)
            .AsImplementedInterfaces();

            //注入Ledger上下文
            var ledger = new LedgerContext();

            ledger.Database.Initialize(false);
            //#warning 输出SQL
            //ledger.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
            //builder.RegisterInstance(ledger).As<LedgerContext>();
            builder.RegisterType <LedgerContext>().InstancePerLifetimeScope();

            //注入BizProgressContext
            var prog = new BizProgressContext();

            prog.Database.Initialize(false);
            builder.RegisterType <BizProgressContext>().InstancePerLifetimeScope();

            // WebAPI - Register your Web API controllers
            builder.RegisterApiControllers(assembly);

            // WebAPI - OPTIONAL: Register the Autofac filter provider.
            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

            //注入Log4net
            builder.RegisterModule(new LogInjectionModule());


            IContainer container = builder.Build();

            //注入MVC
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            //注入Web API
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Example #11
0
 public VoucherHelper(LedgerContext ledger,
                      ICacheHelper cache,
                      IAccountBookHelper acctBook,
                      HttpContextBase context,
                      IAccountHelper account)
 {
     _ledger   = ledger;
     _cache    = cache;
     _acctBook = acctBook;
     _context  = context;
     _account  = account;
 }
 public Category GetCategory(int id, DbContextOptionsBuilder <LedgerContext> context)
 {
     using (var ctx = new LedgerContext(context.Options))
     {
         var cat = ctx.Categories.FirstOrDefault(c => c.Id == id);
         if (cat == null)
         {
             throw new Exception("Cannot find a category with this parameter");
         }
         return(cat);
     }
 }
        public ActionResult CryptoData()
        {
            ViewBag.Message = "Here are the top 100 coins !";
            ViewBag.Time    = DateTime.Now;

            /*
             * var hap = new HAPScraper();
             * hap.Run();
             */

            using (var db = new LedgerContext())
            {
                var url = "https://coinmarketcap.com/";

                var htmlWeb = new HtmlWeb();

                var htmlDocument = new HtmlDocument();

                htmlDocument = htmlWeb.Load(url);

                HtmlNodeCollection allRows = htmlDocument.DocumentNode.SelectNodes("//table[1]/tbody[1]/tr[*]");

                List <Coin> currencyList = new List <Coin>();

                foreach (var row in allRows)
                {
                    var CoinPosition = row.ChildNodes[1].InnerText;
                    var CoinSymbol   = row.ChildNodes[3].ChildNodes[3].InnerText;
                    var CoinName     = row.ChildNodes[3].ChildNodes[7].InnerText;
                    var CoinChange   = row.ChildNodes[13].InnerText;
                    var CoinPrice    = row.ChildNodes[7].InnerText;


                    Coin coin = new Coin(CoinPosition, CoinSymbol, CoinName, CoinChange, CoinPrice);
                    currencyList.Add(coin);
                }

                //Creates a date.time snapshot-this will be my future snapshot button


                var ledger = new Ledger
                {
                    CryptoCoins = currencyList,
                    Time        = DateTime.Now
                };
                db.Ledgers.Add(ledger);
                db.SaveChanges();
                Console.WriteLine();

                return(View(currencyList));
            }
        }
        public int RemoveTransaction(Guid transId, DbContextOptionsBuilder <LedgerContext> context)
        {
            using (var ctx = new LedgerContext(context.Options))
            {
                var entity = ctx.Transactions.FirstOrDefault(t => t.Id == transId);
                if (entity != null)
                {
                    ctx.Entry(entity).State = EntityState.Deleted;
                }

                return(ctx.SaveChanges());
            }
        }
        public Transaction GetTransaction(Guid id, DbContextOptionsBuilder <LedgerContext> context)
        {
            using (var ctx = new LedgerContext(context.Options))
            {
                var trans = ctx.Transactions.FirstOrDefault(t => t.Id == id);

                if (trans == null)
                {
                    throw new Exception("Cannot locate transaction with this id");
                }
                return(trans);
            }
        }
        public void Can_Get_Account()
        {
            var optionBuilder = new DbContextOptionsBuilder <LedgerContext>();

            optionBuilder.UseInMemoryDatabase();

            using (var context = new LedgerContext(optionBuilder.Options))
            {
                var account = context.Accounts.FirstOrDefault(a => a.UserName == "BVilla");

                Assert.IsNotNull(account, "Can not locate account");
            }
        }
        public void OnException(ExceptionContext filterContext)
        {
            LedgerContext context = new LedgerContext();

            ExceptionLog exception = new ExceptionLog();

            exception.RequestUrl       = filterContext.HttpContext.Request.RawUrl;
            exception.RequestDetail    = JsonConvert.SerializeObject(filterContext.HttpContext.Request.Params);
            exception.ExceptionMessage = filterContext.Exception.Message;
            exception.ExceptionDetail  = JsonConvert.SerializeObject(filterContext.Exception);
            exception.LogTime          = System.DateTime.Now;
            context.Exceptions.Add(exception);
            context.SaveChanges();
        }
Example #18
0
        public AddLedgerInViewModel(IRegionManager rm, IEventAggregator ea, IOfficeContext context)
        {
            regionManager   = rm;
            eventAggregator = ea;
            this.context    = context;

            LedgerDTO = new LedgerContext {
                LedgerDate = DateTime.Now
            };

            AccountList   = new ObservableCollection <AccountInfoContext>();
            AccountInList = new ObservableCollection <AccountInfoContext>();
            EmployeeList  = new ObservableCollection <UserSimpleContext>();
        }
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            using (var db = new LedgerContext())
            {
            }



            var url = "https://coinmarketcap.com/";

            var htmlWeb = new HtmlWeb();

            var htmlDocument = new HtmlDocument();

            htmlDocument = htmlWeb.Load(url);

            HtmlNodeCollection allRows = htmlDocument.DocumentNode.SelectNodes("//table[1]/tbody[1]/tr[*]");
            //var rowNumber = 0;
            List <Coin> currencyDataList = new List <Coin>();

            foreach (var row in allRows)
            {
                // Console.WriteLine("Attempting to process row: " + rowNumber++);

                try
                {
                    var CoinSymbol = row.ChildNodes[3].ChildNodes[3].InnerText;
                    var CoinName   = row.ChildNodes[3].ChildNodes[5].InnerText;
                    var CoinPrice  = row.ChildNodes[7].InnerText;

                    Coin coin = new Coin(CoinSymbol, CoinName, CoinPrice);
                    currencyDataList.Add(coin);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to Find Value at Specified Co-ordinates");
                    Console.WriteLine(e);
                    throw;
                }


                Console.WriteLine("Process done");
            }


            return(View(currencyDataList));
        }
Example #20
0
        public PaymentType GetPaymentType(int id, DbContextOptionsBuilder <LedgerContext> context)
        {
            using (var ctx = new LedgerContext(context.Options))
            {
                var pt = ctx.PaymentTypes.FirstOrDefault(p => p.Id == id);

                if (pt == null)
                {
                    throw new Exception("Cannot find a payment type with this parameter");
                }
                return(pt);

                ;
            }
        }
Example #21
0
        public static Guid SetPersonId()
        {
            do
            {
                try
                {
                    Console.WriteLine("Выберите номер человека который уходит:");

                    List <Person> persons;

                    using (var context = new LedgerContext())
                    {
                        persons = context.People.ToList();

                        if (persons.Count == Constants.NULL)
                        {
                            throw new ArgumentNullException("Нет людей");
                        }

                        for (int i = 0; i < persons.Count; i++)
                        {
                            Console.WriteLine($"{i + 1}) {persons[i].Name} : {persons[i].CertificateNumber}");
                        }
                    }
                    int personId;

                    if (int.TryParse(Console.ReadLine().Trim(), out personId))
                    {
                        if (personId > 0 && personId <= persons.Count)
                        {
                            return(persons[personId - 1].Id);
                        }

                        throw new ArgumentException("Нет такого номера, выберите существующи");
                    }

                    throw new ArgumentException("Номер был некоректно введен");
                }
                catch (ArgumentNullException)
                {
                    throw;
                }
                catch (ArgumentException exception)
                {
                    Console.WriteLine(exception.Message);
                }
            } while (true);
        }
Example #22
0
        private static async Task GetHtmlAsync()
        {
            using (var db = new LedgerContext())
            {
                var url = "https://coinmarketcap.com/";

                var htmlWeb = new HtmlWeb();

                var htmlDocument = new HtmlDocument();
                htmlDocument = htmlWeb.Load(url);

                HtmlNodeCollection allRows   = htmlDocument.DocumentNode.SelectNodes("//table[1]/tbody[1]/tr[*]");
                var         rowNumber        = 0;
                List <Coin> currencyDataList = new List <Coin>();

                foreach (var row in allRows)
                {
                    try
                    {
                        Console.WriteLine("Attempting to process row: " + rowNumber++);

                        var CoinPosition = row.ChildNodes[1].InnerText;

                        /*var CoinSymbol = row.ChildNodes[3].ChildNodes[3].InnerText;
                         * var CoinName = row.ChildNodes[3].ChildNodes[5].InnerText;
                         * var CoinPrice = row.ChildNodes[7].InnerText; */

                        Coin coin = new Coin(CoinPosition /*CoinSymbol, CoinName, CoinPrice*/);
                        currencyDataList.Add(coin);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to find value at specified coordinates");
                        Console.WriteLine(e);
                        throw;
                    }

                    Console.WriteLine("Process Done !");
                }

                Console.WriteLine(currencyDataList);

                //db.Ledgers.Add(Ledger);
                //db.SaveChanges();
            }
        }
 public int Create(Category category, DbContextOptionsBuilder <LedgerContext> context)
 {
     try
     {
         using (var ctx = new LedgerContext(context.Options))
         {
             ctx.Categories.Add(category);
             return(ctx.SaveChanges());
         }
     }
     catch (DbEntityValidationException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public Account GetAccount(string userName, DbContextOptionsBuilder <LedgerContext> context)
 {
     try
     {
         using (var ctx = new LedgerContext(context.Options))
         {
             var account = ctx.Accounts.FirstOrDefault(a => a.UserName == userName);
             return(account);
         }
     }
     catch (DbEntityValidationException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #25
0
 public int Create(PaymentType paymentType, DbContextOptionsBuilder <LedgerContext> context)
 {
     try
     {
         using (var ctx = new LedgerContext(context.Options))
         {
             ctx.PaymentTypes.Add(paymentType);
             return(ctx.SaveChanges());
         }
     }
     catch (DbEntityValidationException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int Create(Account account, DbContextOptionsBuilder <LedgerContext> context)
 {
     try
     {
         using (var ctx = new LedgerContext(context.Options))
         {
             account.DateCreated = DateTime.Now;
             ctx.Accounts.Add(account);
             return(ctx.SaveChanges());
         }
     }
     catch (DbEntityValidationException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #27
0
        public void Can_Create_Tranaction()
        {
            using (var context = new LedgerContext(_optionBuilder.Options))
            {
                context.Transactions.Add(new Transaction
                {
                    AccountId       = _acctId,
                    Amount          = 100,
                    CategoryId      = 1,
                    Description     = "New shoes",
                    IsDeposit       = false,
                    PaymentTypeId   = 1,
                    TransactionDate = DateTime.Now,
                    CreatedBy       = "BVilla",
                    DateCreated     = DateTime.Now,
                });
                context.SaveChanges();

                var trans = context.Transactions.FirstOrDefault(t => t.AccountId == _acctId);

                Assert.IsNotNull(trans, "Transaction was not successfully created");
            }
        }
        public void Can_Create_Account()
        {
            var optionBuilder = new DbContextOptionsBuilder <LedgerContext>();

            optionBuilder.UseInMemoryDatabase();

            using (var context = new LedgerContext(optionBuilder.Options))
            {
                context.Accounts.Add(new Account
                {
                    FirstName   = "Bob",
                    LastName    = "Villa",
                    UserName    = "******",
                    Password    = "******",
                    CreatedBy   = "Admin",
                    DateCreated = DateTime.Now
                });
                context.SaveChanges();

                var account = context.Accounts.FirstOrDefault(a => a.UserName == "BVilla");

                Assert.IsNotNull(account, "Account was not successfully created");
            }
        }
Example #29
0
        public static void CraeteReacord()
        {
            Person newPerson = new Person()
            {
                Name = SetInformations.SetName(),
                CertificateNumber = SetInformations.SetCertificateNumber()
            };

            Ledger newRecord = new Ledger()
            {
                Person       = newPerson,
                EnterTime    = DateTime.Now,
                ExitTime     = null,
                PersonId     = newPerson.Id,
                VisitPurpose = SetInformations.SetVisitPurpose()
            };

            using (var context = new LedgerContext())
            {
                context.People.Add(newPerson);
                context.Ledgers.Add(newRecord);
                context.SaveChanges();
            }
        }
Example #30
0
 public CacheHelper(HttpContextBase context, LedgerContext ledger)
 {
     _context = context;
     _ledger  = ledger;
 }