public (bool Success, string Error, CreatePriceViewModel Model) GetUpdatePriceViewModel() { bool success = false; string error = string.Empty; var model = new CreatePriceViewModel(); try { var now = DateTime.Now; var filterStartDate = new DateTime(now.Year, now.Month, 1); var filterEndDate = filterStartDate.AddMonths(1).AddDays(-1); model.Date = now; model.FilterStartDate = filterStartDate; model.FilterEndDate = filterEndDate; success = true; } catch (Exception ex) { error = "Unexpected error occurred while processing your request"; _logger.LogError("AdminService.GetUpdatePriceViewModel - Exception:{@Ex}", args: new object[] { ex }); } return(Success : success, Error : error, Model : model); }
public async Task <(bool Success, string Error)> SavePriceAsync(CreatePriceViewModel model, string userId) { bool success = false; string error = string.Empty; try { // determin if adding or editing Price price = null; if (model.PriceId > 0) { price = await _priceRepository.FetchBasePriceByIdAsync(model.PriceId); } if (price == null) { price = new Price { CreatedUserId = userId, CreatedUtc = DateTime.UtcNow }; } else { price.AuditUserId = userId; price.AuditUtc = DateTime.UtcNow; } // save other values price.Date = model.Date.Value; price.MetalId = model.MetalId; price.KaratId = model.KaratId; price.BuyPrice = model.BuyPrice; price.SellPrice = model.SellPrice; price.LoanPrice = model.LoanPrice; price.LoanPricePercent = model.LoanPricePercent; price.PerOunce = model.PerOunce; await _priceRepository.SavePriceAsync(price); success = true; } catch (Exception ex) { error = "Unexpected error occurred while processing your request"; _logger.LogError("AdminService.SavePriceAsync - Exception:{@Ex}", args: new object[] { ex }); } return(Success : success, Error : error); }
public async Task <(bool Success, string Error, CreatePriceViewModel Model)> GetPriceForEditAsync(int id) { bool success = false; string error = string.Empty; var model = new CreatePriceViewModel(); try { if (id > 0) { var price = await _priceRepository.FetchBasePriceByIdAsync(id); if (price != null) { model.PriceId = price.PriceId; model.Date = price.Date; model.BuyPrice = price.BuyPrice; model.SellPrice = price.SellPrice; model.LoanPrice = price.LoanPrice; model.LoanPricePercent = price.LoanPricePercent; model.KaratId = price.KaratId; model.MetalId = price.MetalId; model.PerOunce = price.PerOunce; success = true; } else { error = "Price information not found"; } } else { error = "Invalid Id"; } } catch (Exception ex) { error = "Unexpected error occurred while processing your request"; _logger.LogError("AdminService.GetPriceForEditAsync - Exception:{@Ex}", args: new object[] { ex }); } return(Success : success, Error : error, Model : model); }
public async Task <IActionResult> SavePrice(CreatePriceViewModel model) { _logger.LogInformation(GetLogDetails() + " - model:{@Model}", args: new object[] { model }); if (ModelState.IsValid) { var userId = _userManager.GetUserId(User); var result = await _adminService.SavePriceAsync(model, userId); return(Json(new { success = result.Success, error = result.Error })); } return(Json(new { success = false, error = "Please review all information and try again" })); }