Example #1
0
        public override async Task <int> HandleCommand(DeleteCommand request, CancellationToken cancellationToken)
        {
            var method = await methodQueries.GetById(request.Id);

            if (method == null)
            {
                throw new BusinessException("Method.NotExisted");
            }
            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        method.IsDeleted = true;
                        method           = UpdateBuild(method, request.LoginSession);

                        if (await methodRepository.Update(method) > 0)
                        {
                            rs = 0;
                        }
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                        }
                    }
                }
            }

            return(rs);
        }
        public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.Method == null || request.Method.Id == 0)
            {
                throw new BusinessException("Method.NotExisted");
            }

            var method = await methodQueries.GetById(request.Method.Id);

            if (method == null)
            {
                throw new BusinessException("Method.NotExisted");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Method.CreatedDate = method.CreatedDate;
                        request.Method.CreatedBy   = method.CreatedBy;
                        request.Method             = UpdateBuild(request.Method, request.LoginSession);
                        request.Method.Code        = string.IsNullOrWhiteSpace(method.Code)
                            ? (await storageQueries.GenarateCodeAsync(StorageKeys.MethodCode))
                            : method.Code;

                        rs = await methodRepository.Update(request.Method);

                        if (rs == 0)
                        {
                            return(-1);
                        }

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

            return(rs);
        }
Example #3
0
 public bool Update(Method model, int key) => methodRepository.Update(model, key);