ChrisCompleteCodeTrunk
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
|
using ActionTireCo.Crm.Model.Database;
using ActionTireCo.Crm.Model.Session;
using ActionTireCo.Crm.Model.View;
using Microsoft.Exchange.WebServices.Data;
using System;
using System.Collections.Generic;
using System.DirectoryServices.Protocols;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
namespace ActionTireCo.Crm.Controllers
{
public class AppointmentController : Controller
{
[HttpPost]
public ActionResult Add(AppointmentModel appointmentModel)
{
try
{
UserObject userObject = (UserObject)Session["UserObject"];
ActionTireCoCrmContext context = new ActionTireCoCrmContext();
User user = (from u in context.User where u.Adname.ToUpper() == userObject.UserName.ToUpper() select u).SingleOrDefault<User>();
Customer customer = (from c in context.Customer where c.Id == appointmentModel.CustomerId select c).SingleOrDefault<Customer>();
/*
LdapConnection lcon = new LdapConnection(new LdapDirectoryIdentifier("ACTIONDC1", false, false));
NetworkCredential nc = new NetworkCredential(userObject.UserName, userObject.Password, "ATC");
lcon.Credential = nc;
lcon.AuthType = AuthType.Negotiate;
lcon.Bind(nc);
*/
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url = new Uri("https://webmail.actiontireco.com/EWS/Exchange.asmx");
service.Credentials = new WebCredentials(userObject.UserName, userObject.Password);
DateTime date = appointmentModel.AppointmentDate;
TimeSpan time;
if (appointmentModel.StartTime.IndexOf("AM") >= 0)
{
string[] timesplit = appointmentModel.StartTime.Split(':');
time = new TimeSpan(Int32.Parse(timesplit[0]),Int32.Parse(timesplit[1].Replace("AM",String.Empty).Replace("PM",String.Empty)),0);
}
else
{
string[] timesplit = appointmentModel.StartTime.Split(':');
time = new TimeSpan(Int32.Parse(timesplit[0]) * 12, Int32.Parse(timesplit[1].Replace("AM", String.Empty).Replace("PM", String.Empty)), 0);
}
DateTime combined = date.Add(time);
Appointment appointment = new Appointment(service);
// Set the properties on the appointment object to create the appointment.
appointment.Subject = customer.Name;
appointment.Start = date;
appointment.End = appointment.Start.AddHours(1);
appointment.ReminderDueBy = DateTime.Now;
// Save the appointment to your calendar.
appointment.Save(SendInvitationsMode.SendToNone);
// Verify that the appointment was created by using the appointment's item ID.
Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject));
return RedirectToAction("Edit", "Customer", new { @customerId = appointmentModel.CustomerId });
}
catch(Exception ex)
{
return RedirectToAction("Edit", "Customer", new { @customerId = appointmentModel.CustomerId, @errorMessage = ex.Message });
}
}
}
}
|
Revision |
Author |
Commited |
Message |
1
|
BBDSCHRIS
|
Wed 22 Aug, 2018 20:08:03 +0000 |
|