Beispiel #1
0
        public JsonResult DeleteEvent(Table t)
        {
            var status = false;

            //System.Diagnostics.Debug.WriteLine("event ID to delete is: "+ e.EventID);
            try
            {
                using (var ecm = new EventCalendarModel())
                {
                    var entry = ecm.Tables.Where(e => e.EventID == t.EventID).FirstOrDefault();
                    if (entry != null)
                    {
                        ecm.Tables.Remove(entry);
                        ecm.SaveChanges();
                        status = true;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Delete exception message is: " + ex.ToString());
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
Beispiel #2
0
        public JsonResult SaveEvent(Table t)
        {
            var status = false;

            try
            {
                using (EventCalendarModel ecm = new EventCalendarModel())
                {
                    //System.Diagnostics.Debug.WriteLine("event id is: " + e.EventID);
                    // if >0, then this entry is already in our db
                    if (t.EventID > 0) // 0 is the default, which is not allowed in our db
                    {
                        //Update the event
                        var entry = ecm.Tables.Where(e => e.EventID == t.EventID).FirstOrDefault();
                        if (entry != null)
                        {
                            entry.Subject     = t.Subject;
                            entry.Start       = t.Start;
                            entry.End         = t.End;
                            entry.Description = t.Description;
                            entry.EventColor  = t.EventColor;
                        }
                        // else, something unexpected occured.
                    }
                    else
                    {
                        t.EventID = 1;
                        // if table is not empty
                        if (ecm.Tables.Any())
                        {
                            t.EventID = ecm.Tables.Max(e => e.EventID) + 1;
                        }

                        ecm.Tables.Add(t);

                        /* System.Diagnostics.Debug.WriteLine("start is: " + e.Start.ToString());
                         * System.Diagnostics.Debug.WriteLine("end is: " + e.End.ToString());*/
                    }

                    ecm.SaveChanges();
                    status = true;
                }
            }
            catch (Exception ex) //Catch Other Exception
            {
                System.Diagnostics.Debug.WriteLine("Exception message is: " + ex.ToString());
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }