Я хочу использовать fullcalendar в моем проекте MVC. Мой проект включает EWS API Exchange
. Я хочу получить встречу в обмен. Также я использую аутентификацию рекламы: Настройка ASP.NET MVC для аутентификации по AD
Я создал пользовательскую модель:
public class AccountModels
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
Тогда AccountController:
public ActionResult Login()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(AccountModels model, string returnURL)
{
if (!this.ModelState.IsValid)
{
return this.View(model);
}
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (this.Url.IsLocalUrl(returnURL) && returnURL.Length > 1 && returnURL.StartsWith("/")
&& !returnURL.StartsWith("//") && !returnURL.StartsWith("/\\"))
{
return this.Redirect(returnURL);
}
return this.RedirectToAction("Index", "Home", model);
}
this.ModelState.AddModelError(string.Empty, "The username or password is incorrect");
return this.View(model);
}
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
return this.RedirectToAction("Account", "Login");
}
}
Создание модели в порядке, а затем я перенаправляю на Home
Контроллер по методу Index
. В методе Index я создаю свой ExchnageServer, но после выполнения Index
мой объект модели становится пустым.
Этот домашний контроллер
public ActionResult Index(AccountModels model)
{
ServerExchangeCore server = new ServerExchangeCore(model);
return View(server);
}
// [Authorize]
public JsonResult GetAppointments(ServerExchangeCore serverExchange)
{
ServerExchangeCore server = serverExchange;
server.SetServer();
JsonResult result = new JsonResult();
List<Appointment> dataList = server.GetAppointments();
result = Json(dataList, JsonRequestBehavior.AllowGet);
return result;
}
а это мой ServerExchnageCore
класс
public class ServerExchangeCore
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2016);
AccountModels _model = new AccountModels();
public ServerExchangeCore()
{ }
public ServerExchangeCore(AccountModels model)
{
_model = model;
}
public void SetServer()
{
string email = GetEmail()
service.Credentials = new WebCredentials(_model.UserName, _model.Password);
service.AutodiscoverUrl(email, RedirectionUrlValidationCallback);
}
public List<Appointment> GetAppointments()
{
DateTime startDate = DateTime.Now;
string sssssss = service.Url.ToString();
DateTime endDate = startDate.AddDays(30);
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
CalendarView calendarView = new CalendarView(startDate, endDate);
calendarView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
FindItemsResults<Appointment> appointments = calendar.FindAppointments(calendarView);
List<Appointment> lst = new List<Appointment>();
foreach (Appointment aa in appointments)
{
lst.Add(aa);
}
return lst;
}
private string GetEmail()
{
if (HttpContext.Current.User.Identity.Name != null && HttpContext.Current.User.Identity.IsAuthenticated)
{
MembershipUser user = Membership.GetUser();
if (user != null)
userEmail = user.Email;
}
userEmail = Membership.GetUser().Email;
return userEmail;
}
Как мне починить мой Home
контроллер?