コード例 #1
0
        public async Task <APIResult <Citizen> > UpdateCitizenPassword(string LoginAccountId, string TypedCurrentPassword, string NewPassword, string VerifyNewPassword)
        {
            if (string.IsNullOrWhiteSpace(LoginAccountId))
            {
                return(APIResult <Citizen> .CreateFailed(
                           HttpStatusCode.BadRequest, $"Null or empty {nameof(LoginAccountId)}"));
            }

            if (LoginAccountId.Length != 9)
            {
                return(APIResult <Citizen> .CreateFailed(
                           HttpStatusCode.BadRequest, $"Invalid {nameof(LoginAccountId)}"));
            }

            var citizen = await context_.Citizens
                          .Where(c => c.CitizenId.Equals(LoginAccountId,
                                                         StringComparison.OrdinalIgnoreCase))
                          .Where(c => c.Password == TypedCurrentPassword)
                          .SingleOrDefaultAsync();

            if (citizen == null)
            {
                return(APIResult <Citizen> .CreateFailed(
                           HttpStatusCode.NotFound, $"Invalid {nameof(LoginAccountId)}"));
            }

            citizen.Password       = NewPassword;
            citizen.ChangePassword = false;

            context_.Citizens.Update(citizen);
            context_.SaveChanges();

            return(APIResult <Citizen> .CreateSuccessful(citizen));
        }
コード例 #2
0
        public async Task <APIResult <Citizen> > GetCitizenAccountAsync(
            string LoginAccountId)
        {
            if (string.IsNullOrWhiteSpace(LoginAccountId))
            {
                return(APIResult <Citizen> .CreateFailed(
                           HttpStatusCode.BadRequest, $"Null or empty {nameof(LoginAccountId)}"));
            }

            if (LoginAccountId.Length != 9)
            {
                return(APIResult <Citizen> .CreateFailed(
                           HttpStatusCode.BadRequest, $"Invalid {nameof(LoginAccountId)}"));
            }

            var citizen = await context_.Citizens
                          .Where(c => c.CitizenId.Equals(LoginAccountId,
                                                         StringComparison.OrdinalIgnoreCase))
                          .SingleOrDefaultAsync();

            if (citizen == null)
            {
                return(APIResult <Citizen> .CreateFailed(
                           HttpStatusCode.NotFound, $"Invalid {nameof(LoginAccountId)}"));
            }

            return(APIResult <Citizen> .CreateSuccessful(citizen));
        }