public async Task <IActionResult> Create(BuyerManagementDTO buyer) { if (ModelState.IsValid) { try { _repositoryWrapper.Buyer.CreateBuyer(_mapper.Map <Buyer>(buyer)); await _repositoryWrapper.SaveAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { _logger.LogError($"Error occured when creating a new buyer: {ex}"); RedirectToAction(nameof(Index)); } } return(View(nameof(Create), buyer)); }
public async Task <IActionResult> Edit(int id, BuyerManagementDTO buyer) { if (id != buyer.Id) { _logger.LogError($"{id} is not a valid id"); return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { try { _repositoryWrapper.Buyer.UpdateBuyer(_mapper.Map <Buyer>(buyer)); await _repositoryWrapper.SaveAsync(); } catch (Exception ex) { _logger.LogError($"Error occured when updating buyer: {ex}"); } return(RedirectToAction(nameof(Index))); } return(View(nameof(Edit), buyer)); }