Example #1
0
        private void EditEnquiryCommandExecute(EnquiryModel item)
        {
            RaisePropertyChanged("DisableParentWindow");
            var currentEnquiry = item.Clone();

            item.Refresh();
            var window = new NewEnquiryView(item);

            window.ShowDialog();
            RaisePropertyChanged("EnableParentWindow");
            if (window.DialogResult == null || window.DialogResult != true)
            {
                item.Refresh();
                return;
            }
            item.Refresh();
            var  viewModel        = window.DataContext as NewEnquiryViewModel;
            bool activityChanged  = viewModel.ActivityChanged;
            bool followUpsChanged = viewModel.FoolowUpsChanged;

            //  var diff = LoggingService.FindDifference(currentEnquiry, item, out activityChanged, out followUpsChanged);
            //  ProcessUpdates(item, diff);

            if (activityChanged)
            {
                _allActivities.RemoveAll(x => x.Activity.EnquiryID == item.Enquiry.ID);

                foreach (var activity in window.ViewModel.Enquiry.Activities)
                {
                    _allActivities.Add(activity);
                }
                Activities = new ObservableCollection <ActivityModel>(_allActivities);
            }
            else
            {
                Activities.ForEach(x => x.Refresh());
            }
            if (followUpsChanged)
            {
                _allFollowUps.RemoveAll(
                    x => x.FollowUp.EnquiryID != null && (Guid)x.FollowUp.EnquiryID == item.Enquiry.ID);

                _allFollowUps.RemoveAll(x => x.TakenByUser == null);

                foreach (var followUp in window.ViewModel.Enquiry.FollowUps)
                {
                    SetFollowUpPriority(followUp);
                    _allFollowUps.Add(followUp);
                }

                FollowUps = new ObservableCollection <FollowUpModel>(_allFollowUps);
            }
            else
            {
                FollowUps.ForEach(x => x.Refresh());
            }
        }
Example #2
0
        private async void SubmitCommandExecuted()
        {
            if (!_isEditMode)
            {
                FollowUp.TakenByUser    = TakenByUser;
                FollowUp.AssignedToUser = AssignedToUser;
                if (AreEnquiriesVisible)
                {
                    FollowUp.FollowUp.Enquiry = SelectedEnquiry.Enquiry;
                }
                else if (!_isToDo)
                {
                    _enquiry.FollowUps.Add(FollowUp);
                }

                _crmDataUnit.FollowUpsRepository.Add(FollowUp.FollowUp);

                if (!_isToDo)
                {
                    var primaryContact = FollowUp.FollowUp.Enquiry != null ? FollowUp.FollowUp.Enquiry.Contact == null ? String.Empty : "Primary Contact: " + FollowUp.FollowUp.Enquiry.Contact.FirstName + " "
                                         + FollowUp.FollowUp.Enquiry.Contact.LastName : String.Empty;

                    var msg = "Follow-Up" + "\n" + "Created by " + FollowUp.TakenByUser.FirstName + " " +
                              FollowUp.TakenByUser.LastName + " at " + DateTime.Now + "\n" +
                              "Event Name: " + FollowUp.EnquiryName + "\n" + primaryContact + "\n" + FollowUp.WhatToDo;
                    var email = new CorrespondenceModel(new Corresponcence()
                    {
                        ID          = Guid.NewGuid(),
                        Date        = DateTime.Now,
                        FromAddress = FollowUp.TakenByUser.EmailAddress,
                        ToAddress   = FollowUp.AssignedToUser.EmailAddress,
                        Subject     = "Follow-Up",
                        Message     = msg,
                    });

                    await EmailService.SendEmail(email, null, null);

                    if (AreEnquiriesVisible)
                    {
                        _originalEnquiry = SelectedEnquiry.Clone();
                        _selectedEnquiry.FollowUps.Add(FollowUp);
                        var diff = LoggingService.FindDifference(_originalEnquiry, SelectedEnquiry, out ActivityChanged, out FoolowUpsChanged);
                        if (!SelectedEnquiry.EnquiryUpdates.Any())
                        {
                            var updates = await _crmDataUnit.EnquiryUpdatesRepository.GetAllAsync(x => x.EnquiryID == SelectedEnquiry.Enquiry.ID);

                            SelectedEnquiry.EnquiryUpdates = new ObservableCollection <EnquiryUpdate>(updates.OrderByDescending(x => x.Date));
                        }

                        ProcessUpdates(_selectedEnquiry, diff);
                        if (!_addToActivity)
                        {
                            await _crmDataUnit.SaveChanges();
                        }
                    }
                }
            }
            else
            {
                _followUp.AssignedToUser         = AssignedToUser;
                _followUp.FollowUp.UserDueToDoID = AssignedToUser.ID;
                _followUp.FollowUp.LastEditDate  = DateTime.Now;
                if (AreEnquiriesVisible)
                {
                    if (_originalEnquiry.Enquiry.ID != _selectedEnquiry.Enquiry.ID)
                    {
                        _originalEnquiry = _selectedEnquiry.Clone();
                    }

                    FollowUp.FollowUp.Enquiry = SelectedEnquiry.Enquiry;
                    SelectedEnquiry.FollowUps.Where(x => x.FollowUp == _followUp.FollowUp).FirstOrDefault().AssignedToUser = AssignedToUser;
                    var diff = LoggingService.FindDifference(_originalEnquiry, SelectedEnquiry, out ActivityChanged, out FoolowUpsChanged);
                    if (!SelectedEnquiry.EnquiryUpdates.Any())
                    {
                        var updates = await _crmDataUnit.EnquiryUpdatesRepository.GetAllAsync(x => x.EnquiryID == SelectedEnquiry.Enquiry.ID);

                        SelectedEnquiry.EnquiryUpdates = new ObservableCollection <EnquiryUpdate>(updates.OrderByDescending(x => x.Date));
                    }
                    ProcessUpdates(_selectedEnquiry, diff);

                    if (!_addToActivity)
                    {
                        await _crmDataUnit.SaveChanges();
                    }
                }
                else
                {
                    _crmDataUnit.FollowUpsRepository.SetEntityModified(_followUp.FollowUp);
                }
                FollowUp.Refresh();
            }
        }
Example #3
0
        private void EditEnquiryCommandExecute(EnquiryModel item)
        {

            RaisePropertyChanged("DisableParentWindow");
            var currentEnquiry = item.Clone();
            item.Refresh();
            var window = new NewEnquiryView(item);
            window.ShowDialog();
            RaisePropertyChanged("EnableParentWindow");
            if (window.DialogResult == null || window.DialogResult != true)
            {
                item.Refresh();
                return;
            }
            item.Refresh();
            var viewModel = window.DataContext as NewEnquiryViewModel;
            bool activityChanged = viewModel.ActivityChanged;
            bool followUpsChanged = viewModel.FoolowUpsChanged;

            //  var diff = LoggingService.FindDifference(currentEnquiry, item, out activityChanged, out followUpsChanged);
            //  ProcessUpdates(item, diff);

            if (activityChanged)
            {
                _allActivities.RemoveAll(x => x.Activity.EnquiryID == item.Enquiry.ID);

                foreach (var activity in window.ViewModel.Enquiry.Activities)
                {
                    _allActivities.Add(activity);
                }
                Activities = new ObservableCollection<ActivityModel>(_allActivities);
            }
            else
            {
                Activities.ForEach(x => x.Refresh());
            }
            if (followUpsChanged)
            {
                _allFollowUps.RemoveAll(
                    x => x.FollowUp.EnquiryID != null && (Guid)x.FollowUp.EnquiryID == item.Enquiry.ID);

                _allFollowUps.RemoveAll(x => x.TakenByUser == null);

                foreach (var followUp in window.ViewModel.Enquiry.FollowUps)
                {
                    SetFollowUpPriority(followUp);
                    _allFollowUps.Add(followUp);
                }

                FollowUps = new ObservableCollection<FollowUpModel>(_allFollowUps);
            }
            else
            {
                FollowUps.ForEach(x => x.Refresh());
            }
        }
Example #4
0
        private async void LoadEnquiryData(EnquiryModel model)
        {
            // if (!model.FollowUps.Any())
            {
                if (_forceRefreshEnquiryData) _crmDataUnit.FollowUpsRepository.Refresh();
                var followUps = await _crmDataUnit.FollowUpsRepository.GetAllAsync(x => x.EnquiryID == model.Enquiry.ID);
                model.FollowUps = new ObservableCollection<FollowUpModel>(followUps.Select(x => new FollowUpModel(x)));
            }
            //if (!model.Activities.Any())
            {
                if (_forceRefreshEnquiryData) _crmDataUnit.ActivitiesRepository.Refresh();
                var activities = await _crmDataUnit.ActivitiesRepository.GetAllAsync(x => x.EnquiryID == model.Enquiry.ID);
                model.Activities = new ObservableCollection<ActivityModel>(activities.OrderByDescending(p => p.Date).Select(x => new ActivityModel(x)));
            }

            if (!model.EnquiryUpdates.Any())
            {
                var updates = await _crmDataUnit.EnquiryUpdatesRepository.GetAllAsync(x => x.EnquiryID == model.Enquiry.ID);
                model.EnquiryUpdates = new ObservableCollection<EnquiryUpdate>(updates.OrderByDescending(x => x.Date));
            }

            if (!model.EnquiryNotes.Any())
            {
                var notes = await _crmDataUnit.EnquiryNotesRepository.GetAllAsync(x => x.EnquiryID == model.Enquiry.ID);
                model.EnquiryNotes = new ObservableCollection<EnquiryNoteModel>(notes.Select(x => new EnquiryNoteModel(x)));
            }

            if (!model.Correspondences.Any())
            {
                if (_forceRefreshEnquiryData) _crmDataUnit.CorresponcencesRepository.Refresh();
                var correspondence = await _crmDataUnit.CorresponcencesRepository.GetAllAsync(x => x.OwnerID == model.Enquiry.ID);
                model.Correspondences = new ObservableCollection<CorrespondenceModel>(
                    correspondence.OrderByDescending(x => x.Date).Select(x => new CorrespondenceModel(x)));

                var documents = await _crmDataUnit.DocumentsRepository.GetAllAsync(x => x.IsCommon);

                foreach (var enquiryCorresponcence in model.Correspondences)
                {
                    foreach (var cd in enquiryCorresponcence.Correspondence.CorrespondenceDocuments)
                    {
                        enquiryCorresponcence.Documents.Add(documents.First(x => x.ID == cd.DocumentID));
                    }
                }
            }

            _originalEnquiry = model.Clone();

            //  IsBusy = false;
        }
Example #5
0
        private async void LoadEnquiryData(EnquiryModel model)
        {
            // if (!model.FollowUps.Any())
            {
                if (_forceRefreshEnquiryData)
                {
                    _crmDataUnit.FollowUpsRepository.Refresh();
                }
                var followUps = await _crmDataUnit.FollowUpsRepository.GetAllAsync(x => x.EnquiryID == model.Enquiry.ID);

                model.FollowUps = new ObservableCollection <FollowUpModel>(followUps.Select(x => new FollowUpModel(x)));
            }
            //if (!model.Activities.Any())
            {
                if (_forceRefreshEnquiryData)
                {
                    _crmDataUnit.ActivitiesRepository.Refresh();
                }
                var activities = await _crmDataUnit.ActivitiesRepository.GetAllAsync(x => x.EnquiryID == model.Enquiry.ID);

                model.Activities = new ObservableCollection <ActivityModel>(activities.OrderByDescending(p => p.Date).Select(x => new ActivityModel(x)));
            }

            if (!model.EnquiryUpdates.Any())
            {
                var updates = await _crmDataUnit.EnquiryUpdatesRepository.GetAllAsync(x => x.EnquiryID == model.Enquiry.ID);

                model.EnquiryUpdates = new ObservableCollection <EnquiryUpdate>(updates.OrderByDescending(x => x.Date));
            }

            if (!model.EnquiryNotes.Any())
            {
                var notes = await _crmDataUnit.EnquiryNotesRepository.GetAllAsync(x => x.EnquiryID == model.Enquiry.ID);

                model.EnquiryNotes = new ObservableCollection <EnquiryNoteModel>(notes.Select(x => new EnquiryNoteModel(x)));
            }

            if (!model.Correspondences.Any())
            {
                if (_forceRefreshEnquiryData)
                {
                    _crmDataUnit.CorresponcencesRepository.Refresh();
                }
                var correspondence = await _crmDataUnit.CorresponcencesRepository.GetAllAsync(x => x.OwnerID == model.Enquiry.ID);

                model.Correspondences = new ObservableCollection <CorrespondenceModel>(
                    correspondence.OrderByDescending(x => x.Date).Select(x => new CorrespondenceModel(x)));

                var documents = await _crmDataUnit.DocumentsRepository.GetAllAsync(x => x.IsCommon);

                foreach (var enquiryCorresponcence in model.Correspondences)
                {
                    foreach (var cd in enquiryCorresponcence.Correspondence.CorrespondenceDocuments)
                    {
                        enquiryCorresponcence.Documents.Add(documents.First(x => x.ID == cd.DocumentID));
                    }
                }
            }

            _originalEnquiry = model.Clone();

            //  IsBusy = false;
        }