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 DeletePromotionCustomerWithId(int id) { if (PromtionCustomerExists(id)) { try { PromotionCustomer promotionCustomer = await _ctx.PromotionCustomers.FindAsync(id); _ctx.Remove(promotionCustomer); await _ctx.SaveChangesAsync(); return; } catch (Exception ex) { _logger.LogInformation($"could not delete promotion customer: {ex.Message}"); } } throw new Exception(); }