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, };
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)); }
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)); }
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 } ); }
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}")); } }
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); }
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)); }