public object ExecuteSaveMethod(LibClientInfo clientInfo, string accountId, string funcId, string method, LibTable[] param) { DalResult result = new DalResult(); try { ReflectionOperate reflect = new ReflectionOperate(funcId); object obj = reflect.InstanceTarget(); DALBase dalBase = ((DALBase)obj); dalBase.AccountID = accountId; dalBase.ProgId = funcId; dalBase.LibTables = param; dalBase.LibClient = clientInfo; //dalBase.Language = clientInfo .Language; Type t = obj.GetType(); MethodInfo func = t.GetMethod(method); object[] p = new object[] { param }; result.Value = func.Invoke(obj, p); result.Messagelist = dalBase.GetMessage(); //result.Messagelist.Add("jjjj"); } catch (Exception ex) { ErrorMessage error = new ErrorMessage(); while (ex.InnerException != null) { ex = ex.InnerException; } error.Message = ex.Message; error.Stack = ex.StackTrace; result.ErrorMsglst.Add(error); } return(result); }
public void Create(DalResult result) { if (context.Results.FirstOrDefault(x => x.PassedUserId == result.UserId && x.QuestionId == result.QuestionId) == null) { context.Results.Add(result.ToOrmResult()); } }
public void Create(DalResult e) { if (e == null) { return; } var tmp = e.ToResult(); context.Set <Result>().Add(tmp); }
public void Update(DalResult entity) { var tmp = context.Set <Result>().SingleOrDefault(t => t.Id == entity.Id); if (tmp != null) { return; } tmp = entity.ToResult(); context.Entry(tmp).State = EntityState.Modified; }
public static ResultEntity ToBllResult(this DalResult result) { return(new ResultEntity { Id = result.Id, UserId = result.UserId, QuestionId = result.QuestionId, IsTrueAnswer = result.IsTrueAnswer, PassedTime = result.PassedTime }); }
public static Result ToOrmResult(this DalResult result) { return(new Result { Id = result.Id, PassedUserId = result.UserId, QuestionId = result.QuestionId, PassedTime = result.PassedTime, IsTrueAnswer = result.IsTrueAnswer }); }
public Result MapToOrm(DalResult entity) { return(new Result { id = entity.Id, defectDescription = entity.DefectDescription, weldingType = entity.WeldingType, norm = entity.Norm, number = entity.Number, quality = entity.Quality, resultLib_id = entity.Lib_id, welder = entity.Welder }); }
public DalResult MapToDal(BllResult entity) { DalResult dalEntity = new DalResult { Id = entity.Id, DefectDescription = entity.DefectDescription, WeldingType = entity.WeldingType, Norm = entity.Norm, Number = entity.Number, Quality = entity.Quality, Welder = entity.Welder, }; return(dalEntity); }
public BllResult MapToBll(DalResult entity) { BllResult bllEntity = new BllResult { Id = entity.Id, DefectDescription = entity.DefectDescription, WeldingType = entity.WeldingType, Norm = entity.Norm, Number = entity.Number, Quality = entity.Quality, Welder = entity.Welder, }; return(bllEntity); }
public static Result ToResult(this DalResult result) { if (result == null) { return(null); } return(new Result() { //Id = result.Id, Mark = result.Mark, TestId = result.TestId, UserId = result.UserId, Date = result.Date }); }
public static ResultEntity ToBll(this DalResult result) { var resultEntity = new ResultEntity() { Id = result.Id, Name = result.Name, CorrectAnswerCount = result.CorrectAnswerCount, IsPassed = result.IsPassed, PassingTime = result.PassingTime, PassingProcent = result.PassingProcent, TestId = result.TestId, UserId = result.UserId }; return(resultEntity); }
public static DalResult ToDal(this ResultEntity result) { var dalResult = new DalResult() { Id = result.Id, Name = result.Name, CorrectAnswerCount = result.CorrectAnswerCount, IsPassed = result.IsPassed, PassingTime = result.PassingTime, PassingProcent = result.PassingProcent, TestId = result.TestId, UserId = result.UserId }; return(dalResult); }
private async Task <DalResult> ExecuteCommand(string sql) { using var conn = new SqlConnection(ConnectionString); try { await conn.OpenAsync(); await conn.ExecuteAsync(sql); return(DalResult.Success); } catch (Exception ex) { return(DalResult.FromException(ex)); } finally { await conn.CloseAsync(); } }
public virtual async Task <DalResult> DeleteAsync(int id) { var sql = $"delete from {_tableName} where Id={id};"; using var conn = new SqlConnection(ConnectionString); try { await conn.OpenAsync(); await conn.ExecuteAsync(sql); return(DalResult.Success); } catch (Exception ex) { return(DalResult.FromException(ex)); } finally { await conn.CloseAsync(); } }
public async Task <DalResult> InsertAsync(MovementEntity movement, BeanEntity bean) { if (movement is null) { throw new ArgumentNullException(nameof(movement)); } if (bean is null) { throw new ArgumentNullException(nameof(bean)); } using var conn = new SqlConnection(ConnectionString); await conn.OpenAsync(); using var transaction = await conn.BeginTransactionAsync(); try { var result = await conn.InsertAsync(movement, transaction : transaction); movement.Id = result; var beanresult = await conn.UpdateAsync(bean, transaction : transaction); await transaction.CommitAsync(); return(beanresult ? DalResult.Success : DalResult.NotFound); } catch (Exception ex) { await transaction.RollbackAsync(); return(DalResult.FromException(ex)); } finally { await conn.CloseAsync(); } }
public void Delete(DalResult item) { throw new NotImplementedException(); }
public void Create(DalResult item) { var result = item.ToEntity(); _context.Set <TestResult>().Add(result); }
public static ApiError FromDalResult(DalResult result) => new((int)result.ErrorCode, result.Exception?.Innermost() ?? string.Empty);
public async Task <DalResult> SellToExchangeAsync(int holdingid, long quantity) { if (holdingid <= 0) { return(new(DalErrorCode.Invalid, new("Holding id is invalid"))); } if (quantity <= 0) { return(new(DalErrorCode.Invalid, new("Quantity is invalid"))); } using var conn = new SqlConnection(ConnectionString); await conn.OpenAsync(); using var transaction = await conn.BeginTransactionAsync(); try { var sql = $"select * from holdings where id={holdingid};"; var holding = await conn.QueryFirstOrDefaultAsync <HoldingEntity>(sql, transaction : transaction); if (holding is null) { await transaction.RollbackAsync(); return(new(DalErrorCode.NotFound, new($"No holding with the id '{holdingid}' was found"))); } if (holding.Quantity < quantity) { await transaction.RollbackAsync(); return(new(DalErrorCode.NSF, new("Insufficient beans in that holding"))); } sql = $"select * from Users where Id={holding.UserId};"; var user = await conn.QueryFirstOrDefaultAsync <UserEntity>(sql, transaction : transaction); if (user is null) { await transaction.RollbackAsync(); return(new(DalErrorCode.NotFound, new($"No user with the email id '{holding.UserId}' was found"))); } sql = $"select * from Beans where Id={holding.BeanId};"; var bean = await conn.QueryFirstOrDefaultAsync <BeanEntity>(sql, transaction : transaction); if (bean is null) { await transaction.RollbackAsync(); return(new(DalErrorCode.NotFound, new($"No bean with the id '{holding.BeanId}' was found"))); } var sale = new SaleEntity { Id = 0, UserId = user.Id, BeanId = bean.Id, Quantity = quantity, PurchaseDate = holding.PurchaseDate, CostBasis = holding.Price, SaleDate = DateTime.UtcNow, SalePrice = bean.Price, Bean = null, }; bean.Outstanding += quantity; if (quantity == holding.Quantity) { sql = $"delete from holdings where Id={holdingid};"; await conn.ExecuteAsync(sql, transaction : transaction); } else { holding.Quantity -= quantity; await conn.UpdateAsync(holding, transaction : transaction); } user.Balance += quantity * bean.Price; await conn.InsertAsync(sale, transaction : transaction); await conn.UpdateAsync(user, transaction : transaction); await conn.UpdateAsync(bean, transaction : transaction); await transaction.CommitAsync(); return(DalResult.Success); } catch (Exception ex) { await transaction.RollbackAsync(); return(DalResult.FromException(ex)); } finally { await conn.CloseAsync(); } }
public async Task <DalResult> BuyFromExchangeAsync(int userid, int beanid, long quantity) { if (userid <= 0) { return(new(DalErrorCode.Invalid, new("User id is invalid"))); } if (beanid <= 0) { return(new(DalErrorCode.Invalid, new("Bean id is invalid"))); } using var conn = new SqlConnection(ConnectionString); await conn.OpenAsync(); using var transaction = await conn.BeginTransactionAsync(); try { var sql = $"select * from Users where Id={userid};"; var user = await conn.QueryFirstOrDefaultAsync <UserEntity>(sql, transaction : transaction); if (user is null) { await transaction.RollbackAsync(); return(new(DalErrorCode.NotFound, new($"No user with the id '{userid}' was found"))); } sql = $"select * from Beans where Id={beanid};"; var bean = await conn.QueryFirstOrDefaultAsync <BeanEntity>(sql, transaction : transaction); if (bean is null) { await transaction.RollbackAsync(); return(new(DalErrorCode.NotFound, new($"No bean with the id '{beanid}' was found"))); } if (quantity > bean.Outstanding) { await transaction.RollbackAsync(); return(new(DalErrorCode.NSF, new("Insufficient outstanding beans for that quantity"))); } if (quantity * bean.Price > user.Balance) { await transaction.RollbackAsync(); return(new(DalErrorCode.NSF, new("User has insufficient funds to buy that many beans"))); } user.Balance -= quantity * bean.Price; bean.Outstanding -= quantity; var holding = new HoldingEntity { Id = 0, UserId = userid, BeanId = beanid, PurchaseDate = DateTime.UtcNow, Price = bean.Price, Quantity = quantity, Bean = null }; await conn.InsertAsync(holding, transaction : transaction); await conn.UpdateAsync(user, transaction : transaction); await conn.UpdateAsync(bean, transaction : transaction); await transaction.CommitAsync(); return(DalResult.Success); } catch (Exception ex) { await transaction.RollbackAsync(); return(DalResult.FromException(ex)); } finally { await conn.CloseAsync(); } }