-
Notifications
You must be signed in to change notification settings - Fork 1
/
CRActivityMaintExtension.cs
88 lines (69 loc) · 3.07 KB
/
CRActivityMaintExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using PX.Api;
using PX.Data;
using PX.Objects.CR;
using PX.Objects.EP;
using PX.SM;
using PX.SmsProvider;
using PX.SmsProvider.SM.DAC;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Autofac;
using Newtonsoft.Json;
using PX.SmsProvider.SM;
namespace TeamBeta2021
{
public class CRActivityMaintExtension : PXGraphExtension<CRActivityMaint>
{
public PXSelect<SmsPluginParameter, Where<SmsPluginParameter.pluginName, Equal<Current<SmsPlugin.name>>>,
OrderBy<Asc<SmsPluginParameter.lineNumber>>> Details;
public PXSetup<TBetaCred> Creds;
[InjectDependency] public IReadOnlyDictionary<string, ISmsProviderFactory> ProviderFactories { get; set; }
public PXAction<CRActivity> tBetaInitiate;
[PXButton]
[PXUIField(DisplayName = "Start Video", MapEnableRights = PXCacheRights.Select,
MapViewRights = PXCacheRights.Select)]
public virtual IEnumerable TBetaInitiate(PXAdapter adapter)
{
Base.Actions.PressSave();
CRCase myCase =
PXSelect<CRCase, Where<CRCase.noteID, Equal<Required<CRCase.noteID>>>>.Select(Base,
Base.CurrentActivity.Current.RefNoteID);
Contact mycontact =
PXSelect<Contact, Where<Contact.contactID, Equal<Required<Contact.contactID>>>>.Select(Base,
myCase.ContactID ?? 0);
if (mycontact == null)
throw new PXException("No Contact!!!");
//PXDatabase.SelectDataFields<>();
string apikey = Creds.Current.Apikey;
var srurl = "https://hackathon.acumatica.com/Beta/Frames/vnr.html?key=" + apikey + "&nid=" + Base.CurrentActivity.Current.NoteID.ToString();
var request = new SendMessageRequest()
{
RecepientPhoneNbr = (mycontact.Phone1 == null) ? mycontact.Phone2 : mycontact.Phone1,
RecepientSMSMessage = ""+ srurl
};
request.RecepientPhoneNbr = request.RecepientPhoneNbr.Replace("(", "");
request.RecepientPhoneNbr = request.RecepientPhoneNbr.Replace(")", "");
PXTrace.WriteInformation(mycontact.DisplayName + " " + request.RecepientPhoneNbr);
try
{
Guid guid = Guid.Parse("A18E155A-7CBF-E911-8173-DAB1842B9396");
var pluginParameters = SmsPluginMaint.Def[guid];
var plugin = ProviderFactories[pluginParameters.typeName].Create(pluginParameters.parameters);
plugin.SendMessageAsync(request, CancellationToken.None).Wait();
}
catch (Exception ex)
{
throw ex;
}
var surl = "https://hackathon.acumatica.com/Beta/Frames/vnl.html?key=" + apikey + "&nid=" +
Base.CurrentActivity.Current.NoteID.ToString();
throw new PXRedirectToUrlException(surl, PXBaseRedirectException.WindowMode.Same,
string.Empty);
}
}
}