Beispiel #1
0
        public async Task <FuncResult> Delete(string id /*, string currentUserId*/)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "未接收到参数信息!"
                });
            }
            ApdFctGas entity = await context.ApdFctGas.FindAsync(id);

            if (entity == null)
            {
                return(new FuncResult()
                {
                    IsSuccess = false, Message = "用户ID不存在!"
                });
            }
            entity.DeleteFlag = 1;
            //entity.DeleteBy = currentUserId;
            entity.DeleteDate = DateTime.Now;
            context.ApdFctGas.Update(entity);
            await context.SaveChangesAsync();

            return(new FuncResult()
            {
                IsSuccess = true, Content = entity, Message = "删除成功"
            });
        }
Beispiel #2
0
        public async Task <FuncResult> DeleteData(string key)
        {
            FuncResult fr = new FuncResult()
            {
                IsSuccess = true, Message = "Ok"
            };

            try
            {
                if (string.IsNullOrWhiteSpace(key))
                {
                    fr.IsSuccess = false;
                    fr.Message   = "未接收到参数信息!";
                }
                var       _key   = Convert.ToDecimal(key);
                ApdFctGas entity = context.ApdFctGas.FirstOrDefault(f => f.RecordId.Equals(_key));
                if (entity == null)
                {
                    fr.IsSuccess = false;
                    fr.Message   = "异常参数,未找到数据!";
                }

                //删除
                context.ApdFctGas.Remove(entity);
                using (IDbContextTransaction trans = context.Database.BeginTransaction())
                {
                    try
                    {
                        await context.SaveChangesAsync();

                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        fr.IsSuccess = false;
                        fr.Message   = $"{ex.InnerException},{ex.Message}";
                        throw new Exception("error", ex);
                    }
                }
                return(fr);
            }
            catch (Exception ex)
            {
                throw new Exception("error", ex);
            }
        }