Esempio n. 1
0
        public async Task <List <Event> > GetEventsByDate(DateTime date)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse($"{_token.Type} {_token.Value}");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var response = await client.GetAsync(GetEventsByDateUri + date.ToString("yyyy-MM-dd"));

                var jsonString = await response.Content.ReadAsStringAsync();

                Debug.WriteLine(jsonString);

                if (string.IsNullOrEmpty(jsonString))
                {
                    ServerError = new ErrorsDto <string>
                    {
                        Message = "Нет ответа от сервера"
                    };
                    return(null);
                }

                if (response.IsSuccessStatusCode)
                {
                    var jsonData = JsonConvert.DeserializeObject <JsonResponseDto <List <EventDto> > >(jsonString);
                    return(_mapper.Map <List <Event> >(jsonData.Data));
                }

                var jsonError = JsonConvert.DeserializeObject <ErrorsDto <string> >(jsonString);
                ServerError = jsonError;
                return(null);
            }
        }
        public ActionResult <ExpenseDto> Post([FromBody] string content)
        {
            try
            {
                var expense = _expenseExtractService.GetExpense(content);
                return(expense);
            }
            catch (InvalidContentException invalidContentException)
            {
                _logger.LogError("Invalid Content", invalidContentException);

                var errorsViewModel = new ErrorsDto
                {
                    Errors = new[]
                    {
                        new ErrorDto
                        {
                            Title  = "Invalid Content",
                            Detail = invalidContentException.Message
                        }
                    }
                };
                return(BadRequest(errorsViewModel));
            }
        }
Esempio n. 3
0
        public async Task <User> Register(RegisterDto registrationDto)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var json = JsonConvert.SerializeObject(registrationDto);
                Debug.WriteLine(json);
                var response = await client.PostAsync(SignUpUri, new StringContent(json, Encoding.UTF8, "application/json"));

                var jsonString = await response.Content.ReadAsStringAsync();

                Debug.WriteLine(jsonString);

                if (string.IsNullOrEmpty(jsonString))
                {
                    ServerRegistrationError = new ErrorsDto <RegisterErrorDto>
                    {
                        Message = "Нет ответа от сервера"
                    };
                    return(null);
                }

                if (response.IsSuccessStatusCode)
                {
                    var jsonData = JsonConvert.DeserializeObject <JsonResponseDto <UserDto> >(jsonString);
                    return(_mapper.Map <User>(jsonData.Data));
                }

                var jsonError = JsonConvert.DeserializeObject <ErrorsDto <RegisterErrorDto> >(jsonString);
                ServerRegistrationError = jsonError;
                return(null);
            }
        }
Esempio n. 4
0
        public ErrorsDto Validate(string password)
        {
            var errors = new ErrorsDto();

            if (password.Length > MaximalLength)
            {
                errors.AddError(String.Format(ServiceMessages.MaximalLengthError, MaximalLength));
            }

            if (password.Length < MinimalLength)
            {
                errors.AddError(String.Format(ServiceMessages.MinimalLengthError, MinimalLength));
            }

            if (password.All(IsLetterOrDigit))
            {
                errors.AddError(ServiceMessages.NonAlphanumericError);
            }

            if (!password.Any(IsDigit))
            {
                errors.AddError(ServiceMessages.DigitError);
            }

            if (!password.Any(IsLower))
            {
                errors.AddError(ServiceMessages.LowerError);
            }

            if (!password.Any(IsUpper))
            {
                errors.AddError(ServiceMessages.UpperError);
            }

            return(errors);
        }