// fetch all from table into new List of class instances, filtered by any column
        // links:
        //  docLink: http://sql2x.org/documentationLink/db27658d-4d23-46d7-9970-7bbaef8634b0
        public List <CrudeDefaultSystemSettingModel> FetchWithFilter(System.Guid defaultSystemSettingId, string defaultSystemSettingRcd, string defaultSystemSettingValue, System.Guid defaultUserId, System.DateTime dateTime)
        {
            var list = new List <CrudeDefaultSystemSettingModel>();
            List <CrudeDefaultSystemSettingData> dataList = CrudeDefaultSystemSettingData.FetchWithFilter(defaultSystemSettingId, defaultSystemSettingRcd, defaultSystemSettingValue, defaultUserId, dateTime);

            foreach (CrudeDefaultSystemSettingData data in dataList)
            {
                var crudeDefaultSystemSettingBusinessModel = new CrudeDefaultSystemSettingModel();
                DataToModel(data, crudeDefaultSystemSettingBusinessModel);
                list.Add(crudeDefaultSystemSettingBusinessModel);
            }

            return(list);
        }
        // fetch all rows from table into new List of Contracts, filtered by any column
        // links:
        //  docLink: http://sql2x.org/documentationLink/ce01ef4a-5cd0-4e51-b211-9c0a15b791a0
        public List <CrudeDefaultSystemSettingContract> FetchWithFilter(System.Guid defaultSystemSettingId, string defaultSystemSettingRcd, string defaultSystemSettingValue, System.Guid defaultUserId, System.DateTime dateTime)
        {
            var list = new List <CrudeDefaultSystemSettingContract>();
            List <CrudeDefaultSystemSettingData> dataList = CrudeDefaultSystemSettingData.FetchWithFilter(
                defaultSystemSettingId: defaultSystemSettingId,
                defaultSystemSettingRcd: defaultSystemSettingRcd,
                defaultSystemSettingValue: defaultSystemSettingValue,
                defaultUserId: defaultUserId,
                dateTime: dateTime
                );

            foreach (CrudeDefaultSystemSettingData data in dataList)
            {
                var crudeDefaultSystemSettingContract = new CrudeDefaultSystemSettingContract();
                DataToContract(data, crudeDefaultSystemSettingContract);
                list.Add(crudeDefaultSystemSettingContract);
            }

            return(list);
        }
Exemple #3
0
        public void PromotionSend(
            Guid servicePackagePromotionId,
            Guid userId
            )
        {
            Logging log =
                Logging.PerformanceTimeStart(
                    "Service",
                    "BusinessLogicLayer",
                    "ServiceService",
                    "PromotionSend",
                    userId
                    );

            using (var connection = new SqlConnection(Conn.ConnectionString)) {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction();

                try {
                    var promotionData = CrudeServicePackagePromotionData.GetByServicePackagePromotionId(servicePackagePromotionId);
                    var packageData   = CrudeServicePackageData.GetByServicePackageId(promotionData.ServicePackageId);
                    var clientData    = CrudeClientData.GetByClientId(promotionData.ClientId);
                    var contactData   = CrudeClientContactMethodData.GetCurrentMail(promotionData.ClientId);

                    // todo, assume one hit
                    GetServicePackageData packageDetailsData =
                        new ServiceSearch().GetServicePackage(promotionData.ServicePackageId)[0];

                    string messageText = string.Empty;
                    messageText += "Hi,<br>\r\n";
                    messageText += "<br>\r\n";
                    if (!string.IsNullOrEmpty(packageDetailsData.DepartureAirportName))
                    {
                        messageText += " From: " + packageDetailsData.DepartureAirportName + "<br>\r\n";
                    }
                    if (!string.IsNullOrEmpty(packageDetailsData.ArrivalAirportName))
                    {
                        messageText += " To: " + packageDetailsData.ArrivalAirportName + "<br>\r\n";
                    }
                    if (!string.IsNullOrEmpty(packageDetailsData.CarName))
                    {
                        messageText += " Traveling with: " + packageDetailsData.CarName + "<br>\r\n";
                    }
                    if (!string.IsNullOrEmpty(packageDetailsData.HotelName))
                    {
                        messageText += " Staying at: " + packageDetailsData.HotelName + "<br>\r\n";
                    }
                    if (!string.IsNullOrEmpty(packageDetailsData.ServiceSpecialServiceRequestName))
                    {
                        messageText += " Special Request: " + packageDetailsData.ServiceSpecialServiceRequestName + "<br>\r\n";
                    }

                    List <CrudeDefaultSystemSettingData> systemSettingDatas =
                        CrudeDefaultSystemSettingData.FetchWithFilter(
                            Guid.Empty,
                            DefaultSystemSettingRef.EMailURL,
                            string.Empty,
                            Guid.Empty,
                            DateTime.MinValue
                            );

                    CrudeDefaultSystemSettingData systemSettingData;
                    if (systemSettingDatas.Count > 0)
                    {
                        systemSettingData = systemSettingDatas[0];

                        messageText += "<br>\r\n";
                        messageText += "The package is not yet a booking, click ";
                        // http://localhost:1301/ServicePackagePromotionWithFilter/ServicePackagePromotionMakeBooking?servicePackagePromotionId=4417cd4e-e033-4644-b9fe-74ceec50d903
                        messageText += "<a href=\"" + systemSettingData.DefaultSystemSettingValue;
                        messageText += "/ServicePackagePromotionWithFilter/ServicePackagePromotionMakeBooking";
                        messageText += "?servicePackagePromotionId=" + promotionData.ServicePackagePromotionId.ToString();
                        messageText += "\">here to make it into one</a>. The flight will be the first available one, so fly to the airport :-|<br>\r\n";

                        // change package message
                        messageText += "If you for some reason do not agree with this wonderful package then <br>\r\n";
                        messageText += " it can be ";
                        messageText += "<a href=\"" + systemSettingData.DefaultSystemSettingValue;
                        messageText += "/GetServicePackageLive/ServicePackageEdit";
                        messageText += "?servicePackageId=" + packageData.ServicePackageId.ToString();
                        messageText += "\">changed here</a><br>\r\n";

                        // confirmed message
                        messageText += "<br>\r\n";
                        messageText += "The booking will be confirmed and a new mail message will arrive at this address confirming that fact.<br>\r\n";
                        messageText += "In the confirmation mail you can view the complete booking through web pages or a windows interface<br>\r\n";
                        messageText += "<br>\r\n";
                        messageText += "Thanks for booking through nor-port<br>\r\n";
                        messageText += "<br>\r\n";
                    }
                    messageText += "//nor-port<br>\r\n";

                    SmtpClient client = new SmtpClient();
                    client.Port                  = 587;
                    client.Host                  = "smtp.live.com"; // todo, system setting
                    client.EnableSsl             = true;
                    client.Timeout               = 10000;
                    client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;

                    // todo, system setting
                    client.Credentials =
                        new System.Net.NetworkCredential(
                            "emailLog",
                            "HU6767Ghvhvj"
                            );

                    MailMessage message =
                        new MailMessage(
                            "emailLog",
                            contactData.ContactMethodWay,
                            "Promotional Package : " + packageData.ServicePackageName,
                            messageText
                            );

                    message.IsBodyHtml = true;

                    message.BodyEncoding = UTF8Encoding.UTF8;
                    message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                    client.Send(message);

                    transaction.Commit();
                    log.PerformanceTimeStop();
                } catch (Exception ex) {
                    transaction.Rollback();
                    log.Error(ex);
                    throw ex;
                }
            }
        }