Exemplo n.º 1
0
        private void SubmitEventCommandExecuted()
        {
            if (!_isEditMode)
            {
                Enquiry.LoggedUser     = LoggedUser;
                Enquiry.EnquiryStatus  = EnquiryStatus;
                Enquiry.AssignedToUser = AssignedToUser;
                Enquiry.ReceivedMethod = ReceivedMethod;
                Enquiry.EventType      = EventType;
                Enquiry.EventStatus    = EventStatus;
                Enquiry.Campaign       = Campaign;

                if (!_enquiry.Enquiry.Activities.Any() && !_enquiry.Enquiry.FollowUps.Any())
                {
                    _crmDataUnit.EnquiriesRepository.Add(_enquiry.Enquiry);
                }

                var update = new EnquiryUpdate()
                {
                    ID        = Guid.NewGuid(),
                    EnquiryID = _enquiry.Enquiry.ID,
                    Date      = DateTime.Now,
                    UserID    = AccessService.Current.User.ID,
                    Message   = string.Format("Enquiry {0} was created", _enquiry.Name)
                };

                _enquiry.EnquiryUpdates.Add(update);
                _crmDataUnit.EnquiryUpdatesRepository.Add(update);
            }
            else
            {
                _enquiry.Enquiry.TakenByID        = LoggedUser.ID;
                _enquiry.Enquiry.EnquiryStatusID  = EnquiryStatus.ID;
                _enquiry.Enquiry.AssignedToID     = AssignedToUser.ID;
                _enquiry.Enquiry.ReceivedMethodID = ReceivedMethod.ID;
                _enquiry.Enquiry.EventTypeID      = EventType.ID;
                _enquiry.Enquiry.Campaign         = Campaign;
                _enquiry.AssignedToUser           = AssignedToUser;
                _enquiry.EnquiryStatus            = EnquiryStatus;
                _enquiry.ReceivedMethod           = ReceivedMethod;
                _enquiry.EventType = EventType;

                var diff = LoggingService.FindDifference(_originalEnquiry, _enquiry, out ActivityChanged, out FoolowUpsChanged);
                ProcessUpdates(_enquiry, diff);

                _enquiry.Enquiry.LastEditDate = DateTime.Now;
                _enquiry.Enquiry.LockedUserID = null;
            }
            _crmDataUnit.SaveChanges();

            //if (_isEditMode)
            //{
            //    var diff = LoggingService.FindDifference(_originalEnquiry, _enquiry, out ActivityChanged, out FoolowUpsChanged);
            //    ProcessUpdates(_enquiry, diff);
            //}

            PopupService.ShowMessage(Properties.Resources.MESSAGE_NEW_EVENT_ADDED, MessageType.Successful);
        }
Exemplo n.º 2
0
        private void ProcessUpdates(EnquiryModel model, IEnumerable <string> diff)
        {
            diff.ForEach(difference =>
            {
                var update = new EnquiryUpdate()
                {
                    ID        = Guid.NewGuid(),
                    Date      = DateTime.Now,
                    EnquiryID = model.Enquiry.ID,
                    UserID    = AccessService.Current.User.ID,
                    Message   = difference
                };

                model.EnquiryUpdates.Add(update);
                _crmDataUnit.EnquiryUpdatesRepository.Add(update);
            });

            model.EnquiryUpdates = new ObservableCollection <EnquiryUpdate>(model.EnquiryUpdates.OrderByDescending(x => x.Date));
            //    _crmDataUnit.SaveChanges();
        }
Exemplo n.º 3
0
        protected async void OnClick(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
            {
                Session["CheckRefresh"] = Server.UrlDecode(DateTime.Now.ToString());
            }
            else
            {
                ClearAll();
                return;
            }

            DefaultSettingsForEnquiry defaultSettings =
                (await _webEnquiryDataUnit.DefaultSettingsForEnquiriesRepository.GetAllAsync()).First();

            var user = (await _webEnquiryDataUnit.UsersRepository.GetUsersAsync(x => x.ID == defaultSettings.UserID)).FirstOrDefault();

            var emailSettings = (await _webEnquiryDataUnit.EmailSettingsRepository.GetAllAsync()).First();

            var receivedMethods =
                new List <EnquiryReceiveMethod>(await _webEnquiryDataUnit.EnquiryReceiveMethodsRepository.GetAllAsync());
            var eventStatuses = new List <EventStatus>(await _webEnquiryDataUnit.EventStatusesRepository.GetAllAsync());

            var      places = String.IsNullOrEmpty(txtNum.Text) ? 0 : Convert.ToInt32(txtNum.Text);
            var      name   = String.IsNullOrEmpty(txtName.Text) ? "Web Enquiry" : txtName.Text;
            DateTime?date;

            if (!String.IsNullOrEmpty(txtDate.Text))
            {
                date = DateTime.ParseExact(txtDate.Text, "dd/MM/yyyy", CultureInfo.CurrentCulture);
            }
            else
            {
                date = null;
            }

            var contact = new Contact()
            {
                ID        = Guid.NewGuid(),
                FirstName = txtFirstName.Text,
                LastName  = txtLastName.Text,
                Phone1    = txtMobilePhone.Text,
                Email     = txtEmail.Text
            };

            _webEnquiryDataUnit.ContactsRepository.Add(contact);

            var enquiry = new Enquiry()
            {
                ID               = Guid.NewGuid(),
                Date             = date,
                Name             = name,
                EventTypeID      = Guid.Parse(EventTypesDropDown.SelectedValue),
                EventStatusID    = eventStatuses.First(x => x.Name.Equals("Enquiry")).ID,
                Places           = places,
                ContactID        = contact.ID,
                EnquiryStatusID  = defaultSettings.EnquiryStatusID,
                AssignedToID     = defaultSettings.UserID,
                ReceivedMethodID = receivedMethods.First(x => x.ReceiveMethod == "web site").ID,
                TakenByID        = defaultSettings.UserID,
                CreationDate     = DateTime.Now
            };

            _webEnquiryDataUnit.EnquiriesRepository.Add(enquiry);

            if (!String.IsNullOrEmpty(txtEventDetails.Text))
            {
                var note = new EnquiryNote()
                {
                    ID        = Guid.NewGuid(),
                    EnquiryID = enquiry.ID,
                    Note      = txtEventDetails.Text,
                    Date      = DateTime.Now,
                    UserID    = defaultSettings.UserID,
                };

                _webEnquiryDataUnit.EnquiryNotesRepository.Add(note);
            }

            var update = new EnquiryUpdate()
            {
                ID        = Guid.NewGuid(),
                EnquiryID = enquiry.ID,
                Date      = DateTime.Now,
                UserID    = defaultSettings.UserID,
                Message   = string.Format("Enquiry {0} was created", enquiry.Name)
            };

            _webEnquiryDataUnit.EnquiryUpdatesRepository.Add(update);

            _webEnquiryDataUnit.SaveChanges();

            Alert("Enquiry was successfully sent", Page);

            try
            {
                using (var smtpClient = new SmtpClient(emailSettings.Server))
                {
                    smtpClient.Port                  = 587;
                    smtpClient.EnableSsl             = emailSettings.EnableSSL;
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials           = new NetworkCredential(emailSettings.Username, emailSettings.Password);

                    using (var message = new MailMessage())
                    {
                        message.From            = new MailAddress(defaultSettings.FromAddress);
                        message.IsBodyHtml      = true;
                        message.Subject         = "Web Enquiry";
                        message.SubjectEncoding = Encoding.UTF8;
                        message.Body            = "Enquiry " + enquiry.Name + " has been received.";
                        message.BodyEncoding    = Encoding.UTF8;
                        message.To.Add(user.EmailAddress);

                        smtpClient.Send(message);
                    }
                }
            }
            catch (SmtpException)
            {
                Alert("Couldn't send email", Page);
            }

            ClearAll();
        }
Exemplo n.º 4
0
        private async void SubmitCommandExecuted()
        {
            IsBusy = true;

            if (_isResend)
            {
                var mail = GetCorrespondence();
                mail.CCAddress           = Correspondence.CCAddress;
                mail.Date                = DateTime.Now;
                mail.FromAddress         = Correspondence.FromAddress;
                mail.ToAddress           = Correspondence.ToAddress;
                mail.Message             = Correspondence.Message;
                mail.SendMailToCcAddress = Correspondence.SendMailToCcAddress;
                mail.Subject             = Correspondence.Subject;
                mail.EmailType           = Correspondence.EmailType;
                mail.Correspondence.CorresponcenceTypeID = Correspondence.Correspondence.CorresponcenceTypeID;
                mail.ContactTo = Correspondence.ContactTo;

                Correspondence = mail;
            }
            else
            {
                var type = _corresponcenceTypes.FirstOrDefault(x => x.Type == "Event");
                Correspondence.CorresponcenceType = type;
                Correspondence.Message            = Correspondence.Message;
            }

            var onCompletedAction = new Action(() =>
            {
                if (Correspondence.SendMailToCcAddress)
                {
                    AddCCContacts();
                }

                foreach (var document in Correspondence.Documents)
                {
                    var correspondenceDocument = new CorrespondenceDocument()
                    {
                        ID = Guid.NewGuid(),
                        CorrespondenceID = Correspondence.Correspondence.ID,
                        DocumentID       = document.ID
                    };

                    _crmDataUnit.CorrespondenceDocumentsRepository.Add(correspondenceDocument);
                }

                // add entry into update log
                var update = new EnquiryUpdate()
                {
                    ID        = Guid.NewGuid(),
                    EnquiryID = _enquiry.Enquiry.ID,
                    Date      = DateTime.Now,
                    Message   = string.Format("Email was sent to {0}", _correspondence.ToAddress),
                    UserID    = AccessService.Current.User.ID
                };

                _enquiry.EnquiryUpdates.Insert(0, update);
                _crmDataUnit.EnquiryUpdatesRepository.Add(update);

                _enquiry.Correspondences.Insert(0, Correspondence);
                _crmDataUnit.CorresponcencesRepository.Add(Correspondence.Correspondence);
            });

            bool success = await EmailService.SendEmail(Correspondence, onCompletedAction, MainEmailTemplate.MailTemplate.Template);

            IsBusy = false;
            if (success)
            {
                RaisePropertyChanged("CloseDialog");
            }
        }