Example #1
0
        public bool Add(ElectricItem electricItem)
        {
            var companyLogic = new CompanyLogic();
            var companyId    = companyLogic.GetCompanyId(electricItem.CompanyName);
            var electric     = _context.Electrics.FirstOrDefault(item => item.CompanyId == companyId && item.Year == electricItem.Year && item.Month == electricItem.Month);

            if (electric != null)
            {
                electric.Electricity     = electricItem.Electricity;
                electric.BuyElectricity  = electricItem.BuyElectricity;
                electric.BuyAvgPrice     = electricItem.BuyAvgPrice;
                electric.SellElectricity = electricItem.SellElectricity;
                electric.SellAvgPrice    = electricItem.SellAvgPrice;
                electric.ModifyTime      = DateTime.Now;
            }
            else
            {
                var entity = new Electric {
                    CompanyId       = companyId,
                    Year            = electricItem.Year,
                    Month           = electricItem.Month,
                    Electricity     = electricItem.Electricity,
                    BuyElectricity  = electricItem.BuyElectricity,
                    BuyAvgPrice     = electricItem.BuyAvgPrice,
                    SellElectricity = electricItem.SellElectricity,
                    SellAvgPrice    = electricItem.SellAvgPrice,
                    CreateTime      = DateTime.Now,
                    ModifyTime      = DateTime.Now
                };
                _context.Electrics.Add(entity);
            }
            _context.SaveChanges();
            return(true);
        }
Example #2
0
        public bool Add(ProfitItem profitItem)
        {
            var companyLogic = new CompanyLogic();
            var companyId    = companyLogic.GetCompanyId(profitItem.CompanyName);
            var profit       = _context.Profits.FirstOrDefault(item => item.CompanyId == companyId && item.Year == profitItem.Year && item.Month == profitItem.Month);

            if (profit != null)
            {
                profit.AssetsImpairmentLoss    = profitItem.AssetsImpairmentLoss;
                profit.EngineeringAndLeasehold = profitItem.EngineeringAndLeasehold;
                profit.FinancialCost           = profitItem.FinancialCost;
                profit.ProfitValue             = profitItem.ProfitValue;
                profit.OtherCost           = profitItem.OtherCost;
                profit.TaxAndAdditional    = profitItem.TaxAndAdditional;
                profit.ThirdMaintenanceFee = profitItem.ThirdMaintenanceFee;
                profit.ModifyTime          = DateTime.Now;
            }
            else
            {
                var entity = new Profit {
                    CompanyId               = companyId,
                    Year                    = profitItem.Year,
                    Month                   = profitItem.Month,
                    AssetsImpairmentLoss    = profitItem.AssetsImpairmentLoss,
                    EngineeringAndLeasehold = profitItem.EngineeringAndLeasehold,
                    FinancialCost           = profitItem.FinancialCost,
                    ProfitValue             = profitItem.ProfitValue,
                    OtherCost               = profitItem.OtherCost,
                    TaxAndAdditional        = profitItem.TaxAndAdditional,
                    ThirdMaintenanceFee     = profitItem.ThirdMaintenanceFee,
                    CreateTime              = DateTime.Now,
                    ModifyTime              = DateTime.Now
                };
                _context.Profits.Add(entity);
            }
            _context.SaveChanges();
            return(true);
        }
Example #3
0
        public bool Add(CostItem costItem)
        {
            var companyLogic = new CompanyLogic();
            var companyId    = companyLogic.GetCompanyId(costItem.CompanyName);
            var cost         = _context.Costs.FirstOrDefault(item => item.CompanyId == companyId && item.Year == costItem.Year && item.Month == costItem.Month);

            if (cost != null)
            {
                cost.Salary                  = costItem.Salary;
                cost.WorkersWelfare          = costItem.WorkersWelfare;
                cost.TotalCost               = costItem.TotalCost;
                cost.ControllableCost        = costItem.ControllableCost;
                cost.OtherControllableCost   = costItem.ControllableCost - costItem.WorkersWelfare;
                cost.OtherUnControllableCost = costItem.TotalCost - costItem.ControllableCost - costItem.Salary;
                cost.ModifyTime              = DateTime.Now;
            }
            else
            {
                var entity = new Cost()
                {
                    Year                    = costItem.Year,
                    Month                   = costItem.Month,
                    Salary                  = costItem.Salary,
                    WorkersWelfare          = costItem.WorkersWelfare,
                    TotalCost               = costItem.TotalCost,
                    ControllableCost        = costItem.ControllableCost,
                    OtherControllableCost   = costItem.ControllableCost - costItem.WorkersWelfare,
                    OtherUnControllableCost = costItem.TotalCost - costItem.ControllableCost - costItem.Salary,
                    CreateTime              = DateTime.Now,
                    ModifyTime              = DateTime.Now
                };
                entity.CompanyId = companyId;
                _context.Costs.Add(entity);
            }
            _context.SaveChanges();
            return(true);
        }