public async Task <int> AddAsync(GrowingMethod growingMethod)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(growingMethod);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
        public override async Task <int> HandleCommand(DeleteGrowingMethodCommand request, CancellationToken cancellationToken)
        {
            GrowingMethod growingMethod = null;

            if (request.Model == 0)
            {
                throw new BusinessException("GrowingMethod.NotSelected");
            }
            else
            {
                growingMethod = await growingMethodQueries.GetByIdAsync(request.Model);

                if (growingMethod == null)
                {
                    throw new BusinessException("GrowingMethod.NotSelected");
                }
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        growingMethod.IsDeleted    = true;
                        growingMethod.ModifiedDate = DateTime.Now;
                        growingMethod.ModifiedBy   = request.LoginSession.Id;

                        if (await growingMethodRepository.UpdateAsync(growingMethod) > 0)
                        {
                            rs = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(rs);
        }
예제 #3
0
 public UpdateGrowingMethodCommand(GrowingMethod growingMethod)
 {
     Model = growingMethod;
 }
        public async Task <int> UpdateAsync(GrowingMethod growingMethod)
        {
            var cmd = QueriesCreatingHelper.CreateQueryUpdate(growingMethod);

            return(await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection));
        }
예제 #5
0
 public InsertGrowingMethodCommand(GrowingMethod growingMethod)
 {
     Model = growingMethod;
 }