public string addEvent(string id, string json) { if (!Validation.IDValidation(id)) return "Wrong Input"; StudentEvent se = new StudentEvent(); se = JsonConvert.DeserializeObject<StudentEvent>(json); ProjectDBEntities PDb = new ProjectDBEntities(); int count = PDb.StudentInfo.Where(s => s.SID == id).Count(); if (count != 0) { Event e = new Event { SID = id, E_TITLE = se.Title, E_LOCATION = se.Location, E_PEOPLE = se.People, E_DETAIL = se.Detail, E_START = se.Start, E_END = se.End, E_ALLDAY = se.isAllDay, E_DATE = se.Date }; PDb.Event.Add(e); PDb.SaveChanges(); return "True"; } else return "False"; }
public string getEventsByDate(string id, string sDate, string eDate) { if (!Validation.IDValidation(id)) return "Wrong Input"; try { DateTime sDT = Convert.ToDateTime(sDate); DateTime eDT = Convert.ToDateTime(eDate); if (sDT > eDT) return "Wrong Input"; ProjectDBEntities PDb = new ProjectDBEntities(); List<StudentEvent> seList = new List<StudentEvent>(); IQueryable<Event> allEvent = from eve in PDb.Event where eve.SID == id select eve; if (allEvent.Count() == 0) return "False"; foreach (Event item in allEvent) { DateTime DT = Convert.ToDateTime(item.E_DATE); if ((sDT <= DT) && (DT <= eDT)) { StudentEvent se = new StudentEvent(); se.Title = item.E_TITLE; se.Detail = item.E_DETAIL; se.Location = item.E_LOCATION; se.People = item.E_PEOPLE; se.Start = item.E_START; se.End = item.E_END; se.isAllDay = item.E_ALLDAY; se.Date = item.E_DATE; seList.Add(se); } } if (seList.Count == 0) return "False"; string reRes = JsonConvert.SerializeObject(seList); return reRes; } catch (FormatException e) { return "Wrong Input"; } }
public string getAllEvents(string id) { if (!Validation.IDValidation(id)) return "Wrong Input"; ProjectDBEntities PDb = new ProjectDBEntities(); List<StudentEvent> seList = new List<StudentEvent>(); //StudentEvent se = new StudentEvent(); try { IQueryable<Event> allEvent = from eve in PDb.Event where eve.SID == id select eve; if (allEvent.Count() == 0) return "False"; foreach(Event item in allEvent) { StudentEvent se = new StudentEvent(); se.EID = item.EID.ToString(); se.Title = item.E_TITLE; se.Detail = item.E_DETAIL; se.Location = item.E_LOCATION; se.People = item.E_PEOPLE; se.Start = item.E_START; se.End = item.E_END; se.isAllDay = item.E_ALLDAY; se.Date = item.E_DATE; seList.Add(se); } string reRes = JsonConvert.SerializeObject(seList); return reRes; } catch { return "False"; } }