Ejemplo n.º 1
0
 public static Card ToCard(this CardUpdateRequest request) =>
 new Card()
 {
     Id        = request.Id,
     Number    = request.Number,
     Type      = (CardTypes)request.Type,
     Created   = request.Created,
     ValidThru = request.ValidThru,
     Cvc       = request.Cvc,
     Owner     = request.Owner,
 };
Ejemplo n.º 2
0
        public HttpResponseMessage Update(CardUpdateRequest card)
        {
            if (!ModelState.IsValid && card != null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            int id = _flashcardServices.Update(card);

            int response = id;

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Ejemplo n.º 3
0
    public async Task <ActionResult <CardResponse> > Put([FromBody] CardUpdateRequest request)
    {
        if (!ModelState.IsValid)
        {
            return(BadRequest(ModelState));
        }

        var model = _mapper.Map <Card>(request);
        await _db.UpdateAsync(model);

        _logger.LogInformation("Карта {0} успешно изменена", request.Id);

        var result = _mapper.Map <CardResponse>(model);

        return(Ok(result));
    }
Ejemplo n.º 4
0
 public async Task UpdateCardTest()
 {
     var requestTester     = GetRequestTester();
     var customerId        = "1";
     var cardId            = "1";
     var cardUpdateRequest = new CardUpdateRequest()
     {
         CardholderName = "Jan Kowaslki", CustomerId = customerId, CardId = cardId
     };
     await requestTester.TestMethod <Card>(
         async (api) =>
     {
         await api.UpdateCard(cardUpdateRequest);
     },
         new RequestDescriptor()
     {
         Method    = HttpMethod.Post,
         Action    = string.Format("customers/{0}/cards/{1}", customerId, cardId),
         Parameter = cardUpdateRequest
     }
         );
 }
Ejemplo n.º 5
0
    public async Task <ActionResult <CardResponse> > Put([FromBody] CardUpdateRequest request)
    {
        try
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var model = request.ToCard();
            await _db.UpdateAsync(model);

            _logger.LogInformation("Карта {0} успешно изменена", request.Id);

            var result = model.ToResponse();
            return(Ok(result));
        }
        catch (Exception ex)
        {
            LogError(ex);
            return(BadRequest($"Ошибка изменения карты {request.Id}"));
        }
    }
Ejemplo n.º 6
0
        public int Update(CardUpdateRequest card)
        {
            int cardId = 0;
            //string user = "******";

            string connectionString = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand("dbo.Flashcards_Update", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@Id", card.Id);
                    command.Parameters.AddWithValue("@Front", card.Front);
                    command.Parameters.AddWithValue("@Back", card.Back);

                    connection.Open();
                    command.ExecuteNonQuery();

                    int.TryParse(command.Parameters["@Id"].Value.ToString(), out cardId);
                }
            }
            return(cardId);
        }
Ejemplo n.º 7
0
        public async Task <Card> UpdateCard(CardUpdateRequest updateCard)
        {
            var url = string.Format(CARDS_PATH, updateCard.CustomerId) + "/" + updateCard.CardId;

            return(await SendRequest <Card>(HttpMethod.Post, url, updateCard));
        }