public JsonResult Post([FromBody] BuyerViewModel viewModel) { try { if (ModelState.IsValid) { var newBuyer = Mapper.Map <Buyer>(viewModel); _logger.LogInformation("Attemping to save new Buyer"); _repository.AddBuyer(newBuyer); if (_repository.SaveAll()) { Response.StatusCode = (int)HttpStatusCode.Created; return(Json(Mapper.Map <BuyerViewModel>(newBuyer))); } } } catch (Exception ex) { _logger.LogError("Failed to save new Buyer", ex); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Message = ex.Message })); } return(Json("Failed!")); }
private void ButtonAddBuyer_Click(object sender, RoutedEventArgs e) { try { if (!string.IsNullOrWhiteSpace(_newBuyer.Error)) { return; } int _idCounter = 1; foreach (Buyer buyer in buyerRepository.GetAll()) { _idCounter++; } _newBuyer.BuyerID = _idCounter++; _newBuyer.BuyerName = TextBoxAddBuyerName.Text; _newBuyer.BuyerAdress = TextBoxAddBuyerAdress.Text; _newBuyer.BuyerUNP = Int32.Parse(TextBoxAddBuyerUNP.Text); _newBuyer.BuyerPhone = TextBoxAddBuyerPhone.Text; _newBuyer.BuyerRequest = TextBoxAddBuyerRequest.Text; buyerRepository.AddBuyer(_newBuyer); MessageBox.Show("Данные добавлены."); this.Close(); } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Ошибка"); } }
public async Task Handle(OrderStartedDomainEvent notification, CancellationToken cancellationToken) { var buyer = await _buyerRepository.FindAsync(notification.UserId); bool buyerOriginallyExisted = (buyer == null) ? false : true; if (!buyerOriginallyExisted) { buyer = new Buyer(notification.UserId, notification.UserName); } var buyerUpdated = buyerOriginallyExisted ? _buyerRepository.UpdateBuyer(buyer) : _buyerRepository.AddBuyer(buyer); await _buyerRepository.unitOfWork.SaveEntitiesAsync(); _logger.CreateLogger(nameof(ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler)); }