public async Task <ActionResult <ProductRegRespObj> > AddUpdateProductAsync([FromBody] ProductObj entity) { try { var isDone = false; var user = await _identityServer.UserDataAsync(); var createdBy = user.UserName; entity.CreatedBy = createdBy; entity.UpdatedBy = createdBy; var product = _repo.AddUpdateProduct(entity); if (product != null) { isDone = true; var allAllowableCollaterals = await _allowableCollateralRepository.GetAllowableCollateralByProductIdAsync(product.ProductId); if (allAllowableCollaterals != null) { await _allowableCollateralRepository.DeleteListAllowableCollateralByProductIdAsync(product.ProductId); } var listOfAallowableCollateral = new List <AllowableCollateralObj>(); if (entity.AllowableCollaterals != null) { foreach (var id in entity.AllowableCollaterals) { listOfAallowableCollateral.Add(new AllowableCollateralObj { CollateralTypeId = id, ProductId = product.ProductId }); } await _allowableCollateralRepository.AddAllowableCollateral(listOfAallowableCollateral); } } return(new ProductRegRespObj { Products = product, Status = new APIResponseStatus { IsSuccessful = isDone ? true : false, Message = new APIResponseMessage { FriendlyMessage = isDone ? "Successful" : "Unsuccessful" } } }); } catch (Exception ex) { var errorCode = ErrorID.Generate(5); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new ProductRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }