Пример #1
0
        private void CancelCommandExecuted()
        {
            _crmDataUnit.RevertChanges();

            if (_isEditMode)
            {
                FollowUp.Refresh();
            }
            else
            {
                FollowUp = null;
            }
        }
Пример #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();
            }
        }