public async Task <IActionResult> Create(PromotionCustomerDto promotion) { if (!ModelState.IsValid) { return(View("Error", "Home")); } try { var result = await _promo.AddCustomerProduct(promotion); 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 UpdatePromotionCustomerWithId(PromotionCustomerDto promotionCustomer) { if (PromtionCustomerExists(promotionCustomer.PromotionCustomerId)) { try { PromotionCustomer promotion = await _ctx.PromotionCustomers .Where(p => p.PromotionCustomerId == promotionCustomer.PromotionCustomerId) .Select(p => new PromotionCustomer { CustomerId = p.CustomerId, Price = promotionCustomer.Price, PromotionId = p.PromotionId, HasPaid = promotionCustomer.HasPaid, PaymentType = promotionCustomer.PaymentType, ActualEndDate = promotionCustomer.ActualEndDate, PromotionDetail = !string.IsNullOrEmpty(promotionCustomer.PromotionDetail) ? promotionCustomer.PromotionDetail : p.PromotionDetail, ActualStartDate = promotionCustomer.ActualStartDate, ExpectedStartDate = promotionCustomer.HasPaid && !p.HasPaid ? DateTime.Now : promotionCustomer.ExpectedStartDate, ExpectedEndDate = promotionCustomer.HasPaid && !p.HasPaid ? DateTime.Now.AddDays(14) : promotionCustomer.ExpectedEndDate, PromotionCustomerId = p.PromotionCustomerId }).SingleOrDefaultAsync(); _ctx.Update(promotion); await _ctx.SaveChangesAsync(); return; } catch (Exception ex) { _logger.LogInformation($"could not delete promotion customer: {ex.Message}"); } } throw new Exception(); }
public async Task <(bool, bool)> AddCustomerProduct(PromotionCustomerDto promotionCustomerDto) { bool mailSent = false; CustomerDto customer = new CustomerDto { CustomersWant = promotionCustomerDto.CustomersWant, UserId = promotionCustomerDto.UserId }; (bool, bool, string)result = await _cusRepository.AddCustomer(customer); if (result.Item1) { if (result.Item2) { mailSent = true; } PromotionCustomer promotionCustomer = new PromotionCustomer { CustomerId = result.Item3, PromotionId = promotionCustomerDto.PromotionId, HasPaid = false, Price = promotionCustomerDto.Price, PromotionDetail = promotionCustomerDto.PromotionDetail, PaymentType = Enums.PaymentType.None }; try { _ctx.PromotionCustomers.Add(promotionCustomer); await _ctx.SaveChangesAsync(); return(true, mailSent); } catch (Exception ex) { _logger.LogInformation($"could not add customer promotion: {ex.Message}"); return(false, mailSent); } } return(false, mailSent); }
public async Task <IActionResult> Edit(int id, PromotionCustomerDto promotionDto, bool payment = false) { if (id != promotionDto.PromotionCustomerId) { return(RedirectToAction("Edit", new { id })); } try { await _promo.UpdatePromotionCustomerWithId(promotionDto); // TODO: Add update logic here if (payment) { return(RedirectToAction("Details")); } return(RedirectToAction(nameof(Index))); } catch { return(View("Error", "Home")); } }