public async Task <IActionResult> SaveClientBelonging(ClientBelongingViewModel model) { _logger.LogInformation(GetLogDetails() + " - model:{@Model}", args: new object[] { model }); // process request var userId = _userManager.GetUserId(User); var result = await _clientService.SaveClientBelongingAsync(model, userId); return(Json(new { success = result.Success, error = result.Error })); }
public async Task <(bool Success, string Error, ClientBelongingViewModel Model)> FetchClientBelongingViewModelForEditAsync(int id) { var success = false; var error = ""; var model = new ClientBelongingViewModel(); try { if (id > 0) { var belonging = await _clientBelongingRepository.FetchBaseByIdAsync(id); if (belonging != null) { model.ClientBelongingId = belonging.ClientBelongingId; model.TransactionAction = belonging.TransactionAction; model.MetalId = belonging.MetalId; model.MetalOther = belonging.MetalOther; model.KaratId = belonging.KaratId; model.KaratOther = belonging.KaratOther; model.ItemDescription = belonging.ItemDescription; model.Weight = belonging.ItemWeight; model.ItemPrice = belonging.ItemPrice; model.FinalPrice = belonging.FinalPrice; model.ReplacementValue = belonging.ReplacementValue; model.ClientReceiptId = belonging.ClientReceiptId; model.HstAmount = belonging.HstAmount; success = true; } else { error = "Unable to locate data"; } } else { error = "Invalid request"; } } catch (Exception ex) { error = "Somethong went wrong while processing your request."; _logger.LogError("ClientService.FetchClientBelongingViewModelForEditAsync - exception:{@Ex}", args: new object[] { ex }); } return(Success : success, Error : error, Model : model); }
public async Task <(bool Success, string Error)> SaveClientBelongingAsync(ClientBelongingViewModel model, string userId) { var success = false; var error = string.Empty; try { if (model.ClientReceiptId > 0) { ClientBelonging clientBelonging = null; if (model.ClientBelongingId > 0) { clientBelonging = await _clientBelongingRepository.FetchBaseByIdAsync(model.ClientBelongingId.Value); } if (clientBelonging == null) { clientBelonging = new ClientBelonging { CreatedUserId = userId, CreatedUtc = DateTime.UtcNow }; } else { clientBelonging.AuditUserId = userId; clientBelonging.AuditUtc = DateTime.UtcNow; } // save other values clientBelonging.ClientReceiptId = model.ClientReceiptId; clientBelonging.TransactionAction = model.TransactionAction; if (model.MetalId.HasValue && model.MetalId != Guid.Empty) { clientBelonging.MetalId = model.MetalId; clientBelonging.MetalOther = null; } else { clientBelonging.MetalId = null; clientBelonging.MetalOther = model.MetalOther; } if (model.KaratId.HasValue && model.KaratId != Guid.Empty) { clientBelonging.KaratId = model.KaratId; clientBelonging.KaratOther = null; } else { clientBelonging.KaratId = null; clientBelonging.KaratOther = model.KaratOther; } clientBelonging.ItemDescription = model.ItemDescription; clientBelonging.ItemWeight = model.Weight; clientBelonging.ItemPrice = model.ItemPrice; clientBelonging.FinalPrice = model.FinalPrice; clientBelonging.ReplacementValue = model.ReplacementValue; clientBelonging.HstAmount = model.HstAmount; await _clientBelongingRepository.SaveClientBelongingAsync(clientBelonging); success = true; } else { error = "Invalid request"; } } catch (Exception ex) { error = "Somethong went wrong while processing your request."; _logger.LogError("ClientService.SaveClientBelongingAsync - exception:{@Ex}", args: new object[] { ex }); } return(Success : success, Error : error); }