Esempio n. 1
0
        public ActionResult Create([Bind(Include = "ProductID,ProductName,QuantityPerUnit,UnitPrice,UnitInStock,UnitInOrder,ReorderLevel,ProductDescription,Remarks,CategoryID,SupplierID,OwnerID")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
            ViewBag.OwnerID    = new SelectList(db.OwnerCompanies, "OwnerID", "Owner", product.OwnerID);
            ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", product.SupplierID);
            return(View(product));
        }
Esempio n. 2
0
        public void Load <T>(IEnumerable <T> ts, bool save) where T : class
        {
            using (var context = new AccountingContext())
            {
                var dbSet = context
                            .GetType()
                            .GetProperty(this.pluralizationService.Pluralize(typeof(T).Name))
                            .GetValue(context, null) as DbSet <T>;

                if (dbSet == null)
                {
                    throw new Exception("could not cast to DbSet<T> for T = " + typeof(T).Name);
                }

                foreach (var t in ts)
                {
                    dbSet.AddOrUpdate(t);
                }

                if (save)
                {
                    context.SaveChanges();
                }
            }
        }
        public ActionResult SaveOrder(Order inputModel)
        {
            string message = string.Format("Created user '{0}' in the system.", inputModel.CustomerID);
            int    orderId = 0;

            try
            {
                db.Orders.Add(inputModel);
                db.SaveChanges();
                orderId = inputModel.OrderID;
            }
            catch (Exception ex) {
                message = ex.ToString();
            }
            return(Json(new OrderViewModel {
                Message = message, OrderID = orderId
            }));
        }
Esempio n. 4
0
        public ActionResult Index(HttpPostedFileBase file, UploadedFileInfo upload)
        {
            //check file extension
            string extension = Path.GetExtension(Request.Files[0].FileName).ToLower();

            if (extension != ".xls" && extension != ".xlsx")
            {
                ModelState.AddModelError("uploadError", "Supported file extensions: .xls, .xlsx");
                return(View());
            }

            // extract only the filename
            var fileName = Path.GetFileName(file.FileName);

            //display adding date
            var currentDate = DateTime.Now.ToString("d");

            // store the file inside ~/App_Data/uploads folder
            var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), currentDate + fileName);

            using (AccountingContext context = new AccountingContext())
            {
                // Verify that the user selects a file
                if (file != null && file.ContentLength > 0)
                {
                    file.SaveAs(path);

                    // save the filename and path in UploadedFilesInfo table
                    upload.FileName = fileName;
                    upload.FilePath = path;

                    context.UploadedFiles.Add(upload);

                    context.SaveChanges();
                }
                else
                {
                    ModelState.AddModelError("blankFileError", "You're trying to attach blank file.");
                    return(View());
                }

                ExcelHandler excelHandler = new ExcelHandler();
                FileInfo     fi1          = new FileInfo(path);

                var queryId = from customer in context.UploadedFiles
                              select customer.UploadedFileInfoId;

                int?currentId = queryId.ToList().Last();

                var id = currentId++ ?? 1;

                excelHandler.SelectDataFromFile(fi1, id);
            }

            // redirect back to the index action to show the form once again
            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public IActionResult Index(string shopName, DateTime dateTime, string description, string[] itemName, decimal[] itemCost, decimal[] itemCount, string[] itemsDiscount)
        {
            Shop shop = db.Shops.FirstOrDefault(i => i.Name == shopName);

            if (shop == null)
            {
                shop = new Shop {
                    Name = shopName
                };
                db.Shops.Add(shop);
            }

            User user = db.Users.FirstOrDefault(i => i.Login == "CHUKIN");

            Purchase purchase = new Purchase {
                Shop = shop, User = user, Date = dateTime, Descriprion = description
            };

            db.Purchases.Add(purchase);

            for (int i = 0; i < itemName.Count(); i++)
            {
                Item item = db.Items.FirstOrDefault(j => j.Name == itemName[i]);
                if (item == null)
                {
                    item = new Item {
                        Name = itemName[i]
                    };
                    db.Items.Add(item);
                }

                bool discount = itemsDiscount.Contains(item.Name);

                Price price = new Price {
                    Date = dateTime, Discount = discount, Cost = itemCost[i], Shop = shop, Item = item
                };
                db.Prices.Add(price);

                PurchaseItem purchaseItem = new PurchaseItem {
                    Purchase = purchase, Item = item, Price = price, Count = itemCount[i]
                };
                db.PurchaseItems.Add(purchaseItem);
            }

            db.SaveChanges();

            return(View());
        }
        public void GatherTransaction()
        {
            string        path = @"D:\apps\accounting";
            DirectoryInfo di   = new DirectoryInfo(path);

            FileInfo[] files = di.GetFiles("*.json");
            foreach (FileInfo file in files)
            {
                using (StreamReader r = new StreamReader(file.FullName))
                {
                    string             json  = r.ReadToEnd();
                    List <Transaction> items = JsonConvert.DeserializeObject <List <Transaction> >(json);
                    if (items == null)
                    {
                        continue;
                    }
                    foreach (Transaction t in items)
                    {
                        bool exists = false;
                        if (t.Bank.Equals("Amazon"))
                        {
                            exists = _dbContext.Transactions.Where(b => b.Detail.Equals(t.Detail)).Any();
                        }
                        if (!exists)
                        {
                            exists = _dbContext.Transactions.Where(b =>
                                                                   b.Bank.Equals(t.Bank) &&
                                                                   b.Amount == t.Amount &&
                                                                   b.Date.Year.Equals(t.Date.Year) &&
                                                                   b.Date.Month.Equals(t.Date.Month) &&
                                                                   b.Date.Day.Equals(t.Date.Day) &&
                                                                   b.Description.Equals(t.Description) &&
                                                                   b.Detail.Equals(t.Detail)
                                                                   ).Any();
                        }
                        if (!exists)
                        {
                            _dbContext.Transactions.Add(t);
                            _dbContext.SaveChanges();
                        }
                    }
                }
            }
        }
        public void Service__UpdatesAccount()
        {
            // Arrange
            var id      = 49203841098409218UL;
            var hasCard = true;

            var oldName    = "test_value1";
            var oldFunds   = 123;
            var oldBalance = 456;

            var newName    = "test_value2";
            var newFunds   = 123123;
            var newBalance = 456456;

            var oldAccount = GetMockAccount(id, oldName, oldFunds, oldBalance, hasCard);
            var newAccount = GetMockAccount(id, newName, newFunds, newBalance, hasCard);

            var options = new DbContextOptionsBuilder <AccountingContext>()
                          .UseInMemoryDatabase(databaseName: "UpdatesAccount")
                          .Options;

            // Act
            using (var context = new AccountingContext(options))
            {
                _service = new AccountService(context);

                context.Add(oldAccount);
                context.SaveChanges();

                _service.Update(id, newAccount);

                var updatedAccount = context.Accounts.Find(id);

                // Assert
                Assert.Equal(newAccount.Name, updatedAccount.Name);
                Assert.Equal(newAccount.Balance, updatedAccount.Balance);
                Assert.Equal(newAccount.AvailableFunds, updatedAccount.AvailableFunds);
                Assert.Equal(newAccount.HasCard, updatedAccount.HasCard);
            }
        }
Esempio n. 8
0
        public void SaveBtn()
        {
            using (var ctx = new AccountingContext())
            {
                //Voucher stud = new Voucher() { ModeOfPayment = "Cash" };
                //ctx.Vouchers.Add(stud);

                Voucher fundClusterNumber = new Voucher()
                {
                    FundCluster         = _fundCluster,
                    DVNumber            = _dvNumber,
                    DateTIme1           = _dateTime1,
                    ModeOfPayment       = _modeOfPayment,
                    TinOrEmployeeNumber = _tinOrEmployeeNumber,
                    OrsOrBurs           = _orsOrBurs,
                    Particulars         = _particulars,
                    MFOPAP       = _mFOPAP,
                    Amount       = _amount1,
                    AccountTitle = _accountTitle,
                    UacsCode     = _uacsCode,
                    Debit        = _debit,
                    Credit       = _credit,
                    AFName       = _aFname,
                    AMName       = _aMName,
                    ALName       = _aLName,
                    AJobPosition = _aJobPosition,
                    CheckAda     = _checkAda,
                    DateTime2    = _dateTime2,
                    JevNumber    = _jevNo,
                    DateTim3     = _dateTime3
                };

                ctx.Vouchers.Add(fundClusterNumber);
                ctx.SaveChanges();
                ClearBtn();

                MessageBox.Show("Saved");
            }
        }
        public void SaveIgp()
        {
            using (var ctx = new AccountingContext())
            {
                //Voucher stud = new Voucher() { ModeOfPayment = "Cash" };
                //ctx.Vouchers.Add(stud);

                IGPs igpInfo = new IGPs()
                {
                    IGPsName = _igpName,
                    IGPsZone = _igpName
                };



                //Voucher dvNumber = new Voucher() { DVNumber = _dvNumber };
                ctx.IGPss.Add(igpInfo);


                ctx.SaveChanges();

                ClearIgp();
            }
        }
 public void Save()
 {
     context.SaveChanges();
 }
Esempio n. 11
0
        public static void Initialize(AccountingContext context)
        {
            var email       = "*****@*****.**";
            var adminRoleId = string.Empty;
            var userId      = string.Empty;

            if (context.Users.Any(r => r.Email.Equals(email)))
            {
                userId = context.Users.First(r => r.Email.Equals(email)).Id;
            }

            if (!userId.Equals(string.Empty))
            {
                if (!context.Banks.Any())
                {
                    var banks = new List <Bank>
                    {
                        new Bank {
                            Code        = "001",
                            Name        = "Ngân hàng Đông Á",
                            Address     = "120 Lý Tự Trọng P. Bến Thành Q1 TP.HCM",
                            CreatedBy   = "admin",
                            CreatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                            UpdatedBy   = "admin",
                            UpdatedDate = new DateTime(2019, 12, 8, 12, 0, 0)
                        },
                        new Bank {
                            Code        = "002",
                            Name        = "Ngân hàng BIDV",
                            Address     = "140 Trần Hưng Đạo P. Bến Nghé Q1 TP.HCM",
                            CreatedBy   = "admin",
                            CreatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                            UpdatedBy   = "admin",
                            UpdatedDate = new DateTime(2019, 12, 8, 12, 0, 0)
                        }
                    };
                    context.Banks.AddRange(banks);
                    context.SaveChanges();
                }
            }

            if (!context.CustomerTypes.Any())
            {
                var customerTypes = new List <CustomerType>
                {
                    new CustomerType {
                        Code        = "001",
                        Name        = "Khách hàng công ty",
                        CreatedBy   = "admin",
                        CreatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                        UpdatedBy   = "admin",
                        UpdatedDate = new DateTime(2019, 12, 8, 12, 0, 0)
                    },
                    new CustomerType {
                        Code        = "002",
                        Name        = "Khách hàng lẻ",
                        CreatedBy   = "admin",
                        CreatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                        UpdatedBy   = "admin",
                        UpdatedDate = new DateTime(2019, 12, 8, 12, 0, 0)
                    }
                };
                context.CustomerTypes.AddRange(customerTypes);
                context.SaveChanges();
            }

            if (!context.ReceiptTypes.Any())
            {
                var receiptTypes = new List <ReceiptType>
                {
                    new ReceiptType {
                        Code = "001",
                        ReceiptTypeInVietnamese     = "Thu tiền nợ khách hàng",
                        ReceiptTypeInSecondLanguage = "Customer Receipt",
                        ShowReceiptTypeInVietNamese = true,
                        CreatedBy   = "admin",
                        CreatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                        UpdatedBy   = "admin",
                        UpdatedDate = new DateTime(2019, 12, 8, 12, 0, 0)
                    },
                    new ReceiptType {
                        Code = "002",
                        ReceiptTypeInVietnamese     = "Thu tiền nội bộ",
                        ReceiptTypeInSecondLanguage = "Internal Receipt",
                        ShowReceiptTypeInVietNamese = true,
                        CreatedBy   = "admin",
                        CreatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                        UpdatedBy   = "admin",
                        UpdatedDate = new DateTime(2019, 12, 8, 12, 0, 0)
                    }
                };
                context.ReceiptTypes.AddRange(receiptTypes);
                context.SaveChanges();
            }

            if (!context.ReceiptBatches.Any())
            {
                var receiptBatches = new List <ReceiptBatch>
                {
                    new ReceiptBatch
                    {
                        ReceiptBatchNo          = "BR00000001",
                        ReceiptBatchDate        = new DateTime(2019, 10, 10, 0, 0, 0),
                        DescriptionInVietNamese = "Batch No created by Hang",
                        BatchStatus             = true,
                        CreatedBy   = "admin",
                        CreatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                        UpdatedBy   = "admin",
                        UpdatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                    },
                    new ReceiptBatch
                    {
                        ReceiptBatchNo          = "BR00000002",
                        ReceiptBatchDate        = new DateTime(2019, 10, 10, 0, 0, 0),
                        DescriptionInVietNamese = "Batch No created by Nga",
                        BatchStatus             = false,
                        CreatedBy   = "admin",
                        CreatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                        UpdatedBy   = "admin",
                        UpdatedDate = new DateTime(2019, 12, 8, 12, 0, 0),
                    }
                };
            }
        }
Esempio n. 12
0
 public void Add(Transaction newTransaction)
 {
     _context.Add(newTransaction);
     _context.SaveChanges();
 }
 public void AddDoc(AccountingDocument inputData)
 {
     _context.AccountingDocumentSet.Add(inputData);
     _context.SaveChanges();
 }