public WriteResult Create(OrderDTO orderDTO) { var result = new WriteResult { IsSuccess = true }; try { #region Validation var validationResult = _orderValidator.ValidateCreate(orderDTO); if (!validationResult.IsSuccess) { return(_mapper.Map <WriteResult>(validationResult)); } #endregion #region Create Order var order = _mapper.Map <Order>(orderDTO); var resultOrder = _orderUnitOfWork.OrderRepository.Create(order); #region Reduce Quntity orderDTO.OrderDetail.ForEach(a => { if (a.ProductId.HasValue) { _orderUnitOfWork.ProductRepository.ReduceQuntity(a.ProductId.Value, a.Quantity.GetValueOrDefault()); } }); #endregion #endregion #region Save Changes _orderUnitOfWork.Save(); #endregion #region Send Alert var account = _orderUnitOfWork.AccountRepository.Get(order.AccountId); var alertDTO = new OrderComfirmationAlertDTO { Email = account.Email , OrderNumber = order.OrderNumber , OrderProducts = _mapper.Map <List <OrderDetailDTO> >(order.OrderDetail.ToList()) }; _appCacheService.MailService.SendOrderConfirmation(alertDTO); #endregion } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; } return(result); }
public void SendOrderConfirmation(OrderComfirmationAlertDTO alertDTO) { var bodyHtml = @"<html><body> Thank you for your order, your order has been confirmed! </html></body> "; var mailMessage = new MailMessage { Subject = $"Order Confirmation - {alertDTO.OrderNumber}" , IsBodyHtml = true , From = new MailAddress(_smtpConfigurationSetting.FromEmail) , Body = bodyHtml }; mailMessage.To.Add(alertDTO.Email); SendEmail(mailMessage); }