public async Task <IActionResult> AddEditReceive(int?id, TransactionForReceiveViewModel transactionForReceiveViewModel) { string message = string.Empty; try { if (ModelState.IsValid) { bool isNew = !id.HasValue; if (isNew) { var transactionReceiveToCreate = _mapper.Map <CustomerTransaction>(transactionForReceiveViewModel); await _uow.CustomerTransactions.AddAsync(transactionReceiveToCreate); await _uow.SaveAsync(); TempData["Message"] = "Saved Successfully"; TempData["Status"] = "success"; } else { var transactionReceiveToUpdate = _mapper.Map <CustomerTransaction>(transactionForReceiveViewModel); _uow.CustomerTransactions.Update(transactionReceiveToUpdate); _uow.Save(); TempData["Message"] = "Updated Successfully"; TempData["Status"] = "success"; } } } catch (DbUpdateConcurrencyException ce) { _logger.LogError(ce.Message, id); TempData["Message"] = "Failed to update for concurrency"; TempData["Status"] = "danger"; } catch (Exception ex) { _logger.LogError(ex.Message, ex.StackTrace); } return(RedirectToAction(nameof(AddEditReceive))); }
public async Task <IActionResult> AddEditReceive(int?id) { TransactionForReceiveViewModel transactionForReceiveViewModel = new TransactionForReceiveViewModel(); if (id.HasValue) { var sellTransactionFromRepo = await _uow.CustomerTransactions.GetByIdAsync(id.Value); if (sellTransactionFromRepo == null) { return(NotFound()); } transactionForReceiveViewModel = _mapper.Map <TransactionForReceiveViewModel>(sellTransactionFromRepo); transactionForReceiveViewModel.CustomerSelectList = new SelectList(await _uow.Customers.GetAllActiveCustomerFullNameAsync(), "CustomerId", "FullName", transactionForReceiveViewModel.CustomerId); } else { transactionForReceiveViewModel.CustomerSelectList = new SelectList(await _uow.Customers.GetAllActiveCustomerFullNameAsync(), "CustomerId", "FullName"); } return(View(transactionForReceiveViewModel)); }