Example #1
0
        private async Task CreateRequest()
        {
            using (SqlConnection conn = _sqlServer.GetConnection())
            {
                await conn.OpenAsync();

                try
                {
                    using (SqlCommand cmd = _sqlServer.GetSpCommand("acquiring.SucceedRequest", conn))
                    {
                        cmd.AddIntParam("@RequestId", _requestId);
                        SqlParameter TypeParam       = cmd.AddTinyIntParam("@Type").Output();
                        SqlParameter PlaceIdParam    = cmd.AddIntParam("@PlaceId").Output();
                        SqlParameter EmployeeIdParam = cmd.AddIntParam("@EmployeeId").Output();
                        SqlParameter AmountParam     = cmd.AddDecimalParam("@Amount", 18, 2).Output();
                        SqlParameter retValParam     = cmd.AddReturnValue();

                        await cmd.ExecuteNonQueryAsync();

                        int retVal = retValParam.GetInt32OrDefault();
                        if (retVal == -1)
                        {
                            _response.SetError(3, "Запрос на платёж не найден");
                            return;
                        }

                        _type       = (PaymentType)TypeParam.GetByte();
                        _placeId    = PlaceIdParam.GetInt32();
                        _employeeId = EmployeeIdParam.GetInt32OrDefault();
                        _amount     = AmountParam.GetDecimal();
                    }
                }
                catch (Exception e)
                {
                    _response.SetError(2, e.Message);
                }
            }
        }
Example #2
0
        private async Task <ShareData> GetShareData(Payment payment, SqlConnection conn, SqlTransaction tx)
        {
            ShareData share = new ShareData();
            Dictionary <int, GroupShareData> groups = new Dictionary <int, GroupShareData>();

            using (SqlCommand cmd = _sqlServer.GetSpCommand("payment.LoadShareData", conn, tx))
            {
                cmd.AddIntParam("@PlaceId", payment.PlaceId);
                cmd.AddIntParam("@EmployeeId", payment.EmployeeId);
                cmd.AddDateTime2Param("@PaymentDateTime", payment.PaymentDateTime);
                cmd.AddBitParam("@IsTimeSpecified", payment.IsTimeSpecified);

                SqlParameter PaymentLimitParam         = cmd.AddDecimalParam("@PaymentLimit", 18, 2).Output();
                SqlParameter SystemCommissionParam     = cmd.AddDecimalParam("@SystemCommission", 4, 2).Output();
                SqlParameter IsPlaceActiveParam        = cmd.AddIntParam("@IsPlaceActive").Output();
                SqlParameter PlaceDisplayNameParam     = cmd.AddNVarCharParam("@PlaceDisplayName", 100).Output();
                SqlParameter ShareSchemeHistoryIdParam = cmd.AddIntParam("@ShareSchemeHistoryId").Output();
                SqlParameter PersonalShareParam        = cmd.AddTinyIntParam("@PersonalShare").Output();
                SqlParameter EmployeeFirstNameParam    = cmd.AddNVarCharParam("@EmployeeFirstName", 50).Output();
                SqlParameter EmployeeLastNameParam     = cmd.AddNVarCharParam("@EmployeeLastName", 50).Output();
                SqlParameter EmployeeIsFiredParam      = cmd.AddBitParam("@EmployeeIsFired").Output();

                using (SqlDataReader dr = await cmd.ExecuteReaderAsync())
                {
                    while (dr.Read())
                    {
                        GroupShareData gdata = new GroupShareData();
                        gdata.Name   = dr.GetString("Name");
                        gdata.Id     = dr.GetInt32("GroupId");
                        gdata.Weight = dr.GetByte("GroupWeight");
                        groups.Add(gdata.Id, gdata);
                        share.Groups.Add(gdata);
                    }

                    dr.NextResult();

                    while (dr.Read())
                    {
                        MembershipData md = new MembershipData();
                        md.EmployeeId    = dr.GetInt32("EmployeeId");
                        md.GroupId       = dr.GetInt32("GroupId");
                        md.BeginDateTime = dr.GetDateTime("BeginDateTime");
                        md.EndDateTime   = dr.GetDateTime("EndDateTime");
                        md.IsManager     = dr.GetBoolean("IsManager");
                        md.IsOwner       = dr.GetBoolean("IsOwner");
                        share.Memberships.Add(md);

                        groups[md.GroupId].AddMembership(md);
                    }
                }

                share.PaymentLimit         = PaymentLimitParam.GetDecimal();
                share.SystemCommission     = SystemCommissionParam.GetDecimal();
                share.Place.Id             = payment.PlaceId;
                share.Place.Name           = PlaceDisplayNameParam.Value.ToString();
                share.Place.IsActive       = (IsPlaceActiveParam.GetInt32() != 0);
                share.ShareSchemeHistoryId = ShareSchemeHistoryIdParam.GetInt32();
                share.PersonalShare        = PersonalShareParam.GetByte();

                if (payment.EmployeeId.HasValue)
                {
                    share.Receiver           = new ReceiverData();
                    share.Receiver.Id        = payment.EmployeeId.Value;
                    share.Receiver.FirstName = EmployeeFirstNameParam.Value.ToString();
                    share.Receiver.LastName  = EmployeeLastNameParam.Value.ToString();
                    share.Receiver.IsFired   = EmployeeIsFiredParam.GetBooleanOrDefault();
                }
            }

            return(share);
        }