Esempio n. 1
0
        public async Task <IActionResult> Handle(HttpRequest request, CheckStatusRequest data)
        {
            AuthByKeyResult authResult = this.GetAuthenticationKey(request);

            if (!authResult.Result)
            {
                return(new JsonErrorResult(authResult.ErrorResponse));
            }

            ErrorResponse validationError = this.ValidateRequest(data);

            if (validationError != null)
            {
                return(new JsonErrorResult(validationError));
            }

            try
            {
                using (SqlConnection conn = sqlServer.GetConnection())
                {
                    await conn.OpenAsync();

                    using (SqlCommand cmd = sqlServer.GetSpCommand("dbo.Employee_CheckEmployeeStatus", conn))
                    {
                        cmd.AddBinaryParam("@PermanentKey", 16, authResult.Key.ToArray());
                        cmd.AddIntParam("@PlaceId", data.PlaceId);

                        SqlParameter EmployeeIdParam         = cmd.AddIntParam("@EmployeeId").Output();
                        SqlParameter EmployeeFirstNameParam  = cmd.AddNVarCharParam("@EmployeeFirstName", 50).Output();
                        SqlParameter EmployeeLastNameParam   = cmd.AddNVarCharParam("@EmployeeLastName", 50).Output();
                        SqlParameter EmployeeIsDisabledParam = cmd.AddBitParam("@EmployeeIsDisabled").Output();
                        SqlParameter PlaceGroupIdParam       = cmd.AddIntParam("@PlaceGroupId").Output();
                        SqlParameter PlaceGroupNameParam     = cmd.AddNVarCharParam("@PlaceGroupName", 50).Output();
                        SqlParameter retValParam             = cmd.AddReturnValue();

                        await cmd.ExecuteNonQueryAsync();

                        int retVal = retValParam.GetInt32OrDefault();
                        if (retVal == -1)
                        {
                            return(this.GetAuthKeyNotFoundResponse());
                        }

                        CheckStatusResponse response = new CheckStatusResponse();
                        response.EmployeeId         = EmployeeIdParam.GetInt32OrDefault();
                        response.EmployeeFirstName  = EmployeeFirstNameParam.Value.ToString();
                        response.EmployeeLastName   = EmployeeLastNameParam.Value.ToString();
                        response.EmployeeIsDisabled = EmployeeIsDisabledParam.GetBooleanOrDefault();
                        response.PlaceGroupId       = PlaceGroupIdParam.GetInt32OrNull();
                        response.PlaceGroupName     = PlaceGroupNameParam.GetStringOrNull();

                        return(new JsonResult(response));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new JsonErrorResult(this.GetExceptionResponse(ex)));
            }
        }
Esempio n. 2
0
        private async Task WriteMessageLog(MessageLog log)
        {
            try
            {
                using (SqlConnection conn = this._sqlServer.GetConnection())
                {
                    await conn.OpenAsync();

                    using (SqlCommand cmd = this._sqlServer.GetSpCommand("telegram.WriteMessageLog", conn))
                    {
                        cmd.AddBitParam("@InputMessage", log.InputMessage);
                        cmd.AddBigIntParam("@TelegramId", log.TelegramId);
                        cmd.AddCharParam("@Phone", 10, log.Phone);
                        cmd.AddIntParam("@EmployeeId", log.EmployeeId);
                        cmd.AddNVarCharMaxParam("@MessageData", log.GetJson());

                        await cmd.ExecuteNonQueryAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                string exStr = ex.ToString();
                _logger.LogError(exStr, "Ошибка при сохранениии записи в журнале сообщений");
                Helper.SaveDiagMessage(_sqlServer, DiagOptions.Tech, "TelegramHostedService.WriteMessageLog, Ошибка при сохранениии записи в журнале сообщений: " + exStr, _logger);
            }
        }
Esempio n. 3
0
        private async Task SavePayment(Payment payment, SqlConnection conn, SqlTransaction tx)
        {
            DataAccess.StructuredParamValue amounts = null;
            if (payment.PersonalAmounts.Count > 0)
            {
                amounts = new DataAccess.StructuredParamValue(_amountsMetadata, payment.PersonalAmounts.Count);
                foreach (PersonalAmount pa in payment.PersonalAmounts)
                {
                    amounts.NewRecord();
                    amounts.AddInt32(pa.EmployeeId);
                    amounts.AddDecimal(pa.Amount);
                }
            }

            using (SqlCommand cmd = _sqlServer.GetSpCommand("payment.SavePayment", conn, tx))
            {
                cmd.AddIntParam("@PlaceId", payment.PlaceId);
                cmd.AddIntParam("@EmployeeId", payment.EmployeeId);
                cmd.AddIntParam("@ShareSchemeHistoryId", payment.ShareSchemeHistoryId);
                cmd.AddTinyIntParam("@Status", (byte)payment.Status);
                cmd.AddTinyIntParam("@ReasonToReturn", (byte?)payment.ReasonToReturn);
                cmd.AddCharParam("@DataSource", 6, payment.DataSource);
                cmd.AddCharParam("@Provider", 6, payment.Provider);
                cmd.AddDecimalParam("@OriginalAmount", 18, 2, payment.OriginalAmount);
                cmd.AddDecimalParam("@ReceivedAmount", 18, 2, payment.ReceivedAmount);
                cmd.AddDecimalParam("@BankCommissionAmount", 18, 2, payment.BankCommissionAmount);
                cmd.AddDecimalParam("@AgentCommissionAmount", 18, 2, payment.AgentCommissionAmount);
                cmd.AddDecimalParam("@IncomeAmount", 18, 2, payment.IncomeAmount);
                cmd.AddDecimalParam("@PayoutAmount", 18, 2, payment.PayoutAmount);
                cmd.AddDateTime2Param("@PaymentDateTime", payment.PaymentDateTime);
                cmd.AddBitParam("@IsTimeSpecified", payment.IsTimeSpecified);
                cmd.AddDateTime2Param("@ArrivalDateTime", payment.ArrivalDateTime);
                cmd.AddVarCharParam("@DocumentName", 100, (payment.DocumentId.HasValue ? null : payment.DocumentName));
                SqlParameter documentIdParam = cmd.AddIntParam("@DocumentId", payment.DocumentId).InputOutput();
                cmd.AddVarCharParam("@DocumentNumber", 40, (payment.DocumentId.HasValue ? null : payment.DocumentNumber));
                cmd.AddDateParam("@DocumentDate", (payment.DocumentId.HasValue ? null : payment.DocumentDate));
                cmd.AddVarCharParam("@ExternalId", 50, payment.ExternalId);
                cmd.AddNVarCharParam("@Fio", 100, payment.Fio);
                cmd.AddNVarCharParam("@Address", 150, payment.Address);
                cmd.AddNVarCharParam("@Purpose", 150, payment.Purpose);
                cmd.AddNVarCharMaxParam("@RawData", payment.RawData);
                cmd.AddStructuredParam("@Amounts", "payment.PaymentShare", amounts);
                SqlParameter PaymentIdParam = cmd.AddBigIntParam("@PaymentId").Output();
                SqlParameter StatusParam    = cmd.AddTinyIntParam("@FinalStatus").Output();

                await cmd.ExecuteNonQueryAsync();

                payment.Id     = PaymentIdParam.GetInt64();
                payment.Status = (PaymentStatus)StatusParam.GetByte();
                if (!payment.DocumentId.HasValue)
                {
                    payment.DocumentId = documentIdParam.GetInt32OrNull();
                }
            }
        }
Esempio n. 4
0
        private async Task TurnEnterExitEmployee(Update update, Employee employee, string command)
        {
            TurnSessionData session = (TurnSessionData)employee.DialogSession;

            bool isCorrect = true;

            if (command.Length < 2 || command[0] != '-' && command[0] != '+')
            {
                isCorrect = false;
            }

            bool isEnter    = (command[0] == '+');
            int  employeeId = 0;

            if (isCorrect)
            {
                for (int i = 1; i < command.Length; i++)
                {
                    if (!char.IsDigit(command[i]))
                    {
                        isCorrect = false;
                        break;
                    }
                }

                if (isCorrect)
                {
                    if (!int.TryParse(command.Substring(1), out employeeId))
                    {
                        isCorrect = false;
                    }
                }
            }

            int retVal = 0;

            if (isCorrect)
            {
                using (SqlConnection conn = _sqlServer.GetConnection())
                {
                    await conn.OpenAsync();

                    using (SqlCommand cmd = _sqlServer.GetSpCommand("telegram.DialogSession_Turn_EnterExitEmployee", conn))
                    {
                        cmd.AddIntParam("@ManagerId", employee.Id);
                        cmd.AddBigIntParam("@ManagerTelegramId", employee.TelegramUserId);
                        cmd.AddNVarCharParam("@ManagerName", 101, employee.GetFullName());
                        cmd.AddIntParam("@EmployeeId", employeeId);
                        cmd.AddIntParam("@PlaceId", employee.Place.Id);
                        cmd.AddBitParam("@IsEnter", isEnter);
                        SqlParameter retValParam = cmd.AddReturnValue();

                        await cmd.ExecuteNonQueryAsync();

                        retVal = retValParam.GetInt32OrDefault();
                    }
                }

                isCorrect = (retVal >= 0);
            }

            if (isCorrect)
            {
                string text;
                if (retVal == 1)
                {
                    text = "Сотрудник уже вошёл в смену";
                }
                else if (retVal == 2)
                {
                    text = "Сотрудник уже вышел из смены";
                }
                else
                {
                    text = "Команда успешно выполнена";
                }

                ReplyKeyboardMarkup keyboard = GetStandardKeyboardMarkup(employee);
                await _telegramClient.SendTextMessageAsync(update.Message.From.Id, text, ParseMode.Default, false, false, 0, keyboard, _cts.Token);

                await this.WriteMessageLog(new MessageLog(text, employee, keyboard));
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                if (retVal == -1)
                {
                    sb.Append("Вы не можете управлять сменами сотрудников. Нажмите кнопку <b>Назад</b>");
                }
                else if (retVal == -2)
                {
                    sb.Append("Сотрудник не принадлежит вашему заведению. Исправьте или нажмите кнопку <b>Назад</b>");
                }
                else
                {
                    sb.Append("Вы ввели неизвестную команду. Исправьте или нажмите кнопку <b>Назад</b>");
                }

                TurnSessionData.Employees employees = null;
                if (retVal != -1)
                {
                    employees = await session.GetEmployeesStatus(employee, _sqlServer);

                    sb.AppendLine().AppendLine();
                    this.GetEmployeesTurnStatusMessageForManager(employees, sb);
                }

                string text = sb.ToString();
                ReplyKeyboardMarkup keyboard = employee.DialogSession.GetKeyboardMarkup(employee, employees);
                await _telegramClient.SendTextMessageAsync(update.Message.From.Id, text, ParseMode.Html, false, false, 0, keyboard, _cts.Token);

                await this.WriteMessageLog(new MessageLog(text, employee, keyboard));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Handle(HttpRequest request, FollowReglinkRequest data)
        {
            AuthByKeyResult authResult = this.HasAuthenticationKey(request);

            if (!authResult.Result)
            {
                return(new JsonErrorResult(authResult.ErrorResponse));
            }

            ErrorResponse validationError = this.ValidateRequest(data);

            if (validationError != null)
            {
                return(new JsonErrorResult(validationError));
            }

            try
            {
                using (SqlConnection conn = sqlServer.GetConnection())
                {
                    await conn.OpenAsync();

                    using (SqlCommand cmd = sqlServer.GetSpCommand("Employee_FollowRegistrationLink", conn))
                    {
                        cmd.AddUniqueIdentifierParam("@LinkParameter", data.LinkParameter);
                        cmd.AddBinaryParam("@PermanentKey", 16, authResult.Key.ToArray());

                        SqlParameter LinkPlaceIdParam        = cmd.AddIntParam("@LinkPlaceId").Output();
                        SqlParameter LinkPlaceNameParam      = cmd.AddNVarCharParam("@LinkPlaceName", 100).Output();
                        SqlParameter LinkPlaceAddressParam   = cmd.AddNVarCharParam("@LinkPlaceAddress", 100).Output();
                        SqlParameter LinkPlaceCityParam      = cmd.AddNVarCharParam("@LinkPlaceCity", 40).Output();
                        SqlParameter EmployeeIdParam         = cmd.AddIntParam("@EmployeeId").Output();
                        SqlParameter EmployeePlaceIdParam    = cmd.AddIntParam("@EmployeePlaceId").Output();
                        SqlParameter EmployeeIsDisabledParam = cmd.AddBitParam("@EmployeeIsDisabled").Output();
                        SqlParameter retValParam             = cmd.AddReturnValue();

                        await cmd.ExecuteNonQueryAsync();

                        int retVal = retValParam.GetInt32OrDefault();
                        if (retVal < 0)
                        {
                            ErrorResponse errorResponse = this.GetErrorResponse(retVal);
                            return(new JsonErrorResult(errorResponse));
                        }

                        FollowReglinkResponse response = new FollowReglinkResponse();
                        response.LinkPlaceId        = LinkPlaceIdParam.GetInt32OrDefault();
                        response.LinkPlaceName      = LinkPlaceNameParam.Value.ToString();
                        response.LinkPlaceAddress   = LinkPlaceAddressParam.Value.ToString();
                        response.LinkPlaceCity      = LinkPlaceCityParam.Value.ToString();
                        response.EmployeeId         = EmployeeIdParam.GetInt32OrNull();
                        response.EmployeePlaceId    = EmployeePlaceIdParam.GetInt32OrNull();
                        response.EmployeeIsDisabled = EmployeeIsDisabledParam.GetBooleanOrNull();
                        return(new JsonResult(response));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new JsonErrorResult(this.GetExceptionResponse(ex)));
            }
        }
Esempio n. 6
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);
        }