public async Task <IActionResult> Create(CustumerProductDto customerProduct) { if (!ModelState.IsValid) { return(View("Error", "Home")); } try { var result = await _cust.AddCustomerProduct(customerProduct); if (result.Item1) { if (result.Item2) { ViewData["Success"] = "Mail Sent"; } else { ViewData["Success"] = "Not Sent"; } return(RedirectToAction(nameof(Details))); } return(View("Error", "Home")); } catch { return(View("Error", "Home")); } }
public async Task <(bool, bool)> AddCustomerProduct(CustumerProductDto customerProductDto) { bool mailSent = false; CustomerDto customer = new CustomerDto { CustomersWant = customerProductDto.CustomerDecription, UserId = customerProductDto.UserId }; (bool, bool, string)result = await _cusRepository.AddCustomer(customer); if (result.Item1) { if (result.Item2) { mailSent = true; } CustomerProduct customerProduct = new CustomerProduct { CustomerDecription = $"{customerProductDto.Service} \n {customerProductDto.CustomerDecription}", CustomerHasPaid = customerProductDto.CustomerHasPaid, CustomerId = result.Item3, ExpectedEndDate = customerProductDto.ExpectedEndDate, ExpectedStartDate = customerProductDto.ExpectedStartDate, PaymentType = customerProductDto.PaymentType, Stage = customerProductDto.Stage, }; try { _ctx.CustomerProducts.Add(customerProduct); await _ctx.SaveChangesAsync(); return(true, mailSent); } catch (Exception ex) { _logger.LogInformation($"could not add customer product: {ex.Message}"); return(false, mailSent); } } return(false, mailSent); }