示例#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)));
            }
        }
示例#2
0
        public async Task <IActionResult> Handle(HttpRequest request, EnterSsRequest 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));
            }

            byte[] securedKey = Guid.NewGuid().ToByteArray();

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

                    using (SqlCommand cmd = sqlServer.GetSpCommand("dbo.Employee_EnterSecuredSession", conn))
                    {
                        cmd.AddBinaryParam("@PermanentKey", 16, authResult.Key.ToArray());
                        cmd.AddBinaryParam("@SecuredKey", 16, securedKey);
                        cmd.AddCharParam("@Phone", 10, data.Phone);
                        cmd.AddCharParam("@PinCode", 4, data.PinCode);

                        SqlParameter retValParam = cmd.AddReturnValue();

                        await cmd.ExecuteNonQueryAsync();

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

                        EnterSsResponse response = new EnterSsResponse();
                        response.SecuredKey = AuthKey.Create(securedKey).ToString() + authResult.Key.ToString();
                        return(new JsonResult(response));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new JsonErrorResult(this.GetExceptionResponse(ex)));
            }
        }
示例#3
0
        public async Task <IActionResult> Handle(HttpRequest request, JoinPlaceRequest 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_JoinPlace", conn))
                    {
                        cmd.AddBinaryParam("@PermanentKey", 16, authResult.Key.ToArray());
                        cmd.AddUniqueIdentifierParam("@LinkParameter", data.LinkParameter);
                        cmd.AddIntParam("@PlaceId", data.PlaceToJoinId);
                        SqlParameter retValParam = cmd.AddReturnValue();

                        await cmd.ExecuteNonQueryAsync();

                        int retVal = retValParam.GetInt32OrDefault();

                        if (retVal == -1)
                        {
                            return(this.GetAuthKeyNotFoundResponse());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(new JsonErrorResult(this.GetExceptionResponse(ex)));
            }

            return(new EmptyResult());
        }
示例#4
0
        public async Task <IActionResult> Handle(HttpRequest request, Request data)
        {
            AuthByKeyResult authResult = this.GetAuthenticationKey(request);

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

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

                    using (SqlCommand cmd = sqlServer.GetSpCommand("dbo.Employee_Logout", conn))
                    {
                        cmd.AddBinaryParam("@PermanentKey", 16, authResult.Key.ToArray());
                        SqlParameter retValParam = cmd.AddReturnValue();
                        await cmd.ExecuteNonQueryAsync();

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

            return(new EmptyResult());
        }
示例#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)));
            }
        }