示例#1
0
        /// <summary>
        /// 新增配股配息紀錄
        /// </summary>
        /// <param name="dividends"></param>
        /// <returns></returns>
        public string AddDividends(Dividends dividends)
        {
            dividends.CreateTime = DateTime.Now;

            dbConnection.Modified(dividends, EntityState.Added);
            dbConnection.SaveChanges();
            return("Success");
        }
示例#2
0
        /// <summary>
        /// 新增交易紀錄(含資產計算)
        /// </summary>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public string AddTransactionLog(TransactionViewModel transaction)
        {
            //本次交易數量
            int transNum = 0;
            //本次成本
            int cost = 0;

            //如手續費為0且非配股交易則自動帶入
            transaction.Fee = transaction.Fee == 0 & !transaction.isDividends ?
                              GetFee((int)(transaction.Num * transaction.UnitPrice), transaction.SoldStatus)
                : transaction.Fee;

            //買入
            if (!transaction.SoldStatus)
            {
                Tx_BuyFunction(transaction, out transNum, out cost);
            }
            else
            {
                Tx_SaleFunction(transaction, out transNum, out cost);
            }

            try
            {
                RecalculateAsset(transaction, transNum, cost);

                dbConnection.SaveChanges();
                return("Success");
            }
            catch (Exception ee)
            {
                return(ee.Message);
            }
        }
示例#3
0
        /// <summary>
        /// 建立完產品後會新增該產品的資產資料供日後計算
        /// </summary>
        /// <param name="product"></param>
        public void AddNewAsset(Product ProductData)
        {
            CheckProductIsNull(ProductData);

            if (CheckAssetIsNew(ProductData))
            {
                var newAsset = new Asset()
                {
                    ProductSeq = ProductData.ProductSeq,
                    Num        = 0,
                    TotalPrice = 0,
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now,
                };

                dbConnection.Modified(newAsset, EntityState.Added);
                dbConnection.SaveChanges();
            }
        }
        public string EditProduct(Product product)
        {
            var isNewProduct = product.ProductSeq == 0;

            if (!isNewProduct)
            {
                var oldData = dbConnection.QueryableProducts.FirstOrDefault(p => p.ProductSeq == product.ProductSeq);
                if (oldData == null)
                {
                    throw new DataNotFoundException();
                }

                oldData.ProductName = product.ProductName;
                oldData.Remark      = product.Remark;
                oldData.Owner       = product.Owner;

                dbConnection.Modified(oldData, EntityState.Modified);
            }
            else
            {
                dbConnection.Modified(product, EntityState.Added);
            }

            try
            {
                dbConnection.SaveChanges();
                if (isNewProduct)
                {
                    assetRepository.AddNewAsset(product);
                }

                return("Success");
            }
            catch (Exception ee)
            {
                return(ee.Message);
            }
        }