Esempio n. 1
0
        public void Create(Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction dbt, Guid key)
        {
            try
            {
                _dbContext.TransactionLog1.Add(new TransactionLog1 {
                    Key = key
                });
                _dbContext.SaveChanges();

                _dbContext.Database.CommitTransaction(); // If not, nothing occurs
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        public async Task <FuncResult> Delete(string[] ids, string currentUserId)
        {
            IQueryable <ApdFctInsuranceDal> entitys = context.ApdFctInsurance.Where(e => ids.Contains(e.RecordId));

            if (entitys.Count() != ids.Length)
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "参数错误"
                });
            }
            foreach (ApdFctInsuranceDal obj in entitys)
            {
                //删除
                context.ApdFctInsurance.Remove(obj);
            }
            using (Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction trans = context.Database.BeginTransaction())
            {
                try
                {
                    await context.SaveChangesAsync();

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    LogService.WriteError(ex);
                    return(new FuncResult()
                    {
                        IsSuccess = false, Message = "删除时发生了意料之外的错误"
                    });
                }
            }
            return(new FuncResult()
            {
                IsSuccess = true, Message = $"已成功删除{ids.Length}条记录"
            });
        }
Esempio n. 3
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <param name="currentUserId"></param>
        /// <returns></returns>
        public async Task <FuncResult> Add(Params model)
        {
            ApdDimRatio entity = new ApdDimRatio
            {
                PeriodYear         = model.PeriodYear,
                TaxPerMu           = model.TaxPerMu,
                AddValuePerMu      = model.AddValuePerMu,
                Procuctivity       = model.Procuctivity,
                PollutantDischarge = model.PollutantDischarge,
                EnergyConsumption  = model.EnergyConsumption,
                NetAssesProfit     = model.NetAssesProfit,
                RDExpenditureRatio = model.RDExpenditureRatio
            };
            await _context.ApdDimRatio.AddAsync(entity);

            using (Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction trans = _context.Database.BeginTransaction())
            {
                try
                {
                    await _context.SaveChangesAsync();

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    return(new FuncResult()
                    {
                        IsSuccess = false, Content = ex.Message
                    });
                }
            }


            return(new FuncResult()
            {
                IsSuccess = true, Content = entity, Message = "添加成功"
            });
        }
Esempio n. 4
0
        public async Task <FuncResult> Deletes(string[] years)
        {
            IQueryable <ApdDimRatio> entitys = _context.ApdDimRatio.Where(e => years.Contains(Convert.ToString(e.PeriodYear)));

            if (entitys.Count() != years.Length)
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "参数错误"
                });
            }
            foreach (ApdDimRatio obj in entitys)
            {
                _context.ApdDimRatio.Remove(obj);
            }
            using (Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction trans = _context.Database.BeginTransaction())
            {
                try
                {
                    await _context.SaveChangesAsync();

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    LogService.WriteError(ex);
                    return(new FuncResult()
                    {
                        IsSuccess = false, Message = "删除时发生了意料之外的错误"
                    });
                }
            }
            return(new FuncResult()
            {
                IsSuccess = true, Message = $"已成功删除{years.Length}条记录"
            });
        }
Esempio n. 5
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <param name="currentUserId"></param>
        /// <returns></returns>
        public async Task <FuncResult> Delete(int year)
        {
            ApdDimRatio entity = await _context.ApdDimRatio.FindAsync(year);

            if (entity == null)
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "ID不存在!"
                });
            }
            _context.ApdDimRatio.Remove(entity);
            using (Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction trans = _context.Database.BeginTransaction())
            {
                try
                {
                    await _context.SaveChangesAsync();

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    LogService.WriteError(ex);
                    return(new FuncResult()
                    {
                        IsSuccess = false, Message = "删除时发生了意料之外的错误"
                    });
                }
            }
            ;
            return(new FuncResult()
            {
                IsSuccess = true, Content = entity, Message = "删除成功"
            });
        }