private void SubmitCommandExecuted() { if (!_isEditMode) { Activity.ActivityType = ActivityType; Activity.Assignee = Assignee; if (AreEnquiriesVisible) { Activity.Activity.Enquiry = SelectedEnquiry.Enquiry; } else { _enquiry.Activities.Add(Activity); } _crmDataUnit.ActivitiesRepository.Add(Activity.Activity); } else { _activity.Activity.ActivityTypeID = ActivityType.ID; if (AreEnquiriesVisible) { Activity.Activity.Enquiry = SelectedEnquiry.Enquiry; } _activity.Activity.LastEditDate = DateTime.Now; _crmDataUnit.ActivitiesRepository.SetEntityModified(Activity.Activity); } if (AreEnquiriesVisible) { _crmDataUnit.SaveChanges(); } }
private void SubmitCommandExecuted() { if (!_isEditMode) { Campaign.CampaignType = CampaignType; _crmDataUnit.CampaignsRepository.Add(Campaign.Campaign); } else { _campaign.Campaign.CampaignTypeID = CampaignType.ID; _campaign.Campaign.LastEditDate = DateTime.Now; } _crmDataUnit.SaveChanges(); }
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(); }
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(); } }
private void SnoozeCommandExecute() { RaisePropertyChanged("DisableParentWindow"); var snoozeWindow = new SnoozeView(FollowUp); snoozeWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner; snoozeWindow.ShowDialog(); RaisePropertyChanged("EnableParentWindow"); if (snoozeWindow.DialogResult == null || snoozeWindow.DialogResult != true) { return; } var viewModel = snoozeWindow.DataContext as SnoozeViewModel; switch (viewModel.SnoozeTime) { case "5 mins": FollowUp.DateDue = DateTime.Now + TimeSpan.FromMinutes(5); break; case "10 mins": FollowUp.DateDue = DateTime.Now + TimeSpan.FromMinutes(10); break; case "30 mins": FollowUp.DateDue = DateTime.Now + TimeSpan.FromMinutes(30); break; case "1 Hour": FollowUp.DateDue = DateTime.Now + TimeSpan.FromHours(1); break; case "2 Hours": FollowUp.DateDue = DateTime.Now + TimeSpan.FromHours(2); break; case "1 Day": FollowUp.DateDue = DateTime.Now + TimeSpan.FromDays(1); break; case "7 Days": FollowUp.DateDue = DateTime.Now + TimeSpan.FromDays(7); break; } _crmDataUnit.SaveChanges(); var window = Application.Current.MainWindow; var mainViewModel = window.DataContext as MainWindowModel; var workspaceView = mainViewModel.WindowContent as WorkspaceView; var tile = workspaceView.RootTileView.MaximizedItem as Tile; if (tile.Name == "CRM") { var crmview = tile.Content as CRMView; var crmvm = crmview.DataContext as CRMViewModel; crmvm.FollowUps.ForEach(x => x.Refresh()); } }
public async void LoadData() { IsBusy = true; var types = await _crmDataUnit.EventTypesRepository.GetAllAsync(x => x.AllowEnquiry); EventTypes = new ObservableCollection <EventType>(types.OrderBy(x => x.Name)); var statuses = await _crmDataUnit.EventStatusesRepository.GetAllAsync(); EventStatuses = new ObservableCollection <EventStatus>(statuses.OrderBy(x => x.Name)); _eventNoteTypes = await _crmDataUnit.EventNoteTypesRepository.GetAllAsync(); var enquiries = await _crmDataUnit.EnquiriesRepository.GetLightEnquiriesAsync(); AlreadyCreatedEnquiries = new ObservableCollection <Enquiry>(enquiries); var users = await _crmDataUnit.UsersRepository.GetUsersAsync(); Users = new ObservableCollection <User>(users); OnLoadCurrentUser(); var campaigns = await _crmDataUnit.CampaignsRepository.GetAllAsync(x => x.IsActive); Campaigns = new ObservableCollection <Campaign>(campaigns); var enquiryStatuses = await _crmDataUnit.EnquiryStatusesRepository.GetAllAsync(x => x.IsEnabled); EnquiryStatuses = new ObservableCollection <EnquiryStatus>(enquiryStatuses.OrderBy(x => x.Status)); var methods = await _crmDataUnit.EnquiryReceiveMethodsRepository.GetAllAsync(); EnquiryReceivedMethods = new ObservableCollection <EnquiryReceiveMethod>(methods.OrderBy(x => x.ReceiveMethod)); if (_isEditMode) { var desiredEnquiry = await _crmDataUnit.EnquiriesRepository.GetUpdatedEnquiry(_enquiry.Enquiry.ID); if (desiredEnquiry.LockedUserID != null && desiredEnquiry.LockedUserID != AccessService.Current.User.ID) { // Okey, someone is editing event right now. var user = (await _crmDataUnit.UsersRepository.GetUsersAsync(x => x.ID == desiredEnquiry.LockedUserID)).FirstOrDefault(); IsLocked = true; LockedText = string.Format("{0} is locked by {1} {2}. Please wait till user makes changes", _enquiry.Name, user.FirstName, user.LastName); return; } // Lock event _enquiry.Enquiry.LockedUserID = AccessService.Current.User.ID; await _crmDataUnit.SaveChanges(); // Check if we have new changes if (desiredEnquiry != null && desiredEnquiry.LastEditDate != null && Enquiry.LoadedTime < desiredEnquiry.LastEditDate) { Enquiry = new EnquiryModel(desiredEnquiry); _forceRefreshEnquiryData = true; } LoadEnquiryData(_enquiry); EventType = _enquiry.EventType; AssignedToUser = _enquiry.AssignedToUser; LoggedUser = _enquiry.LoggedUser; Campaign = _enquiry.Campaign; EnquiryStatus = _enquiry.EnquiryStatus; ReceivedMethod = _enquiry.ReceivedMethod; } else { SetEnquiryStatus(); } IsBusy = false; }