private int GenerateTransactions(CategoryTypesEnum transactionCategory)
        {
            DateTime currentDate = DateTime.Now.AddMonths(MONTHS_START);
            DateTime endDate     = DateTime.Now.AddMonths(MONTHS_END);

            Random categoriesRandomizer = new Random();
            Random daysRandomizer       = new Random();
            Random amountRandomizer     = new Random();
            Random partnerRandomizer    = new Random();

            int minPartner = DbContext.Partners.Min(item => item.Id);
            int maxPartner = DbContext.Partners.Max(item => item.Id);
            List <Models.Categories> incomeCategories = DbContext.Categories
                                                        .Where(item => item.CategoryTypesId == (int)transactionCategory).ToList();

            while (currentDate <= endDate)
            {
                currentDate = currentDate.AddDays(daysRandomizer.Next(5, 12));
                double amount     = amountRandomizer.NextDouble() * 400 + 20;
                int    partnerId  = partnerRandomizer.Next(minPartner, maxPartner);
                int    categoryId = incomeCategories[categoriesRandomizer.Next(incomeCategories.Count - 1)].Id;

                Models.Transactions transaction = new Models.Transactions
                {
                    CategoriesId = categoryId,
                    Amount       = Convert.ToDecimal(Math.Round(amount, 2)),
                    Date         = currentDate,
                    PartnersId   = partnerId
                };
                DbContext.Transactions.Add(transaction);
            }

            return(DbContext.SaveChanges());
        }
Пример #2
0
        public ActionResult Create(Models.Transactions model)//FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                var t = new Transaction();
                //var payment =  collection.Keys

                t.Name        = model.Name;
                t.Amount      = model.Amount;
                t.PaymentDate = model.PaymentDate;
                t.PaymentType = model.ID;
                t.Active      = true;


                db.Transactions.Add(t);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #3
0
        // GET: TransactionsModel/Create
        public ActionResult Create()
        {
            var model = new Models.Transactions();

            var paymentType = from p in db.PaymentTypes orderby p.PaymentName select p;

            var t = new SelectList(paymentType, "ID", "PaymentName");

            model.PaymentTypeList = t;

            return(View(model));
        }
        private int GenerateTransactions(CategoryTypesEnum transactionCategory)
        {
            DateTime currentDate = DateTime.Now.AddMonths(MONTHS_START);
            DateTime endDate = DateTime.Now.AddMonths(MONTHS_END);

            Random categoriesRandomizer = new Random();
            Random daysRandomizer = new Random();
            Random amountRandomizer = new Random();
            Random partnerRandomizer = new Random();

            int minPartner = DbContext.Partners.Min(item => item.Id);
            int maxPartner = DbContext.Partners.Max(item => item.Id);
            List<Models.Categories> incomeCategories = DbContext.Categories
                .Where(item => item.CategoryTypesId == (int)transactionCategory).ToList();

            while (currentDate <= endDate)
            {
                currentDate = currentDate.AddDays(daysRandomizer.Next(5, 12));
                double amount = amountRandomizer.NextDouble() * 400 + 20;
                int partnerId = partnerRandomizer.Next(minPartner, maxPartner);
                int categoryId = incomeCategories[categoriesRandomizer.Next(incomeCategories.Count - 1)].Id;

                Models.Transactions transaction = new Models.Transactions
                {
                    CategoriesId = categoryId,
                    Amount = Convert.ToDecimal(Math.Round(amount, 2)),
                    Date = currentDate,
                    PartnersId = partnerId
                };
                DbContext.Transactions.Add(transaction);
            }

            return DbContext.SaveChanges();
        }
Пример #5
0
        public ActionResult TransactionsGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] string transactionId, [ModelBinder(typeof(DevExpressEditorsBinder))] Models.Transactions item)
        {
            //var model = new object[0];
            if (ModelState.IsValid)
            {
                try
                {
                    var transaction  = unitOfWork.TransactionsRepo.Find(m => m.Id == item.Id);
                    var vehiclesCost = unitOfWork.TransactionVehiclesRepo.Fetch(m => m.TransactionId == item.Id).Sum(m => m.Cost);
                    var itemCost     = unitOfWork.TransactionDetailsRepo.Fetch(m => m.TransactionId == item.Id).ToList()
                                       .Sum(m => m.TotalCost);
                    var facilitiesCost = unitOfWork.TransactionFacilitiesRepo.Fetch(m => m.TransactionId == item.Id)
                                         .Sum(m => m.Cost);

                    transaction.TransactionTotal = (vehiclesCost ?? 0) + (itemCost ?? 0) + (facilitiesCost ?? 0);
                    transaction.LastEditedBy     = UserId;



                    unitOfWork.Save();
                    // Insert here a code to update the item in your model
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            var model = unitOfWork.TransactionsRepo.Get(includeProperties: "Permitees,Permitees.PermiteeTypes");

            return(PartialView("_TransactionsGridViewPartial", model));
        }
Пример #6
0
 public bool UpdateTransaction(Models.Transactions transaction)
 {
     return(transactionRepository.Update(transaction));
 }
Пример #7
0
 public bool AddTransaction(Models.Transactions transaction)
 {
     return(transactionRepository.Insert(transaction));
 }