This is a migrated thread and some comments may be shown as answers.

I am not able to get Start and stop dates in the controller's create method

4 Answers 90 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Nayeem
Top achievements
Rank 1
Nayeem asked on 24 Oct 2013, 11:49 AM
Hello Team,

I have implemented the scheduler in the ASP.Net MVC application and I am not able to get the start/stop dates from event creation popup to the controller's save method, below is the code please help me to resolve this issue.
The other issue is when I try to comment the dates and save the appointment in database and opens the appointment event creation again then it doesn't closes out.

Below is the code please help me to resolve this issue :
Controller Code :
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kendo.Mvc.Extensions;
using VisionDB.Helper;
using VisionDB.Models;
using System.Globalization;
using System.IO;
using System.Collections.Specialized;
using System.Web.UI;
using System.Web.Security;

namespace VisionDB.Controllers
{
[Authorize]
public class CustomersController : Controller
{

#region Customers
public ActionResult Index()
{
return Search(null);
}

public ActionResult Search(string Search)
{
var db = new CustomersDataContext();
var results = from row in db.Customers
select row;

if (!string.IsNullOrWhiteSpace(Search))
{
results = results.Where(c => c.Number.ToLower().Contains(Search.ToLower())
|| c.Number.Replace(" ", "").ToLower().Contains(Search.Replace(" ", "").ToLower())
|| c.Firstnames.ToLower().Contains(Search.ToLower())
|| c.Surname.ToLower().Contains(Search.ToLower())
|| c.Address.ToLower().Contains(Search.ToLower())
|| c.Postcode.ToLower().Contains(Search.ToLower())
|| c.Postcode.Replace(" ", "").ToLower().Contains(Search.Replace(" ", "").ToLower())
|| c.Telephone.ToLower().Contains(Search.ToLower())
|| c.SMSNumber.ToLower().Contains(Search.ToLower())
|| c.SMSNumber.Replace(" ", "").ToLower().Contains(Search.Replace(" ", "").ToLower())
|| c.Email.ToLower().Contains(Search.ToLower()));
}
else
{
results = results.Where(c => false);
}

return View(results);
}

public ActionResult Customer(Guid Id,string message)
{
var db = new CustomersDataContext();
//get customers by id
var customer = db.Customers.Find(Id);
customer.EyeTests = new EyeTestsController().GetEyeTests(customer);
//get customer attachments
customer.GetAttachments = GetCustomerAttachments();
customer.Invoices = new InvoicesController().GetInvoices(customer);
foreach (Invoice invoice in customer.Invoices)
{
invoice.InvoiceDetails = GetInvoices(invoice);
}
if (message != null)
{
@ViewBag.Message = message;
}
return View(customer);
}

[HttpGet]
public ActionResult Edit(Guid Id)
{
var db = new CustomersDataContext();
var customer = db.Customers.Find(Id);
ViewBag.NHSPrivateLists = EnumHelper.ToSelectList(VisionDB.Models.Customer.NHSPrivateList.Unknown);
ViewBag.SmokerLists = EnumHelper.ToSelectList(VisionDB.Models.Customer.SmokerList.Unknown);

return View(customer);


}



[HttpPost]
public ActionResult Edit([Bind(Exclude = "Age,LastTestDate,NextTestDueDate")]Models.Customer customer)
{
if (string.IsNullOrWhiteSpace(customer.Telephone) && string.IsNullOrWhiteSpace(customer.SMSNumber))
{
ModelState.AddModelError("Telephone", "Either a telephone or SMS number must be supplied");
ModelState.AddModelError("SMSNumber", "Either a SMS or telephone number must be supplied");
}

if (ModelState.IsValid)
{
if (customer.Id == Guid.Empty)
{
customer.Id = Guid.NewGuid();
}

//Save to database
var db = new CustomersDataContext();

db.Entry(customer).State = EntityState.Modified;

db.SaveChanges();

return RedirectToAction("Customer", new { customer.Id });
}

return Edit(customer.Id);
}

[HttpGet]
public ActionResult Create()
{
//populate drop down lists
ViewBag.NHSPrivateLists = EnumHelper.ToSelectList(VisionDB.Models.Customer.NHSPrivateList.Unknown);
ViewBag.SmokerLists = EnumHelper.ToSelectList(VisionDB.Models.Customer.SmokerList.Unknown);
ViewBag.AppTypes = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.AppType.Eye_Test);
return View();
}

[HttpPost]
public ActionResult Create([Bind(Exclude = "Age,LastTestDate,NextTestDueDate")]Models.Customer customer)
{
if (string.IsNullOrWhiteSpace(customer.Telephone) && string.IsNullOrWhiteSpace(customer.SMSNumber))
{
ModelState.AddModelError("Telephone", "Either a telephone or SMS number must be supplied");
ModelState.AddModelError("SMSNumber", "Either a SMS or telephone number must be supplied");
}

if (ModelState.IsValid)
{
if (customer.Id == Guid.Empty)
{
customer.Id = Guid.NewGuid();
}

//Save to database
var db = new CustomersDataContext();
db.Customers.Add(customer);
db.SaveChanges();

return RedirectToAction("Customer", new { customer.Id });
}

return Create();
}
#endregion

#region Eyetest

public ActionResult EyeTest(Guid Id)
{
var db = new CustomersDataContext();

var eyeTest = db.EyeTests.Find(Id);
ViewBag.Customer = db.Customers.Find(eyeTest.CustomerId);

return View(eyeTest);
}

[HttpGet]
public ActionResult EditEyeTest(Guid Id)
{
var db = new CustomersDataContext();
var eyeTest = db.EyeTests.Find(Id);
ViewBag.Customer = db.Customers.Find(eyeTest.CustomerId);
ViewBag.Bases = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.Base.None);
ViewBag.AppTypes = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.AppType.Eye_Test);
ViewBag.AdviceAndRecallLists = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.AdviceAndRecallList.None);
ViewBag.AppRooms = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.AppRoom.One);
ViewBag.YesNos = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.YesNo.None);
ViewBag.LensTypes = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.LensType.Not_Assigned);
return View(eyeTest);
}

[HttpPost]
public ActionResult EditEyeTest([Bind]Models.EyeTest eyeTest)
{
if (eyeTest.TestDateAndTime == null)
{
ModelState.AddModelError("Test date", "A test date is required");
}

if (ModelState.IsValid)
{
if (eyeTest.Id == Guid.Empty)
{
eyeTest.Id = Guid.NewGuid();
}

string signatureJson = Request.Form["output"];

//Save to database
var db = new CustomersDataContext();

db.Entry(eyeTest).State = EntityState.Modified;

db.SaveChanges();

return RedirectToAction("EyeTest", new { eyeTest.Id });
}

return EditEyeTest(eyeTest.Id);
}

[HttpGet]
public ActionResult CreateEyeTest(Customer customer)
{
var db = new CustomersDataContext();
var Customer = db.Customers.Find(customer.Id);
ViewBag.Bases = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.Base.None);
ViewBag.AppTypes = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.AppType.Eye_Test);
ViewBag.AdviceAndRecallLists = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.AdviceAndRecallList.None);
ViewBag.AppRooms = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.AppRoom.One);
ViewBag.YesNos = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.YesNo.None);
ViewBag.LensTypes = EnumHelper.ToSelectList(VisionDB.Models.EyeTest.LensType.Not_Assigned);
ViewBag.Customer = Customer;

return View();

}

[HttpPost]
public ActionResult CreateEyeTest([Bind]Models.EyeTest eyeTest)
{
eyeTest.CustomerId = eyeTest.Id;

if (eyeTest.Id == Guid.Empty)
{
eyeTest.Id = Guid.NewGuid();
}

//Save to database
var db = new CustomersDataContext();
var Customer = db.Customers.Find(eyeTest.CustomerId);

eyeTest.Title = Customer.ToString() + " eye test";
db.EyeTests.Add(eyeTest);
db.SaveChanges();

return RedirectToAction("EyeTest", new { eyeTest.Id });

}
#endregion

#region Invoice
public ActionResult Invoice(Guid Id)
{
var db = new CustomersDataContext();

var invoice = db.Invoices.Find(Id);
ViewBag.Customer = db.Customers.Find(invoice.CustomerId);
invoice.InvoiceDetails = GetInvoices(invoice);
return View(invoice);
}

private ICollection<InvoiceDetail> GetInvoices(Invoice invoice)
{
var db = new CustomersDataContext();

var results = from row in db.InvoiceDetails
select row;

if (invoice != null)
{
results = results.Where(c => c.InvoiceId == invoice.Id && c.UnitPrice >= 0);
}
else
{
results = results.Where(c => false);
}

var payments = from row in db.InvoiceDetails
select row;

if (invoice != null)
{
payments = payments.Where(c => c.InvoiceId == invoice.Id && c.UnitPrice < 0);
}
else
{
payments = payments.Where(c => false);
}

return results.Union(payments).ToList();
}
[HttpGet]
public ActionResult CreateInvoice(Guid Id)
{
var db = new CustomersDataContext();
Invoice Invoice = new Invoice();
Invoice.CustomerId = Id;
ViewBag.Customer = db.Customers.Find(Id);
return View(Invoice);
}
[HttpPost]
public ActionResult CreateInvoice(string List, Invoice invoice)
{
List<InvoiceDetail> InvoiceDetailList = null;
if (!string.IsNullOrEmpty(List) && invoice.InvoiceDate != null)
{
InvoiceDetailList = (List<InvoiceDetail>)Newtonsoft.Json.JsonConvert.DeserializeObject(List, typeof(List<InvoiceDetail>));
}
else
{
ModelState.AddModelError("Invoice", "No invoice detail lines");
}
if (ModelState.IsValid)
{
using (CustomersDataContext db = new CustomersDataContext())
{
ViewBag.Customer = db.Customers.Find(invoice.CustomerId);

if (invoice.Id == Guid.Empty)
{
invoice.Id = Guid.NewGuid();
invoice.UserId = 1;
}

//Save to database
invoice.CreatedTimestamp = DateTime.Now;
db.Entry(invoice).State = EntityState.Modified;
db.Invoices.Add(invoice);
int result = db.SaveChanges();

if (result == 1)
{
foreach (var Detaillst in InvoiceDetailList)
{
Detaillst.InvoiceId = invoice.Id;
if (Detaillst.Id == Guid.Empty)
{
Detaillst.Id = Guid.NewGuid();
}
db.Entry(Detaillst).State = EntityState.Modified;
db.InvoiceDetails.Add(Detaillst);
db.SaveChanges();
}
}
return Json(new { HasError = false, Message = "Success" });
}
}

return Json(new { HasError = true, Message = "Invoice not created! please add invoice detail lines" });
}

[HttpGet]
public ActionResult EditInvoice(Guid Id)
{
var db = new CustomersDataContext();
var invoice = db.Invoices.Find(Id);
ViewBag.Customer = db.Customers.Find(invoice.CustomerId);
Session["InvoiceId"] = Id;
invoice.InvoiceDetails = GetInvoices(invoice);
return View(invoice);
}

[HttpPost]
public ActionResult EditInvoice([Bind]Models.Invoice invoice)
{
//if (invoice.InvoiceDetails.Count == 0)
//{
// ModelState.AddModelError("Invoice", "No invoice detail lines");
//}

if (ModelState.IsValid)
{
if (invoice.Id == Guid.Empty)
{
invoice.Id = Guid.NewGuid();
}

//Save to database
var db = new CustomersDataContext();
invoice.CreatedTimestamp = DateTime.Now;
db.Entry(invoice).State = EntityState.Modified;

db.SaveChanges();

return RedirectToAction("Invoice", new { invoice.Id });
}

return EditInvoice(invoice.Id);
}

public ActionResult EditingInline_Read([DataSourceRequest] DataSourceRequest request, Guid Id)
{
if (Id != Guid.Empty)
{
return Json(SessionInvoiceRepository.All().Where(x => x.InvoiceId == Id).ToDataSourceResult(request));
}
return Json(null);
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingInline_Create([DataSourceRequest] DataSourceRequest request, InvoiceDetail invoiceDetail, string Mode)
{
if (Mode != "Create")
{
if (invoiceDetail != null)
{
invoiceDetail.InvoiceId = (Guid)Session["InvoiceId"];
SessionInvoiceRepository.Insert(invoiceDetail, Mode);
}
}
else
{
if (invoiceDetail != null)
{
SessionInvoiceRepository.Insert(invoiceDetail, Mode);
}
}

return Json(new[] { invoiceDetail }.ToDataSourceResult(request));
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, InvoiceDetail invoiceDetail)
{
if (invoiceDetail != null && ModelState.IsValid)
{
var target = SessionInvoiceRepository.One(p => p.Id == invoiceDetail.Id);
if (target != null)
{
target.Description = invoiceDetail.Description;
target.UnitPrice = invoiceDetail.UnitPrice;
target.Quantity = invoiceDetail.Quantity;
target.ProductTypeId = invoiceDetail.ProductTypeId;
SessionInvoiceRepository.Update(target);
}
}
return Json(new[] { invoiceDetail }.ToDataSourceResult(request, ModelState));
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingInline_Destroy([DataSourceRequest] DataSourceRequest request, InvoiceDetail invoiceDetail)
{
if (invoiceDetail != null)
{
SessionInvoiceRepository.Delete(invoiceDetail);
}

//return RedirectToAction("EditInvoice", "Customers", new { Id = invoiceDetail.InvoiceId });
return Json(new[] { invoiceDetail }.ToDataSourceResult(request, ModelState));
}
#endregion

#region Calendar

public ActionResult Calendar()
{
using (CustomersDataContext db = new CustomersDataContext())
{
List<Schedule> getSchedules = (from b in db.EyeTests
select new Schedule
{
id = b.Id,
customerid = b.CustomerId,
Title = b.Title,
testdateandtime = b.TestDateAndTime,
Start = b.Start.HasValue ? b.Start.Value : b.TestDateAndTime,
End = b.Start.HasValue ? b.End.Value : b.TestDateAndTime,
Description=b.Notes
}).ToList();

return View(getSchedules);
}
}
public virtual JsonResult ReadSchedule([DataSourceRequest] DataSourceRequest request)
{
using (CustomersDataContext db = new CustomersDataContext())
{
List<Schedule> getSchedules = (from b in db.EyeTests
select new Schedule
{
id = b.Id,
customerid = b.CustomerId,
Title = b.Title,
testdateandtime = b.TestDateAndTime,
Start = b.Start.HasValue?b.Start.Value:b.TestDateAndTime,
End = b.Start.HasValue ? b.End.Value : b.TestDateAndTime
}).ToList();

return Json(getSchedules.ToDataSourceResult(request));
}
}
[HttpPost]
public JsonResult SearchCustomer(string SearchData)
{
using (CustomersDataContext db = new CustomersDataContext())
{
List<Customer> GetCustomers = (from Customers in db.Customers
where Customers.Firstnames.Contains(SearchData) || Customers.Surname.Contains(SearchData) ||
Customers.Address.Contains(SearchData) || Customers.Telephone.Contains(SearchData)
select Customers ).ToList();

String json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(GetCustomers);
return Json(json, JsonRequestBehavior.AllowGet);

}
}

public virtual ActionResult DestroySchedule([DataSourceRequest] DataSourceRequest request, Schedule schedule)
{
if (schedule != null)
{
if (schedule.id != Guid.Empty)
{
using (CustomersDataContext dbContext = new CustomersDataContext())
{
EyeTest eyetest = dbContext.EyeTests.Where(x => x.Id == schedule.id).FirstOrDefault();
dbContext.Entry(eyetest).State = EntityState.Modified;
dbContext.EyeTests.Remove(eyetest);
dbContext.SaveChanges();
}
}
}

return RedirectToAction("Calendar", "Customers");
//return Json(new[] { schedule }.ToDataSourceResult(request, ModelState));
}
[HttpPost]
public JsonResult SetCustomerId(string CustomerId)
{
Session["SelectedCustomerId"] = CustomerId;
return Json("Success");
}
public virtual ActionResult CreateSchedule([DataSourceRequest] DataSourceRequest request, Schedule schedule)
{
if (schedule != null)
{
using (CustomersDataContext dbContext = new CustomersDataContext())
{
EyeTest eyetest = new EyeTest();
if (schedule.id == Guid.Empty)
{
//Guid CustomerId = Guid.Parse(Session["SelectedCustomerId"].ToString());
eyetest.Id = Guid.NewGuid();
eyetest.TestDateAndTime = System.DateTime.Now;
// Here time frames become unavailable - Comment By Reishabh
//eyetest.Start = ConvertDateFormat(schedule.Start.ToString());
//eyetest.End = ConvertDateFormat(schedule.End.ToString());
eyetest.Title = schedule.Title;
eyetest.Notes = schedule.Description;
// Replace below customerId from selected CustomerId
eyetest.CustomerId = Guid.Parse("057982f7-5aa1-4850-9de8-10aa264ede76");
//eyetest.CustomerId = CustomerId;
//eyetest.CustomerId = schedule.CustomerId;
//eyetest.AppointmentType = new VisionDB.Models.EyeTest.AppType();
eyetest.UserId = 1;
dbContext.EyeTests.Add(eyetest);
dbContext.SaveChanges();
}
}
}
return RedirectToAction("Calendar", "Customers");
//return Json(new[] { schedule }.ToDataSourceResult(request));
}

public virtual ActionResult UpdateSchedule([DataSourceRequest] DataSourceRequest request, Schedule schedule)
{
if (ModelState.IsValid)
{
if (schedule != null)
{
using (CustomersDataContext dbContext = new CustomersDataContext())
{
if (schedule.id != Guid.Empty)
{
EyeTest target = dbContext.EyeTests.Where(p => p.Id == schedule.id).FirstOrDefault();
target.TestDateAndTime = ConvertDateFormat(schedule.testdateandtime.ToString());
target.Start = ConvertDateFormat(schedule.Start.ToString());
target.End = ConvertDateFormat(schedule.End.ToString());
target.Notes = schedule.Description;
target.Title = schedule.Title;
dbContext.Entry(target).State = EntityState.Modified;
}
dbContext.SaveChanges();
}
}
}

return RedirectToAction("Calendar", "Customers");
//return Json(new[] { schedule }.ToDataSourceResult(request, ModelState));
}

public DateTime ConvertDateFormat(string date)
{
DateTimeFormatInfo dateTimeFormatterProvider = DateTimeFormatInfo.CurrentInfo.Clone() as DateTimeFormatInfo;
dateTimeFormatterProvider.ShortDatePattern = "MM/dd/yyyy HH:mm:ss"; //source date format
DateTime dateTime = DateTime.Parse(date, dateTimeFormatterProvider);
string formatted = dateTime.ToString("dd/MM/yyyy HH:mm:ss");
return Convert.ToDateTime(formatted);
}
#endregion

#region Attachments
public ActionResult UploadAttachments(IEnumerable<HttpPostedFileBase> files, string Comments, Guid Id, int AttachmentId = 0)
{
string fileName = string.Empty;
if (files != null)
{
foreach (var file in files)
{
if (file.ContentLength > 0)
{
fileName = Path.GetFileName(file.FileName);
string urlPath = string.Format("{0}{1}", Server.MapPath("~/content/uploads/"), Id);
var path = Path.Combine(urlPath, fileName);
// Create directory as necessary and save image
if (!Directory.Exists(urlPath) && !System.IO.File.Exists(path))
{
Directory.CreateDirectory(urlPath);
file.SaveAs(path);
}
}
}
}
if (AttachmentId == 0)
{
using (var entities = new CustomersDataContext())
{
Attachments attachments = new Attachments();
attachments.FileName = fileName;
attachments.FileComments = Comments;
attachments.CustomerId = Id;
//check file already exist and if not save the attachments
bool Isfilealreadyexists = entities.Attachments.Where(m => m.FileName == attachments.FileName).Any();
if (!Isfilealreadyexists)
{
entities.Attachments.Add(attachments);
int i = entities.SaveChanges();
}
else
{
ViewBag.Message = "File already exist! please delete the existing one and upload again";
}

}
}
else
{
EditAttachments(AttachmentId, Comments, Id);
}
return RedirectToAction("Customer", new { Id = Id, message = ViewBag.Message });
}

public ActionResult EditAttachments(int id, string Comments, Guid customerId)
{
using (var entities = new CustomersDataContext())
{
//get and edit the attachments
Attachments data = entities.Attachments.Where(m => m.Id == id).FirstOrDefault();
data.FileComments = Comments;
entities.SaveChanges();
}
return RedirectToAction("Customer", new { id });
}
public IEnumerable<Attachments> GetCustomerAttachments()
{
using (var entities = new CustomersDataContext())
{
//get customers by id
return entities.Attachments.ToList();
}
}

public ActionResult Delete(int Id)
{
Attachments data = null;
using (var entities = new CustomersDataContext())
{
//delete the customer
data = entities.Attachments.Where(m => m.Id == Id).FirstOrDefault();
entities.Attachments.Remove(data);
entities.SaveChanges();
}
//to delete the file from the folder
string urlPath = string.Format("{0}{1}", Server.MapPath("~/content/uploads/"), data.CustomerId);
var path = Path.Combine(urlPath, data.FileName);
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
return RedirectToAction("Customer", new { Id = data.CustomerId });
}
#endregion

public ActionResult Recalls(string DueDateDays, string LastRecallDays)
{

if (DueDateDays == null || DueDateDays.Length == 0)
{
DueDateDays = "30";
}

if (LastRecallDays == null || LastRecallDays.Length == 0)
{
LastRecallDays = "5";
}
DateTime dueDateCutOff = DateTime.Now.Date.AddDays(Convert.ToInt32(DueDateDays));

var db = new CustomersDataContext();
var results = from row in db.Customers
select row;

results = results.Where(c => c.NextTestDueDate.HasValue == false
|| (c.NextTestDueDate.Value < dueDateCutOff
&& c.LastRecallDate == null));

return View(results);
}

public ActionResult SendRecalls(Customer customer, FormCollection form)
{
string[] rawselectedids = form.Get("SelectedIds").Split(',');
int recallMethod = Convert.ToInt32(Request.Form["Filter"]);
List<Guid> selectedIds = new List<Guid>();

foreach (string id in rawselectedids)
{
if (id.Length > 1)
{
selectedIds.Add(new Guid(id.Replace("chkbox", "")));
}
}

SendRecallMessages(selectedIds, recallMethod);

TempData["OutboxMessage"] = string.Format("{0} recalls sent", selectedIds.Count);

return RedirectToAction("Outbox");
}

private void SendRecallMessages(List<Guid> selectedIds, int recallMethod)
{
var db = new CustomersDataContext();
var results = from row in db.Customers
select row;

results = results.Where(model => selectedIds.Contains(model.Id));

var templates = from row in db.MessageTemplates
select row;

templates = templates.Where(t => recallMethod == t.MessageTypeId
&& ((UserProfile)HttpContext.Session["user"]).customer.Id == t.CustomerId);
string template = templates.First().Template;


foreach (Customer customer in results)
{
if (customer.SMSNumber != null && customer.SMSNumber.Length > 5)
{

Message message = new Message();
message.Id = Guid.NewGuid();
message.RecipientId = customer.Id;
message.MessageTypeId = recallMethod;
message.SenderUserId = ((UserProfile)HttpContext.Session["user"]).UserId;
message.ToAddressNumber = customer.SMSNumber;
message.MessageText = string.Format(template,
customer.TitleAndName(), customer.NextTestDueDate.Value.ToShortDateString(), customer.SMSNumber); //todo: get number for practice
message.AddedToQueue = DateTime.Now;
message.Cancelled = null;
message.CancelledByUserId = null;
message.Sent = null;

db.Messages.Add(message);
}
else
{
//handle where sms doesn't exist or too short
}
}

db.SaveChanges();
}

public ActionResult Outbox()
{
var db = new CustomersDataContext();

var results = from row in db.Messages
select row;

results = results.Where(m => m.Sent == null && m.Cancelled == null);


return View(results);
}
}
}


View Code :

@model IEnumerable<VisionDB.Models.Schedule>
@{
ViewBag.Title = "Calendar";
}

@(Html.Kendo().Scheduler<VisionDB.Models.Schedule>()
//.Events(e =>
//{
// e.Edit("EditEvent");

//})
.Name("scheduler")
.Editable(true)
.Date(@DateTime.Today.Date)
.StartTime(new DateTime(2013, 6, 13, 10, 00, 00))
.EndTime(new DateTime(2013, 6, 13, 23, 00, 00))

.Height(600)
.Views(views =>
{
views.DayView();
views.WeekView(weekView => weekView.Selected(true));
views.MonthView();
views.AgendaView();
})

//.Resources(resource =>
//{
// resource.Add(m => m.CustomerId)
// .Title("Owner")
// .DataTextField("Text")
// .DataValueField("Value")
// .DataColorField("Color")
// .BindTo(new[] {
// new { Text = "Alex", Value = 1, Color = "#f8a398" } ,
// new { Text = "Bob", Value = 2, Color = "#51a0ed" } ,
// new { Text = "Charlie", Value = 3, Color = "#56ca85" }
// });
//})

.Selectable(true)
.Editable(true)
.MajorTick(60)
//.BindTo(Model)
.DataSource(d => d
.Model(m =>
{
//m.Id(f => f.CustomerId);
// m.Field(f => f.CustomerId).DefaultValue(1);

})

.Read("ReadSchedule", "Customers")
.Create("CreateSchedule", "Customers")
.Destroy("DestroySchedule", "Customers")
.Update("UpdateSchedule", "Customers")

)
)


<script>

//function EditEvent(e) {
// $('.k-popup-edit-form.k-scheduler-edit-form.k-window-content.k-content').hide();
// $('.k-widget.k-window').append('<div id="DivSelectCustomerInner">' + $('#DivSelectCustomer').html() + '</div>');
// //$('#DivSelectCustomer').remove();
//}

function CustomerSelected() {

$('#DivSelectCustomerInner').hide();
$('.k-popup-edit-form.k-scheduler-edit-form.k-window-content.k-content').show();
//ICustomerId

// $('#DivSelectCustomerInner').hide();
}
function SearchCustomer() {
var sPath = '@Url.Action("SearchCustomer", "Customers")';
var SearchData = $("#DivSelectCustomerInner #TxtFName").val();
//var SurName = $("#DivSelectCustomerInner #TxtSName").val();

$.ajax({
type: 'POST',
url: sPath,
data: "{'SearchData': '" + SearchData + "'}",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data) {
WriteToCustomers(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
function SelectCustomer(CustomerId,CustomerName) {
var sPath = '@Url.Action("SetCustomerId", "Customers")';
$.ajax({
type: 'POST',
url: sPath,
data: "{'CustomerId': '" + CustomerId + "'}",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data) {
$('#DivSelectCustomerInner #BtnNext').show(500);
$('.k-edit-form-container').append('<input type="hidden" id="HdnCustomerId" name="CustomerId" data-bind="value:CustomerId" value="' + CustomerId + '">');
$('.k-window-title').html('Event - Selected Customer : ' + CustomerName);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}

function WriteToCustomers(data)
{
//alert(data);
if (data) {
if (data!=null) {
var isdata = 0;
var CustomerHTML = '<table>';
if(data.length>0)
{
//alert("passed length");
CustomerHTML += '<tr>';
CustomerHTML += '<td>Select </td>';
CustomerHTML += '<td>First Name </td>';
CustomerHTML += '<td>Surname </td>';
CustomerHTML += '<td>Address</td>';
CustomerHTML += '</tr>';
$.each($.parseJSON(data), function (key, value) {
isdata = 1;
CustomerHTML += '<tr>';
CustomerHTML += '<td><input type="button" value="Select" onclick="SelectCustomer(\'' + value.Id + '\',\'' + value.Firstnames + ' ' + value.Surname + '\' )" /> </td>';
CustomerHTML += '<td>' + value.Firstnames + '</td>';
CustomerHTML += '<td>' + value.Surname + '</td>';//
CustomerHTML += '<td>' + value.Address + '</td>';
CustomerHTML += '</tr>';
});
CustomerHTML += '</table>';

}
//alert(CustomerHTML);
if (isdata == 0) {
$('#SearchResultDiv').html('<p> No Customers Found</p>');
} else {
// alert(CustomerHTML);
$('#DivSelectCustomerInner #SearchResultDiv').html(CustomerHTML);
}

}else{
LoadAppointment(ScheduleId);
}
}

//return false;
}



</script>
<div id="DivSelectCustomer" style="display:none;">
<h3 style="margin-left:15px;">Search Customer</h3>
@*<div class="k-edit-label"> <label for="title">Search</label></div>*@
<input type="text" class="k-input k-textbox" id="TxtFName" style="width:200px;margin-left:15px;margin-right:10px;"/><input type="button" class="k-button" value="Search" onclick="SearchCustomer()" />
<br /><br />
<div style="text-align:right"></div>
<br />
<div id="SearchResultDiv"></div>
<br />
<div class="k-edit-buttons k-state-default" style="text-align:right">
<input type="button" id="BtnNext" class="k-button" style="display:none;" value="Next" onclick="CustomerSelected()" />
</div>

</div>
<div id="tempdiv"></div>




Model Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

namespace VisionDB.Models
{
public class Schedule : ISchedulerEvent
{
public Guid id { get; set; }
public Guid customerid { get; set; }
public string Description { get; set; }
public DateTime testdateandtime { get; set; }
public string Title { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public bool IsAllDay { get; set; }
public string recurrence { get; set; }
public string RecurrenceRule { get; set; }
public string RecurrenceException { get; set; }
// public int ICustomerId { get; set; }


}
}

4 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 25 Oct 2013, 06:22 AM
Hello,

 
From the provided information it's not clear for us what is the exact reason for current behavior. Could you please provide runable project where the issue is reproduced? This would help us pinpoint the exact reason for this behavior.

Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Nayeem
Top achievements
Rank 1
answered on 25 Oct 2013, 11:06 AM
Hi 

Please find code as requested (just realised I have not sent everything over, will send shortly)

Thank you
0
Nayeem
Top achievements
Rank 1
answered on 25 Oct 2013, 12:18 PM
0
Vladimir Iliev
Telerik team
answered on 29 Oct 2013, 07:43 AM
Hi Nayeem,

 
Unfortunately the provided address returns HTTP 404 error - could you please check if the file is visible from internet? Another option is to share the file using one of the public cloud services (like Google Drive, SkyDrive).

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Scheduler
Asked by
Nayeem
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Nayeem
Top achievements
Rank 1
Share this question
or