Repository navigation
Expand file tree
/
Copy pathumTeaCommerce.cs
More file actions
191 lines (153 loc) · 7.59 KB
/
Copy pathumTeaCommerce.cs
File metadata and controls
191 lines (153 loc) · 7.59 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using lecoati.uMobile;
using lecoati.uMobile.umCore;
using lecoati.uMobile.umComponents;
using TeaCommerce.Umbraco.Web;
using TeaCommerce.Api.Models;
using System.Xml.Linq;
using lecoati.uMobile.umHelpers;
using System.Net;
using System.Collections.Specialized;
using System.Web.Helpers;
using System.Text;
namespace lecoati.uMobile.Extensions
{
/// <summary>
/// Summary description for umTeaCommerce
/// </summary>
[umClass(Category = "Tea Commerce", Icon = GenericIcon.Money)]
public class umTeaCommerce : uMobile
{
[umMethod]
public static string Orders()
{
List list = new List();
Store currentStore = TC.GetStore(1);
XElement allOrders = TC.GetAllFinalizedOrdersAsXml(1);
var ordersList = (from order in allOrders.Elements("order")
orderby DateTime.Parse(order.Attribute("dateCreated").Value)
descending
select order.Attribute("id").Value);
if (ordersList.Any())
{
foreach (var orderId in ordersList)
{
Order order = TC.GetOrder(1, new Guid(orderId));
list.AddListItem(new ListItem(order.OrderNumber + "<b style='float: right;'>" + order.TotalPrice.Formatted + "</b>",
subtitle: "<span style='float: right;'>" + order.Properties.Get("email") + "</span>" + TCExtensions.GetOrderStatus(order.StoreId, order.OrderStatusId).Name.ToString() + "<br /><span style='float: right;'>" + order.Properties.Get("city") + "</span>" + order.DateCreated,
icon: GenericIcon.ShoppingCart,
action: new Call("OrderInfo", new string[] { order.StoreId.ToString(), order.Id.ToString() })
));
}
}
return list.UmGo();
}
[umMethod(Visible = false)]
public static string OrderInfo(string storeId, string orderId)
{
Order order = TC.GetOrder(Convert.ToInt32(storeId), new Guid(orderId));
Store store = TC.GetStore(Convert.ToInt32(storeId));
List orderList = new List();
string statusName = TCExtensions.GetOrderStatus(order.StoreId, order.OrderStatusId).Name.ToString();
//bool positiveStatus = PositiveWord(statusName);
//if (positiveStatus)
//{
// statusName = "<b style='color: green;'>" + statusName + "</b>";
//}
//else
//{
// statusName = "<b style='color: red;'>" + statusName + "</b>";
//}
ListItem detailsRow = new ListItem(
title:
order.OrderNumber + "<br />",
subtitle:
"City: " + order.Properties.Get("city").ToString() + "<br />" +
"Total Price: " + order.TotalPrice.Formatted + "<br />" +
"Date Created: " + order.DateCreated + "<br /><br />" +
"<span style='font-size: 1.3em; margin-top: 20px;'>" + "Email: <a href='mailto:" + order.Properties.Get("email").ToString() + "'>" + order.Properties.Get("email").ToString() + "</a></span><br />" +
"<span style='font-size: 1.3em;'>" + "Phone: " + order.Properties.Get("phone").ToString() + "</span>" +
"<br />" +
"<span style='font-size: 1.3em;'>Status: " + statusName + "</span>"
);
orderList.AddListItem(detailsRow);
orderList.AddListItem(new ListItem(
title: "Change Order Status",
icon: GenericIcon.Tag,
action: new Call("ChangeOrderStatus", new string[] { storeId, orderId })
));
//This is not working at the moment because I was not able to find out the way to get the emailtemplates from the API
//orderList.AddListItem(new ListItem(
// title: "Send Email",
// icon: GenericIcon.EnvelopeAlt
//));
return orderList.UmGo(order.OrderNumber);
}
[umMethod(Title = "Change Order Status", Visible = false)]
public static string ChangeOrderStatus(string storeId, string orderId)
{
Order order = TC.GetOrder(Convert.ToInt32(storeId), new Guid(orderId));
Store store = TC.GetStore(Convert.ToInt32(storeId));
Form orderForm = new Form();
FormFieldset statusFieldset = new FormFieldset();
orderForm.AddFieldset(statusFieldset);
SelectField status = new SelectField("status", "Status", order.OrderStatusId.ToString());
foreach (KeyValuePair<int, OrderStatus> orderStatus in TCExtensions.GetOrderStatuses()) {
status.AddOption(orderStatus.Value.Name, orderStatus.Key.ToString());
}
statusFieldset.AddFormItem(status);
orderForm.primary = new Button("Save", new Call("OrderSave", new string[] { order.StoreId.ToString(), order.Id.ToString() }));
return orderForm.UmGo(order.OrderNumber);
}
[umMethod(Title = "Save", Visible = false)]
public static string OrderSave(string storeId, string orderId)
{
Order order = TC.GetOrder(Convert.ToInt32(storeId), new Guid(orderId));
Store store = TC.GetStore(Convert.ToInt32(storeId));
var status = Utils.GetPostParameter("status");
order.OrderStatusId = Convert.ToInt32(status);
try
{
order.Save();
}
catch (Exception ex)
{
return (new MessageBox("Order couldn't be saved. Exception ocurred: <br />" + ex.Message + "<br/>" + ex.InnerException)).UmGo();
}
return (new MessageBox("Order edited successfully")).UmGo();
}
//Not working. TODO: Find a way to get the TeaCommerce email templates from the API and send it to the costumers.
[umMethod(Title = "Send Email", Visible = false)]
public static string SendEmail(string storeId, string orderId)
{
Order order = TC.GetOrder(Convert.ToInt32(storeId), new Guid(orderId));
Store store = TC.GetStore(Convert.ToInt32(storeId));
TeaCommerce.Umbraco.Application.Trees.Tasks.EmailTemplateTask emailTask = new TeaCommerce.Umbraco.Application.Trees.Tasks.EmailTemplateTask();
emailTask.Alias = "confirmationEmail";
emailTask.TypeID = 1;
long? templateId = store.ConfirmationEmailTemplateId;
if (emailTask.Save()) {
return (new MessageBox("Email sended.")).UmGo();
};
return (new MessageBox("Error on sending email")).UmGo();
}
public static bool PositiveWord(string text) {
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data["text"] = text;
data["service"] = "sentiment_news";
byte[] responseArray = wb.UploadValues("http://nlptools.atrilla.net/api/", "POST", data);
string response = Encoding.ASCII.GetString(responseArray);
var decodedResponse = Json.Decode(response);
decimal NEG = decodedResponse.likelihood.NEG;
decimal POS = decodedResponse.likelihood.POS;
decimal NEU = decodedResponse.likelihood.NEU;
return (POS > NEG);
}
}
}
}